Overclock.net › How To's › Install and Configure a basic LAMP server in Ubuntu 11.10

Install and Configure a basic LAMP server in Ubuntu 11.10

This guide will take you step by step, on how to install and configure a basic LAMP server on your Ubuntu desktop.

 

You might be wondering, why you would want to set this up in a desktop environment. I often do this as a web developer, to have a private, instant server that I have full control over, as I typically can test out a lot of things, to know what I need, and simply what works and what doesn't, without having to worry about restrictions that could be placed upon me by a shared host, and it spares me the cost of renting a Virtual Dedicated or Dedicated server. You could also use this guide as a stepping stone to figure out the ins and out of a LAMP server with zero risk.

 

 

Step One: Update Ubuntu first

 

Open up a terminal (keep it open for most of this tutorial):

 

In Terminal Command:
sudo apt-get update && sudo apt-get upgrade

 

This will sync the package managers database with that of the repositories, to ensure you are getting the latest packages and information available. Now you do not have to do this step, if for whatever reason you do not want to upgrade all available packages, as it will not interfere with the guide if you do not.

 

 

Step Two: Install Apache

 

Quote:
sudo apt-get install apache2

 

This will install the basic Apache server, with default libraries and modules for Apache. After it has finished downloading and installing, Open your browser of choice and type in "http://localhost". You should see this:

 

localhost

 

If you do not see this, the service might not be running.

 

 

In Terminal Command:
sudo service apache2 start
 
or 
 
sudo /etc/init.d/apache2 start

 

Either command will work, I personally think the first one is easier to remember, but the second one is more traditional, and eventually Ubuntu might stop supporting the use of the second command in favor of the first one (If they completely gear towards upstart scripts) so it might be useful to just get into the habit now.

 

If you get the "it works" message, please continue, if not make a post or look for a solution.

 

 

Step Three: Install MySQL

 

In Terminal Command:
sudo apt-get install mysql-server

 

After it has done downloading, it will begin the install, in the terminal window this screen will appear:

 

MySQL root password setup

 

 

After you enter a password and hit enter, it will ask you to confirm it (I do recommend setting a root password, and remember it please, as it is something you will need to access it). After the confirmation screen it will finish configure and install MySQL.

 

Step Four: Install PHP, and apache's modules for PHP and the MySQL module for PHP

 

 

In Terminal Command:
sudo apt-get install php5 libapache2-mod-php5 php5-mysql

 

This will install PHP, the apache2 module for php and the module for php to be able to access MySQL. Once that is done, you will need to restart the Apache server for the changes to take place.

 

 

In Terminal Command:
sudo serive apache2 restart 
 
or 
 
sudo /etc/init.d/apache2 restart

 

Now we will test to see if PHP is being used by Apache.

 

In Terminal Command:
sudo nano /var/www/phpinfo.php

 

Once that is open, add the following to it:

 

Inside Nano:
<?php
//display php info to test if PHP is working with apache2.
 
phpinfo;
 
?>

 

ctrl+o to save, ctrl+x to exit out of nano. Now in your browser of choice, go to: http://localhost/phpinfo.php, you should see this screen if Apache is working with PHP.

 

PHP info screen

 

If you get that to appear, you have successfully installed a LAMP server in your Ubuntu. I would suggest changing the Apache document root from /var/www to another folder, like /home/user/public_html, as you don't want to change permissions on anything inside /var/www. I would also recommend using a web interface for helping managing MySQL, there are a few in the repository, I recommend phpmyadmin:

 

In Terminal Command:
sudo apt-get install phpmyadmin

 

Once it is installed, you can access this from "http://localhost/phpmyadmin" even if you move the document root, an alias is setup for it in apache. There is far more to learn about LAMP than this guide covers, as it is to serve merely as a introduction to LAMP and how to install it. If you have more information to contribute to this, I urge you to write a guide as a follow up on LAMP.

Comments

There are no comments yet
Overclock.net › How To's › Install and Configure a basic LAMP server in Ubuntu 11.10