Upgrading and Downgrading PHP 5.6 and 7.0

Followed the instructions

Possible Errors

If you need to install a new fresh apache2

If you come across an error similar to below when running
$ systemctl status apache2.service

 *** Restarting web server apache2                                                                                                                                          [fail]
 * The apache2 configtest failed.
Output of config test was:
apache2: Syntax error on line 140 of /etc/apache2/apache2.conf: Syntax error on line 1 of /etc/apache2/mods-enabled/php7.load: Cannot load /usr/lib/apache2/modules/libphp7.so into server: /usr/lib/apache2/modules/libphp7.so: cannot open shared object file: No such file or directory
Action 'configtest' failed.
The Apache error log may have more information.**

$ sudo apt-get install libapache2-mod-php7.0

If error “AH00534: httpd: Configuration error: More than one MPM loaded”

Disable all apache2/mods-enabled/mpm* except for mpm_prefork


Setup ssl https for you apache site

Follow every step in:

Get a secure https connections:
1. buy a certificate (namecheap is a good option)
2. Install it in your server

Multiple Remote Virtual host and sub domains

Just by doing whats below the server will automatically recognize if its requesting baligena.com or subdomain.baligena.com and navigate to the correct page. No additional configuration is necessary, everything to make subdomains and virtual host work is here.

$ sudo nano /etc/apache2/sites-available/baligena.com

    # domain: baligena.com
    # public: /var/www/mulsite/

    <virtualhost *:80>

      # Admin email, Server Name (domain name) and any aliases
      ServerAdmin webmaster@baligena.com
      ServerName  baligena.com
      ServerAlias www.baligena.com

      # Index file and Document Root (where the public files are located)
      DocumentRoot /var/www/mulsite/

$ sudo a2ensite baligena.com
$ sudo service apache2 reload


For subdomain:
configure you dns provider godaddy or namecheap.com

$ sudo nano /etc/apache2/sites-available/baligena.com

    # domain: subdomain.baligena.com
    # public: /var/www/mulsite/

    <virtualhost *:80>

      # Admin email, Server Name (domain name) and any aliases
      ServerAdmin webmaster@baligena.com
      ServerName subdomain.baligena.com
      ServerAlias www.subdomain.baligena.com

      # Index file and Document Root (where the public files are located)
      DocumentRoot /var/www/mulsite

$ sudo a2ensite baligena.com
$ sudo service apache2 reload

the default page should be /var/www/

sub domains

Python script in the browser

This site shows you how to setup apache2 so you can run python script in the browser (lampp). He shows a method on how to use an html form to fetch date from python using POST.

Running a script directly without POST and using urllib2 to fetch a website:
in the browser type:

import cgi
import cgitb
import urllib2

# Begin HTML generation, must be here
print "Content-Type: text/html; charset=UTF-8" # Print headers
print "" # Signal end of headers

# HTML is pushed to the page with print
# To save time you can use ''' to open and close a print
# statement for block printing

response = urllib2.urlopen('http://facebook.com')
print response.read()

print "hello world"

run python script html apache2 server
run python script html
urllib2 execute html

Multiple Sites on One Server – Virtual Hosts

This works for Ubuntu

Go to your site directory and make two folder site1.com and site2.com
$ mkdir /var/www/site1.com /var/www/site2.com

Modify your host file
$ sudo nano /etc/hosts

Add the two lines of code into that file site1.com site2.com

Make configuration changes to apache by creating 2 files in the /etc/apache2/sites-available directory
$ sudo touch /etc/apache2/sites-available/site1.com /etc/apache2/sites-available/site2.com

Put this code in those new created file.
site1.com file:
<VirtualHost *:80>
DocumentRoot /var/www/site1.com
ServerName www.site1.com
ServerAlias site1.com

site2.com file:
<VirtualHost *:80>
DocumentRoot /var/www/site2.com
ServerName site2.com
ServerAlias site2.com

Final configuration commands
$ sudo a2ensite site1.com
$ sudo a2ensite site2.com
$ sudo service apache2 reload

Now if you put either site1.com or site2.com in your browser you’ll go to those sites. Now if you own these domain names put you internet IP address with the domain hosting and it will automatically navigate to the specified site location, making accessibility public.

if error:
apache2: Could not reliably determine the server’s fully qualified domain name, using for ServerName

$ sudo nano /etc/apache2/httpd.conf

add the line below:
ServerName localhost


AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using Set the ‘ServerName’ directive globally to suppress this message

Allow htaccess to override php.ini

In order .htaccess to override the configuration on php.ini you must edit your apache configuration.

In order for the .htaccess code below to work in your site

<IfModule mod_php5.c>
php_value upload_max_filesize 10MB
php_value post_max_size 10MB

You’ll will need to insert the code below to /etc/apache2/sites-available/default

<VirtualHost *:80>
        ServerAdmin webmaster@localhost


    <Directory /var/www/>
        AllowOverride All


Then restart apache
$ /etc/init.d/apache2 restart


ubuntu server add .htaccess directory
allow php.ini to be override using .htaccess
php.ini increase upload size
php ini httpd conf htaccess
.htaccess is not overriding php.ini
.htaccess override php.ini
changing php ini values using .htaccess
change php ini htaccess not working

Data Log

When building a site or managing a server its very beneficial to look at data and error logs.

To check if php error logs is enabled run phpinfo() and under Core table and the error_log row if ‘no value’ it means its not enabled. To enable PHP error logging open C:\wamp\bin\apache\Apache2.2.17\bin\php.ini and uncomment error_log line. See below

; Log errors to specified file. PHP's default behavior is to leave this value
; empty.
; http://php.net/error-log
; Example:
;error_log = php_errors.log
; Log errors to syslog (Event Log on NT, not valid in Windows 95).
;error_log = syslog
error_log = "c:/wamp/logs/php_error.log"


Ubuntu Server:
PHP error logs is enabled and shows up /var/log/apache2/error.log

For MySQL logging uncomment the general_log_file and general_log line in /etc/mysql/my.cnf see example below

# * Logging and Replication
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
general_log_file        = /var/log/mysql/mysql.log
general_log             = 1

log_error                = /var/log/mysql/error.log

Then restart MySQL
$ /etc/init.d/mysql restart


XAMPP troubleshoot

XAMPP on linux ubuntu stopped working I belive it was because I
ran the python barebones server script. While XAMPP was running I
would go to http://localhost and the page wouldn’t load. So I tried
to restart xamp
$ sudo opt/lampp/lampp restart

I received this error message

(20014)Internal error: Error retrieving pid file logs/httpd.pid
Remove it before continuing if it is corrupted.

so I deleted the logs/httpd.pid file, restarted LAMPP and it started to work again

troubleshoot, linux ubunut

Python and MySQL

I needed a better way to prevent spammers from coming to my site.  I was manually retrieving their IP address and blocking on my .htaccess file.  However, I decided to automate it by using a python script, crontab, wordpress and MySQL.  My biggest issue was to get python to connect to mysql.

I build a script that fetches every IP address marked as spam in wordpress. Crontab runs this script every week which creates and replaces the .htaccess file with updated data.