Installing LAMP On Ubuntu For Beginners

In this guide we will show you how to install Apache, PHP and Mysql on Ubuntu Linux. This is a very easy how-to..

Install Apache

To start off we will install Apache.

1. Open up the Terminal (Applications > Accessories > Terminal).

2. Copy/Paste the following line of code into Terminal and then press enter:

sudo apt-get install apache2

3. The Terminal will then ask you for you're password, type it and then press enter.

 

Testing Apache

To make sure everything installed correctly we will now test Apache to ensure it is working properly.

1. Open up any web browser and then enter the following into the web address:

http://localhost/

You should see a folder entitled apache2-default/. Open it and you will see a message saying "It works!" , congrats to you!

 

Install PHP

In this part we will install PHP 5.

1. Again open up the Terminal (Applications > Accessories > Terminal).

2. Copy/Paste the following line into Terminal and press enter:

sudo apt-get install php5 libapache2-mod-php5

3. In order for PHP to work and be compatible with Apache we must restart it. Type the following code in Terminal to do this:

sudo /etc/init.d/apache2 restart

Test PHP

To ensure there are no issues with PHP let's give it a quick test run.

1. In the terminal copy/paste the following line:

sudo gedit /var/www/test.php

This will open up a file called phptest.php.

2. Copy/Paste this line into the phptest file:

<?php phpinfo(); ?>

3. Save and close the file.

4. Now open you're web browser and type the following into the web address:

http://localhost/test.php

The page should look like this:

Congrats you have now installed both Apache and PHP!

 

 

Install MySQL

To finish this guide up completely we will install MySQL.  Apachem mysql and php is the best combination for webapplications, e-commerce websites .. anything and everything webbased...

1. Once again open up the amazing Terminal and then copy/paste this line:

sudo apt-get install mysql-server

It will ask you to assign password root user (mysql adminstrator , not your linux systems root). Assign appropriate password at this stage. you can also change/assign it later.

you will see it in a while how to change mysql administrator (also known as root) password. Don't worry if it doesn't ask for password while installation.

2 (optional). You can strictly bind mysql to listen on specific IP Address you want it on (Note: you must assign that ip address on mysql server where you have installed it), you must first edit the "Bind Address". Begin by opening up Terminal to edit the my.cnf file.

gksudo gedit /etc/mysql/my.cnf

Change the line

bind-address = 127.0.0.1

And change the 127.0.0.1 to your IP address.

3. This is where things may start to get tricky. Begin by typing the following into Terminal:

mysql -u root -p

Note: If you have assigned root user (mysql administrator) password during mysql installation then type it otherwise just press Enter.

Following that copy/paste this line:

mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('yourpassword'); 

(Alert ! You need to do this if you have not assigned password previously, or this is the way to change root password in mysql)

(Make sure to change yourpassword to a password of your choice.)

4. We are now going to install a program called phpMyAdmin which is an easy webbased tool to edit your databases. Copy/paste the following line into Terminal:

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

After that is installed our next task is to get PHP to work with MySQL. To do this we will need to open a file entitled php.ini. To open it type the following:

gksudo gedit /etc/php5/apache2/php.ini

Now we are going to have to uncomment the following line by taking out the semicolon (;).

Change this line:

;extension=mysql.so

To look like this:

extension=mysql.so

Now just restart Apache and you are all set!

sudo /etc/init.d/apache2 restart

Back to top