Configuring your webserver (Apache2)

This manual explains how you can serve web pages from out your ‘home user directories’. Not only is this safer, it is also easier to add or delete websites.

Step 1 – Enable the ‘userdir module’ in Apache2

Apache2 has a built in ‘userdir module’. Enable it by using the following command:

username@vpshostname:~$ sudo a2enmod userdir
Step 2 – Create a directory called ‘public_html’

Now you can create a directory called ‘public_html’ and serve your webpages to the world from there.

This you can do using the mkdir command or by using mc.

username@vpshostname:~$ mkdir public_html
Step 3 – Switch on PHP support in user directories

Edit your apache2 configuration as follows:

username@vpshostname:~$ sudo nano /etc/apache2/mods-available/php5.conf

Now you need to comment out a few lines from <IfModule mod_userdir.c> to the next </IfModule> so that the result looks like this:

# Running PHP scripts in user directories is disabled by default
# To re-enable PHP in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
#<IfModule mod_userdir.c>
# <Directory /home/*/public_html>
# php_admin_flag engine Off
# </Directory>

Restart the Apache webserver by using the following command:

username@vpshostname:~$ sudo service apache2 restart

And you should now be able to create php pages within your /home/username/public_html/ directory and serve them to the world (you can easily test this by placing our info.php file of earlier, into your /home/username/public_html/ directory, and then visit http://your vpsip/~username )

Step 4 – Install PHPMyAdmin

An easy way to work with mysql is through a GUI (Graphical User Interface), like the application PHPMyAdmin.

Install phpmyadmin on Ubuntu using the following command:

username@vpshostname:~$ sudo apt-get install phpmyadmin

During Installation a few pop-ups might appear, which have configuration questions for you to answer, for example:

For which webserver is phpmyadmin going to be configured? the answer is apache2 ofcourse

Next it will ask configure database for phpmyadmin with dbconfig-common? answer yes here.

Then it will ask the password for the mysql administrator user, use the mysql-password which you earlier specified during the installation of the LAMP-server here.

At last, it’ll ask for a phpmyadmin application password for mysql so make one up (this is a password which phpmyadmin will use to create a database of it’s own)

Step 5 – Configure your webserver

Phpmyadmin is now installed, but it can’t work in combination with your webserver yet, untill you configure it to do so:

username@vpshostname:~$ sudo nano /etc/apache2/apache2.conf

and add this code to the end of the config file:

Include /etc/phpmyadmin/apache.conf

Next we restart the server again with:

username@vpshostname:~$ sudo service apache2 restart

And when we now visit http://yourvpsip/phpmyadmin/

We should be greeted with the login screen of phpmyadmin, and you can now login as root, with your mysql administration password of earlier, to create and manage your databases.