How To Install LAMP (Linux, Apache, MySQL & PHP)

by Clayton Lambert

Trying to setup your VPS server or just trying to create your own local webserver? This tutorial is about setting up Ubuntu Server 14.04 with a LAMP (Linux, Apache, MySQL, PHP) stack.

VPS or Fresh Install?



For those installing LAMP on a VPS that already has an OS installed with access from open-SSH, you can skip to the Apache, MySQL and PHP install here.
If you don’t have an OS installed already, continue without skipping.

Installing Ubuntu Server 14.04 [Download]

First off you need to get the Ubuntu Server .ISO if you haven’t already. Depending on what you are doing you may need to make it bootable, so if you are going to be installing this from a USB onto an old salvage PC you need to get something that can mount a ISO on a USB for you. My personal choice is UNetbootin, I’ve used it multiple times before and it has yet to fail me. For those using VirtualBox or VMWare you don’t have to worry about this.

Boot into Ubuntu for the first time and you should be given a menu with a few different options. We’re going to go straight to “Install Ubuntu Server” and press Enter to select that option.

menu


Next you’ll be prompted to choose a language, and a select a country. Choose your appropriate selections by navigating through the options with the arrow keys, and press Enter to select it. After that you’ll be prompted to “detect a keyboard layout”. Choose No and then select the layout manually.

choose_key


A few seconds of waiting through loading screens, you will them be prompted to enter a hostname. A hostname is a simple way to identify a computer on a network and you should choose a unique one to avoid conflict. You may wish to do so with a sub domain that points to your server’s IP (server1.mydomain.com) or just enter a random name like I did.

hostname


This is the point where you get to choose a username and password, you’ll first be prompted to enter your full name, then an account name, followed by entering your password. In my case I just made my account name the same as the name I enter for the full name. It really doesn’t matter as long as you remember your username and password.

userpass


Now that you have created your user credentials you will now be asked if would like to encrypt your home directory or not. This is really a personal choice, this setting will add a password prompt every time the machine starts up, but helps keep your files secure. Choose what you want, I usually choose not to encrypt my home directory.

encryptdrive


A few more loading bars later and you’ll eventually be asked for a time zone. Why this wasn’t in the beginning of the setup? The world may never know… Usually Ubuntu will select the correct timezone based on your internet connection, but just in case it doesn’t you have the option to manually choose one. Ubuntu guessed mine correctly so I just pressed Yes. Now you should be asked about a partitioning method, for most cases you should just use “Guided – use entire disk and set up LVM” and press Enter.

part

You’ll be prompted to select the disk you want to partition, just select the drive from the list that you wish to use. Next you’ll be asked if you want to “write changes to disk and configure LVM”, press Yes. Next, choose the amount of space you want to give to that partition, the default number is usually correct and that’s what I always go with. Press continue and once again you’ll be asked to write changes to disk, where you should then select Yes.

partanim


Now we’re going to begin configuring the package manager so you will be asked to enter an HTTP proxy if you need one, if you do not simply press continue and leave the field blank.

httpproxy


In the next prompt, you definitely want to select “Install Security update automatically”. This will ensure your system is up to date and less vulnerable to some attacks. However there is much more that needs to be done after the server is setup to help prevent you server from being compromised. I have another tutorial for server security already in the works…

secsel


ALMOST DONE! We are almost done with the hard part at least. We’re now being prompted to select the software we want to be installed by default, we’re going to install Open-SSH and DNS Server. Use the space bar to make these selections then press Enter to continue.

softwaresel


You’ll be prompted to install the GRUB bootloader, choose Yes. You’ll then be brought to the finish installation prompt, press continue and you’re machine will restart to finish the install.

Ubuntu Server Installed!

Congratulations! You’ve now installed Ubuntu Server 14.04. Mostly just pressing Yes > Yes > Yes, kinda like installing a program on Windows except you don’t have to watch out for toolbar installs…

Finding Your Servers IP

Now that your server is online, we need to find it’s IP to connect to it. Login to the server using the credentials you entered early for your username and password and enter the following command.

sudo ifconfig

When you run that command; assuming you have your computer connected to your router, you should get two devices listed. One called “eth0” and one called “lo”. eth0 is the wired connection, and “lo” is just a local loopback (127.0.0.1).

Find the “inet” address under eth0 and copy it because it will be used in the next step.

ifconfig

SSH Into Your Server

Windows Users

If you are a windows user you need to first download a SSH client. I recommend using PUTTY. PUTTY is a standalone executable so you won’t have to install anything, just run it and go.

Once you have putty open. Enter your servers IP in the “Host Name” field, leave the port set to 22 and click Open.

puttylogin


Since this is your first time connecting to this server through PUTTY, you will be prompted about a rsa2 key fingerpint, click Yes, and continue.

puttyalert


You’re now ready to sign into the server, enter your username and press enter then you will prompted for you password. Enter the password, press enter once more and YOU’RE IN!

puttyconn

Mac & Linux Users

Unix systems usually come pre-installed with an ssh client. Open a new terminal and run the command below with your credentials. After running this command you may get a prompt about a “RSA” key, type “yes” or “y” then continue. Enter your password and your in!

ssh SERVER_IP_HERE -l USER_NAME_HERE

Installing Apache, MySQL & PHP

This is the easy part of the tutorial, you literally just enter a few commands and you’re done. We will begin by installing Apache.

Apache

sudo apt-get install apache2

Once Apache is done installing, you should now be able to connect to the server through your web browser. Remember the IP you used to connect via SSH? Put that into your web browser and hit enter and you should be presented with a page similar to this.

ipwebbrowser


If you did not get this page when you entered the IP, double check that you are using the correct IP. If you are using the correct IP and still can’t load the page, try rebooting the server with this command.

sudo reboot

MySQL

Thankfully it’s just as simple to install MySQL. Just run the following command.

sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql

In the middle of the MySQL installation you will be prompted to enter a root password. Choose a password, and remember it or write it down. You don’t have to set a password but if you are using this as a production server, it would be wise to set one.

mysqlpass

PHP

Finally we can install the last part of the LAMP stack. PHP!

sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt

It’s usually a good idea to restart Apache after everything is installed so run this command to restart the Apache service.

sudo service apache2 restart




Conclusion

The full LAMP stack is now installed! You can now start developing with PHP. Enjoy!
If you have questions or need help with something, leave a comment below and I’ll respond asap.

Know someone that would find this post interesting? Share it with them!
Share on FacebookTweet about this on TwitterShare on RedditShare on Google+Pin on PinterestShare on TumblrShare on StumbleUpon

Add Comment