How to setup a LAMP stack on Ubuntu
If you’re reading this and have somehow came up with the question, “What is LAMP?” Well, simply put LAMP stands for Linux, Apache, MySQL, and PHP.
This has been an article I did not want to write, since I know so many people have written article’s about this topic. The length of this article alone will be enough to put me over my word limit. There are some key things I want to discuss in some upcoming tutorials with respect to installing a LAMP stack on Ubuntu.
So, whether you’re running the server version or you’re running the GUIed version of Ubuntu, this tutorial will tell you how to setup a LAMP stack on a laptop, or a server.
NOTICE: This is already assumes you have already installed Ubuntu.
If you have a small laptop sitting around the house and are not using it, you might want to consider using the laptop as a server. It’s so lovely to have, I use it for many purposes. My clients love checking my progress of their websites through my personal home server.
If you own a website you can setup a subdomain to direct it to your home’s IP address. Now, depending on your ISP you might have port 80 blocked.
Installing Dependencies (PHP, Apache, MySQL)
Step 1 – Installing Apache
Apache is the background worker of the ‘join effort’. Simply put, apache is what creates the handshake between two computer communicating over TCP/IP. The default port Apache uses is port 80.
Open your terminal, or console if you will, and type the following Unix commands:
sudo apt-get update
The above simply downloads the package list from http://linux.die.net/man/8/apt-get. This is important because we want to install the newest dependencies. Now install the latest version of apache using this command:
sudo apt-get install apache2
That is pretty much it for apache. Easy right? This is why I love linux machines. Simple. Point your browser to your severs IP address, or if you are running it locally, simply type ‘localhost’ or 127.0.0.1 in your web browser. You can access this on another machine as well, just type in the machine’s IP address. The IP address for my Machine on my local network is 192.168.1.135. I set it up so it is static and I can access if anytime I need to.
Before we move on to PHP, I would like to modify a config file. Type the following on your console:
sudo nano /etc/apache2/mods-enabled/dir.conf
Or if you want to edit it using a GUI method:
sudo gedit /etc/apache2/mods-enabled/dir.conf
You are going to need to add index.php at the beginning of all the index files. This is so ‘index.php’ taxes precedence. Here is what mine looks like:
DirectoryIndex index.php home.php index.php5 index.html index.cgi index.pl index.php index.xhtml index.htm
Step 2 – Installing PHP
A little history of PHP, it was created in 1994 by Rasmus Lerdorf. As you notice, when you program in PHP, a lot of the syntax is actually from C. So C/C++ developers will love PHP. PHP originally stood for “Personal Home Page,” but now is ironically defined like a recursive algorithm as “PHP: Hypertext Processor.” Interesting isn’t? If you want to know more do a Google search for history of PHP.
Ok, to install PHP open your terminal again and type this command to install the dependencies:
sudo apt-get install php5 php5-mcrypt libapache2-mod-php5
Step 3 – Install MySQL
Next, we will install MySQL. It is important to note that there are other database management systems out there like Oracle DB, and SQL. MySQL does the job just fine for web servers and I believe most of the web uses MySQL as their database of choice because of the popular ‘LAMP’ stack setup.
Now to install MySQL open up your terminal again. Copy and paste this into your terminal:
sudo apt-get install mysql-server php5-mysql libapache2-mod-auth-mysql
Go through the steps and remember, MySQL should ask you to input a password during the installation.
MySQL should ask you to ‘Remove Anonymous users, disallow root login remotely, and reload privlage tables.’
Remove anonymous users? [Y/n] Y
Make sure you disallow root login remotely:
Disallow root login remotely? [Y/n] Y
MySQL comes with a ‘test’ database installed. You can have MySQL remove it here, just type ‘Y’.
Remove test database and access to it? [Y/n] Y
This is to ensure that all changes you made so far take effect. This includes making sure the password you set gets reloaded into the database.
Reload privilege tables? [Y/n] Y
Time to Test PHP and Apache
So we can simplify this, type this into the console:
sudo gedit /var/www/my_phpinfo.php
Now to learn more about the following script check out php.net/phpinfo to find out more. Now copy and paste this into your GUI editor:
If you are on the machine you have installed everything type http://localhost or http://127.0.0.1 You should get something like this:
See More: How to Set Up XAMPP