main

Setting up LAMP on ubuntu 14.04


LAMP stands for Linux Apache MySQL and PHP today we will show you how to set this up on a ubuntu server. And also how to configure a vhost on apache, setting up ftp to upload content and installing phpMyAdmin for easy database management

Install packages

From you cloud control panel create a ubuntu 14.04 server with a minimum of 1GB RAM
copy your root password and login to the box via SSH. The first commands you will want to issue are

apt-get update
apt-get upgrade

This will update the repos and apply any upgrades to the packages needed next we will install all the relevent packages in order to start setting up LAMP

apt-get install apache2

this will install Apache and its dependancys and start the webservice

next we will install MySQL using

apt-get install mysql-server

In the installation process it will prompt you to make a root password for the MySQL database pick something secure that you can remember. The process will be started after install

Next its time to install php version 5.5.9 (at time of writing)

apt-get install php5

This will restart the apache2 service in order for apache to start using php

Setup Apache

Now to configure a vhost to start serving up webcontent

Start by making a directory for your webcontent (replacing example.com with your domain)

mkdir -p /var/www/example.com/public_html

Now we will proceed with the vhost configuration. Apache comes with a default configuration template you can use this to create your own vhost

cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example.com.conf

Open the copied file with a text editor it should look something like this

<VirtualHost *:80>
	ServerAdmin webmaster@localhost
	DocumentRoot /var/www/html
	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

We will change it to look like this

<VirtualHost *:80>
	ServerName example.com
    ServerAlias www.example.com
    ServerAdmin webmaster@example.com
    DocumentRoot /var/www/example.com/public_html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Here we have added a couple of directives ServerName this indicates what domain the vhost should serv. ServerAlias sets the alternate names for a vhost. We have changed the DocumentRoot directive to the path of the vhost public_html files. We can now enable this vhost with the following command

a2ensite example.com.conf

This will set a symbolic link to the sites-enabled directory which effectivly sets the vhost to a live state.

Now we will setup a test page and fix permissions on the public_html folder
to fix permissions on the folder and allow apache to read from this directory do

chown apache:apache /var/www/example.com/public_html

and now setup a test page so we can see everything is working using your text editor make a file inside the public_html folder called index.html and just put
example.com test

save the file and then issue a service restart to apply changes

service apache2 restart

If you have set a ANAME DNS record to your server you should be able to view the test page from your url. Great now we will configure FTP so you can upload your content

Installing an FTP server

Install vsftpd with

apt-get install vsftpd

Now we will enable chroot for localusers so the user wont be able to cause havok or poke around the filesystem
open up /etc/vsftpd.conf and uncomment the line chroot_local_user=YES and add lines

allow_writeable_chroot=YES
write_enable=YES
local_umask=022
pasv_enable=Yes
pasv_max_port=40000
pasv_min_port=40100

to the bottom of vsftpd.conf save it then restart the ftp service with

service vsftpd restart

now we can make a user to log into ftp with

useradd -d /var/www/example.com -s /usr/sbin/nologin exampleuser-ftp

this makes a user called exampleuser-ftp and sets its home directory to the vhost folder and does not allow this user to login via SSH add /usr/sbin/nologin to /etc/shells to allow the user to login via ftp

next set a password for this user with

passwd exampleuser-ftp

Choose a secure password for the ftp user
Now we can fix permissions again to allow the ftp user to write to the directory but also allow Apache to read from it

chown exampleuser-ftp:apache /var/www/example.com/public_html

Test the connection with an ftp client and all should be fine

Install phpMyAdmin

Now we can upload files to the document root via ftp
Next we can install phpMyAdmin. On ubuntu 14.04 the installation of phpMyAdmin is very straght forward using:

apt-get install phpmyadmin

The installer will prompt you for a password to use to connect to MySQL user the one setup earlier in the tutorial when that has finished you can login to phpMyAdmin via http://YOURIPADDRESS/phpmyadmin there are servral ways to improve security around this page which is beyond the scope of this tutorial. If you have any problems following this guide dont hesitate to open a support ticket on your cloud control panel or a chat session to talk to a support specialist who can guide you in the right direction

Have fun :)