How to Install Apache, MySQL, and PHP on your Linux Box
Putting the AMP in your LAMP server
Hello and welcome! This is my first article / guide, so let’s get right into it.
This is intended as a guide for web developers who are new to Linux (namely Kubuntu) and wish to setup a local LAMP server on their machine. For those of you who don’t know, LAMP stands for Linux, Apache, MySQL, and Perl / Python / PHP, although in this case the ‘P’ is for PHP only. When all four of these are installed on a machine, it is a full-blown web-server capable of running complex web applications.
In my case, I have installed Kubuntu 8.04 (Hardy Heron) on my machine using the standard desktop installation, which does not come with Apache, MySQL, or PHP. To be specific, we will be using the following applications:
* Apache2
* MySQL 5
* PHP 5
All of these applications are available through the Adept Package Manager,which is a fast and convenient way to install and uninstall applications in Debian-based Linux systems. Click on the link above for a guide on how this works.
For simplicity, I will assume you know how to operate Adept and have installed at least one package before. Click on the K-Menu, go to ‘System‘, and select ‘Adept Manager - Manage Packages‘ from the list. When prompted, enter your root password and you will see Adept’s package manager interface.
Now, in the search bar, type ‘apache‘. After a short moment, you should see a list of packages. The very first one should be ‘apache2‘. Click on the arrow next to it and select ‘Request Install‘. Now, type into the search bar ‘mysql‘ and this time you will need to scroll down a ways to find the package you are looking for: ‘mysql-server‘. Click on the arrow and select ‘Request Install‘ again. I would also recommend selecting the package ‘mysql-admin‘ for a convenient GUI for managing MySQL server, but that is purely optional. Finally, type ‘php‘ into the search bar and scroll a ways down to find ‘php5‘. Once again, click the arrow and choose ‘Request Install‘.
After selecting these 3-4 packages (depending on whether or not you installed the MySQL Admin GUI), select ‘Apply Changes‘ at the top of Adept to install the packages. This may take a while, so now is an excellent time to take a break and get a drink.
After the installation is complete there is a couple of very important steps to take in order to save yourself a lot of frustration. The first and foremost, is to clear your browser cache! I’m not entirely sure why this is so important, but trust me, it is. If you are running Mozilla Firefox, go to the ‘Tools‘ menu, select ‘Clear Private Data‘, and uncheck everything except for the ‘cache‘ checkbox. You can clear out other information as well, but make sure cache is selected.
The other important step to take is to make sure that php files are parsing correctly. Go to your System Menu (the one next to the K Menu) and select anything, for example, ‘Home‘. The root folder is not in this menu, so you will have to navigate to the right folder anyways. For simplicity, select the ‘Home‘ folder from this menu.
On the left-hand side you should have a column labeled Bookmarks, with an option for Root. Select that, then click on the folder for ‘etc‘. Right-click on the folder named ‘apache2‘ and select from the ‘Action’ menu ‘Open as root‘. Enter your password to continue.
In this folder, select the folder ‘mods-available‘ and look for the file named ‘php5.conf‘. Right-click on this file and select ‘Edit as root‘ and make sure the second line says something like
‘ AddType application/x-httpd-php .htm .html .php .phtml .php3‘
In my case, all I had to do here was add ‘.htm .html ‘ before the ‘.php’ section. This is so that if you have PHP code inside an htm or html file, it will be parsed instead of showing the raw code.
Save your changes, and depending on which editor you used, you might want to delete the temporary ‘~php5.conf‘ file that it creates as a backup. It should not hurt anything to leave it there, but I like to delete the extra backup files to prevent clutter.
In any case, make sure to restart your computer at this point to make sure that the apache web server picks up the configuration changes. You can probably accomplish the same effect by just restarting the apache service, however I haven’t done that yet and restarting the system seemed like a simpler approach.
Alright, now we’re getting to the fun part! Open your favorite web browser and type in the address bar ‘http://localhost‘ to see if apache is running properly. If it is not, you can blame me and probably find some help on the official Ubuntu/Kubuntu forums, however if it is running, it should show the words ‘It Works!‘ in your web browser. We’re almost done now…
All web files will be hosted from ‘/var/www‘. To make sure php is working properly, we will need to first navigate to that folder. Select ‘System Menu‘ -> ‘Home‘, and then select ‘Root‘ from the bookmarks section on the left. Click on the ‘var‘ folder to open it and then right click on ‘www‘ and choose ‘Action‘ -> ‘Open as root‘.
In here, right-click on ‘index.html‘ and choose ‘Action‘ -> ‘Edit as root‘. Add this line right before the closing tag for the body (body tag > added line of code | below):
![]()
![]()
Save your changes, and refresh your browser window. You may want to clear your browser cache again, just to be sure. You should see ‘It Works!‘ followed by a neatly formatted table showing all of the current settings for PHP. If it did not, right-click on the page from your browser and click ‘view source‘ or whatever the option is called for your browser to see the HTML code directly.
If the output from view source shows the “?PHP” part of the code, then something is wrong. PHP code should never be sent to the browser without being parsed. If you haven’t already, try restarting your PC again, otherwise you are on your own (along with the thousands of others with similar problems). Again, I recommend checking the official forums for Ubuntu / Kubuntu.
Hopefully, all went well and you saw the neatly formatted PHP text. To make sure that MySQL is working correctly, I will assume you have the GUI installed. I said it was optional, and it is, but it’s the easiest way I know of for verifying that everything installed correctly. Go to the K-Menu, select the ‘Development‘ menu and choose ‘MySQL Administrator‘.
For the server hostname, choose ‘localhost‘. The login name will be ‘root‘, and the password is the root password for your machine. If you can connect OK, then all is well. If not, fall back on the official forums or google to find a solution, but I suspect that this will work right off the bat.
That’s all I have for this guide for now. There is a mountain of information for all three applications mentioned here, and this guide barely scrapes the surface of any of them. Expect some guides in the future for configuring Apache, MySQL, or PHP.
Comments
4 Responses to “How to Install Apache, MySQL, and PHP on your Linux Box”
Leave a Reply





you busy bastard, you know i pay beer for help
[...] the internet, I found a blog describing a more detail steps to do the post-install configuration. Basically, we need [...]
This is a rarity–a clearly-written step-by-step guide that works the first time. I have my first lamp server in less time than it took to drink a beer. Thank you.
The only problem I had: whenever I put my pointer on ‘index.html’ in the file manager, a box popped up saying some amarok file had an illegal menu entry, and I couldn’t open the index file. So I just unistalled amarok and deleted leftover amarok* files. Then it was smooth sailing.
Thanks for the great feedback man! I’m sure Joe will be happy to hear it. BTW He also wrote another Linux article that sounds like it may help with the problem you are running into.
AddAsPodcast Bug for Amarok on Kubuntu
Cheers!