Configuring LAMP on Ubuntu

LAMP is an acronym that defines a group of applications to provide basic web services. Those services are Linux-Apache-MySQL-PHP. There are variants for Windows (WAMP), MacOS (MAMP) and Solaris (SAMP), along with a variety of instructions on how to install them.  Any *AMP platform will allow you to run programs such as WordPress, phpBB, Joomla and many other applications like these.

So what really makes up LAMP?

Linux – Typically, any distribution will work. This article will focus on setting up the “AMP” portion of LAMP and assumes you already have Ubuntu up and running and thus have no need for the “L”.

Apache – Apache is one of the more common, if not most common, web servers on the Internet. The software is open source and maintained by the Apache Foundation. You could use other web server applications, but then that would not be LAMP.

MySQL – MySQL is a very powerful Open Source database server. It is owned and maintained by MySQL AB, which is owned by Sun Microsystems, which is now a subsidiary of Oracle.

PHP – PHP is a scripting language that helps to drive many of the web applications we all use. It provides for the ability to create logic and dynamic content in your web pages. It’s relatively easy to learn and a plethora of books exist that can teach you the basics quickly.

That’s the back story, let’s  get to the install…

Installing Apache

First we need to install the Apache core files. In your Terminal type:

sudo apt-get install apache2

Once the installer finishes, open your web browser and go to:

http://localhost

You should get a message that says “It Worked!!”

Installing PHP

The command is again fairly straight forward:

sudo apt-get install php5 libapache2-mod-php5

Once the install finishes, you need to restart Apache. In your Terminal type:

sudo /etc/init.d/apache2 restart

You may get a warning message, ignore it for now; We’ll fix at the end of the article.

    Restarting web server apache2

… waiting apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName

Now we need to make sure PHP installed correctly. I use gedit, but feel free to substitute with your editor of choice. In your Terminal type:

sudo gedit /var/www/testphp.php

When gedit opens, type in the following code:

<?php phpinfo(); ?>

Save the file and exit your editor.

In your web browser go to http://localhost/testphp.php

You should see a pretty purple/blue and gray web page telling you all about your PHP configuration.

Installing MySQL

Once again, all of the hard work has been done for you. In your Terminal, type:

sudo apt-get install mysql-server

You may be prompted to accept the installation of a few other packages, go ahead and say yes.

If you have not installed MySQL before, you will be prompted to pick a “root” password as well. Make sure you set it to something you’ll remember!

Once you have completed the install, you may need to reconfigure PHP to work with MySQL. If the phpMyAdmin install works below, this may not be necessary. I did do it on my system, and did not run into any issues.

To do this open /etc/php5/apache2/php.ini in your editor (make sure you use sudo) and add:

extension=mysql.so

The best place to put this (for organizational reasons) is under the area labeled:

; Dynamic Extensions ;

Save the file, and restart Apache again.

sudo /etc/init.d/apache2 restart

Installing phpMyAdmin

Now we need to install a cool front end for your MySQL so that you can do administrative tasks the easy way. I have used phpMyAdmin for years – it’s a great front end that lets you do everything you need form a web page.

In your Terminal, type the following command:

sudo apt-get install phpmyadmin

You will be prompted to approve some other packages. Near the end of the install, a dialog will come up asking you what web server you are configuring for. Select Apache2 by pressing the space bar then press Enter to exit.

More files will install, and another dialog will come that will configure your phpMyAdmin install.

Accept the first prompt covering the creation of a database for phpMyAdmin to use.

You will then be asked “Configure database for phpmyadmin with dbconfig-common?”

Select Yes and press Enter

Next you will need to enter the administrative account to use. Typically, this is root, unless you’ve created another account. Once you have entered your account, press Enter and you will be prompted for a password. Use the password you created above, or your own if you already had MySQL configured. Press Enter, confirm the password and press Enter again.

You can test if phpMyAdmin is working, by pointing your web browser to:

http://localhost/phpmyadmin/

If you see a login box, you’re all set.

If not, it’s troubleshooting time…. The most common issue is the link between where phpMyAdmin is installed and your webserver folder /var/www/ was not created. To create the link, type the following command. You only need to do this if you do not see phpmyadmin in your /var/www folder! In your Terminal type:

sudo ln -s /usr/share/phpmyadmin/ /var/www/phpmyadmin

You can then verify the link is there and test in your web browser again.

Fixing the ServerName issue

This issue is caused if you don’t have DNS that allows your server to figure out who it is on it’s own. It’s not really a bug, and your server will work fine either way but, if it bothers you, here’s how to fix it.

Edit apache.conf located in /etc/apache2 (on my system) and add the following under the ServerRoot line:

ServerName “YourServerName” where YourServerName is the name of your computer.

Then type the following command to verify it worked.

sudo /etc/init.d/apache2 restart

The service may take a moment and then you will see an [ OK ] regarding the restart.

Now that the install is complete, you have a fully functional LAMP Server.

Credit

The Internet At Large

Please do let me know if you find any errors in the document, I wrote it as I was doing the install myself.

This entry was posted in System Administration, Ubuntu and tagged , , , , , . Bookmark the permalink. Follow any comments here with the RSS feed for this post. Post a comment or leave a trackback.

1 Trackback

  1. […] Configuring LAMP &#959&#1495 Ubuntu « It I&#1109 W&#1211&#1072t It I&#1109 […]

Leave a Reply

%d bloggers like this: