HowtoForge - Linux Howtos in English English|HowtoForge.de - Linux-Howtos auf Deutsch Deutsch

Installing LAMP On Ubuntu For Newbies

Submitted by Cargoship (Contact Author) (Forums) on Fri, 2007-07-13 15:57. :: Ubuntu

Installing LAMP On Ubuntu For Newbies

In this guide I will show you how to install a LAMP system. LAMP stands for Linux, Apache, MySQL, PHP. The guide is intended to help those who have very little knowlegde of using Linux.

 

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.

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

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

sudo apt-get install php5 libapache2-mod-php5

Step 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.

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

sudo gedit /var/www/testphp.php

This will open up a file called phptest.php.

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

<?php phpinfo(); ?>

Step 3. Save and close the file.

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

http://localhost/testphp.php

The page should look like this:

Test PHP Page

Congrats you have now installed both Apache and PHP!

 

Install MySQL

To finish this guide up we will install MySQL. (Note - Out of Apache and PHP, MySQL is the most difficult to set up. I will provide some great resources for anyone having trouble at the end of this guide.)

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

sudo apt-get install mysql-server

Step 2 (optional). In order for other computers on your network to view the server you have created, 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.

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

mysql -u root

Following that copy/paste this line:

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

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

Step 4. We are now going to install a program called phpMyAdmin which is an easy 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

 

The End

Quick note to anyone who encountered problems with setting up the MySQL password, please refer to this page: MysqlPasswordReset

I applaud everyone who has taken the time to read this guide. This guide is also my first ever so I would love to hear back from the public on what you guys think! Just don't be too harsh. ;)

If you have questions about installing any part of LAMP just drop them in the comment box and I will do my best to help you out.


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Please do not use the comment function to ask for help! If you need help, please use our forum: http://www.howtoforge.com/forums
Comments will be published after administrator approval.
Submitted by Zmetser (Contact Author) (Forums) on Thu, 2008-05-22 11:10.

First: Excellent work dude!

Second: I had to copy phpmyadmin into my document root directory to work http://localhost/phpmyadmin, with this command in shell:

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

# /usr/share/phpmyadmin/ is the directory where phpmyadmin installed
# /var/www/ is your document root directory

Submitted by mcmarwa (Contact Author) (Forums) on Sun, 2008-03-02 13:30.

Thanks!  This worked very well, with one minor glitch for my particular case.  After installing mysql, I needed to start mysql with:

sudo /etc/init.d mysql start

Then everything else worked. 

Submitted by srodden (Contact Author) (Forums) on Sat, 2007-10-06 11:00.
Thanks very much for the howto. i installed on Oct 5 and the php.ini you refered to near the end has no ;extension=mysql.so line to uncomment. Not able to log in using the root and password  set earlier but i haven't spent any time troubleshooting yet.
Submitted by zaphu (Contact Author) (Forums) on Mon, 2007-08-20 04:43.
one can also add the desktop GUI to the server installation by following this guide on zaphu.com Enjoy your new LAMP server! 
Submitted by aromaman (Contact Author) (Forums) on Sun, 2007-08-19 20:52.

Hi cargoship. I had problems, I'm afraid, and did not manage to get lamp operational. I've posted my questions on the forum, as requested by the admin. I'm new to Linux so I suspect I'm the problem, not your procedure.

 

Submitted by majikins (Contact Author) (Forums) on Tue, 2007-08-07 06:49.
Hi Great howto - thanks! A newbie would not know to type 'exit' after step 3(MySQL section)to get to step 4. Cheers
Submitted by douglaslopezt (Contact Author) (Forums) on Sat, 2007-07-28 01:45.
Excelent How-to, very usefull, very simple and efficent. Thanks a lot.
Submitted by DJ_Maiko (Contact Author) (Forums) on Wed, 2007-07-18 23:09.

First off, thanks a ton for the awesome how-to. My only question is:

Do I have to be connected to the internet to get all of this started? I ask because I plan to set this up on a separate machine & I haven't picked up a router/nat yet. So I just want to make sure if I need that in place for everything to work properly w/out having to re-do it again if I start w/out internet connectivity.

Submitted by Cargoship (Contact Author) (Forums) on Thu, 2007-07-19 09:44.
@DJ_Maiko - Nope you do not need an internet connection to get LAMP to work.
Submitted by Cargoship (Contact Author) (Forums) on Wed, 2007-07-18 14:29.

Thanks for the comments everyone.

@ IronHide - Now just do whatever you want with your brand new installation!

@locutus_of_borg - I re-installed LAMP and it still seems to be in php.ini, but you are right it is also in mysql.ini. I am not sure it if makes a difference though.

@mihai331 - I think I might edit the guide to explain more the purpose of what people are doing. Like what they are downloading, and why they would edit this and that. Also maybe a few pictures for extra clarification.

1
next page
last page