WARNING: The following post talks about an Ubuntu version that is at end of life. It's highly recommended that you upgrade your server to a newer Ubuntu version.

It seemed fitting that the first post on PHP Avenue should be about setting up a new server with PHP. This particular post will focus on a traditional LAMP stack (Linux, Apache, MySQL, PHP) on Ubuntu 12.04 LTS. I also intend on writing additional posts covering the setup of a LEMP (E is for Nginx) server as well as covering the steps on additional Linux distributions.

To start things off, I went ahead and created a new Ubuntu 12.04 LTS x32 server over on DigitalOcean (full disclosure, that’s an affiliate link) so I could start with a clean slate. At the time of this writing, I am still relying on 12.04 LTS over 13.04 because Ubuntu’s long term releases are supported for longer and work just fine for running a website.

First things first, it’s always in your best interest to run a update / upgrade to make sure all of the packages are up to date before you start. This may take a bit of time depending on how old the source image may be.

sudo apt-get update && apt-get dist-upgrade

Once everything is properly upgraded we can start installing the AMP part of our LAMP stack. During this process the server will ask you to set a password for the MySQL user “root”. It’s highly recommend that you set a password during the set up, but in case you don’t you can always go back and set a password at a later date.

sudo apt-get install apache2 php5 php5-cli php5-mysql php5-suhosin mysql-server

This will install the most recent versions of Apache, PHP (including CLI access) and MySQL from the Ubuntu repository. Additional PHP libraries could be installed (like GD or Curl) but that goes beyond the scope of this post. Also, for those that aren’t already familiar, php5-suhosin is the Hardened-PHP Project. It provides additional security that has yet to make it into the main PHP code and was worth noting as I highly recommend using it every server you have running PHP.

Now that everything is setup, you can point your browser to your server’s IP address and should see something like this:

It works! This is the default web page for this server. The web server software is running but no content has been added, yet.

To test that PHP is installed and working properly working, you can create a new file named phpinfo.php in the /var/www directory (that’s Apache’s default document root). Inside that file all you need to type is:

<?php
phpinfo();
?>

Save the file and go back to your web browser and point it to the same address as before but add /phpinfo.php to the end. Once it loads, you should be looking at a page with a bunch of information about your current stack including what extensions are installed and version numbers and dumps of some of the super globals.

That should do it, you now have a bare bones LAMP server at your disposal now get to hacking!





Did you enjoy this post?

Cool if I slip into your inbox with more?
Full posts, 1-2 times per week: