Setup a LAMP (Linux, Apache, MySQL, PHP) Server – Ubuntu 14.04

I need a LAMP Server, STAT!

Setting up a LAMP server is quick and easy.  You will need:

  • A server, either local or cloud (Like from Digital Ocean.)
  • A computer, internet, and a brain of some sort (your own will do fine!)
NOTE: This walkthrough will assume you are using Ubuntu 14.04 on Digital Ocean, though it can be easily adapted for use on other platforms!

Step One: Apache

First of all, if you haven’t recently, I recommend updating/upgrading your apt repo.  This can be done by entering:
sudo apt-get update && sudo apt-get upgrade


Next, download apache2.
sudo apt-get install apache2


If this install was successful you will be able to confirm it by entering your server’s IP address into your browser and a default page should appear.


Step Two: MySQL

Next, we will install MySQL.  THis is nearly as easy as the previous step  (I Love apt-get!!)

sudo apt-get install mysql-server php5-mysql


Once this is done, I am a fan of running
sudo mysql_secure_installation


Follow the steps and change your root password for mysql (if you wish) and then allow it to do the rest of the security settings that it wants to do.  Well worth it, IMHO.



Step Three: PHP

Installing PHP goes a lot like the other two steps.

sudo apt-get install php5 php5-mycrypt libapache2-mod-php5 php5-cli


once this is done, you’re done!  Restart apache2 and make sure that it still works then you are good to go on testing php.
sudo service apache2 restart


Test Your Work:

In order to confirm that everything is working, first try
mysql -u root -p

This will prompt for the root password that you entered previously.  I strongly recommend using a different user rather than root for using mysql, but this will get you in.


Once the <mysql> prompt shows, try entering
show databases;

If your install worked you should get a response from mysql.  If all is well, type exit and you will be released from the <mysql> prompt.


Next we test PHP.  Enter
cd /var/www/html
rm index.html
nano index.php

This will open the nano editor.  Paste in:
<?php phpinfo(); ?>

and then press Ctrl + x, y (to save and exit)


Go to your browser and type in your servers ip then /index.php.  Ex.  if your server’s ip is 123.456.789.10 then enter:  http://123.456.789.10/index.php

You should see the PHP default page.  If you do, then you are done, and it all works!