Installing Apache2 With PHP5 And MySQL Support On Ubuntu 9.10 (LAMP)

Want to support HowtoForge? Become a subscriber!
 
Submitted by falko (Contact Author) (Forums) on Tue, 2009-11-24 19:49. :: Ubuntu | Apache | MySQL | PHP

Installing Apache2 With PHP5 And MySQL Support On Ubuntu 9.10 (LAMP)

Version 1.0
Author: Falko Timme <ft [at] falkotimme [dot] com>
Follow me on Twitter
Last edited 11/09/2009

LAMP is short for Linux, Apache, MySQL, PHP. This tutorial shows how you can install an Apache2 webserver on an Ubuntu 9.10 server with PHP5 support (mod_php) and MySQL support.

I do not issue any guarantee that this will work for you!

 

1 Preliminary Note

In this tutorial I use the hostname server1.example.com with the IP address 192.168.0.100. These settings might differ for you, so you have to replace them where appropriate.

I'm running all the steps in this tutorial with root privileges, so make sure you're logged in as root:

sudo su

 

2 Installing MySQL 5

First we install MySQL 5 like this:

aptitude install mysql-server mysql-client

You will be asked to provide a password for the MySQL root user - this password is valid for the user root@localhost as well as root@server1.example.com, so we don't have to specify a MySQL root password manually later on:

New password for the MySQL "root" user: <-- yourrootsqlpassword
Repeat password for the MySQL "root" user: <-- yourrootsqlpassword

 

3 Installing Apache2

Apache2 is available as an Ubuntu package, therefore we can install it like this:

aptitude install apache2

Now direct your browser to http://192.168.0.100, and you should see the Apache2 placeholder page (It works!):

Apache's default document root is /var/www on Ubuntu, and the configuration file is /etc/apache2/apache2.conf. Additional configurations are stored in subdirectories of the /etc/apache2 directory such as /etc/apache2/mods-enabled (for Apache modules), /etc/apache2/sites-enabled (for virtual hosts), and /etc/apache2/conf.d.

 

4 Installing PHP5

We can install PHP5 and the Apache PHP5 module as follows:

aptitude install php5 libapache2-mod-php5

We must restart Apache afterwards:

/etc/init.d/apache2 restart

 

5 Testing PHP5 / Getting Details About Your PHP5 Installation

The document root of the default web site is /var/www. We will now create a small PHP file (info.php) in that directory and call it in a browser. The file will display lots of useful details about our PHP installation, such as the installed PHP version.

vi /var/www/info.php

<?php
phpinfo();
?>

Now we call that file in a browser (e.g. http://192.168.0.100/info.php):

As you see, PHP5 is working, and it's working through the Apache 2.0 Handler, as shown in the Server API line. If you scroll further down, you will see all modules that are already enabled in PHP5. MySQL is not listed there which means we don't have MySQL support in PHP5 yet.

 

6 Getting MySQL Support In PHP5

To get MySQL support in PHP, we can install the php5-mysql package. It's a good idea to install some other PHP5 modules as well as you might need them for your applications. You can search for available PHP5 modules like this:

aptitude search php5

Pick the ones you need and install them like this:

aptitude install php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl php5-json

Now restart Apache2:

/etc/init.d/apache2 restart

Now reload http://192.168.0.100/info.php in your browser and scroll down to the modules section again. You should now find lots of new modules there, including the MySQL module:

 

7 phpMyAdmin

phpMyAdmin is a web interface through which you can manage your MySQL databases. It's a good idea to install it:

aptitude install phpmyadmin

You will see the following questions:

Web server to reconfigure automatically: <-- apache2
Configure database for phpmyadmin with dbconfig-common? <-- No

Afterwards, you can access phpMyAdmin under http://192.168.0.100/phpmyadmin/:

 

8 Links


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by Travel and Tour... (not registered) on Mon, 2011-05-02 10:56.

This is good, I'll be applying this to my system and see if it really work and helps. This look so helpful and convenient to use.

Submitted by Anonymous (not registered) on Fri, 2010-12-24 15:16.

Thanks. I did everything you showed except for the MySQL (I would like to use Oracle). I was trying to place the same php test file under a webapps directory without success. It looks like if the webapp is set up for JSP, then I guess it does not know about php.

Thanks again,  Mark L.

 

 

Submitted by RonanOD (not registered) on Thu, 2010-08-05 16:21.
Great Howto! Thanks a million...
Submitted by Rich (not registered) on Wed, 2010-05-19 15:18.

Minor gripe:

I can't escape the feeling you should have added one more step to your GREAT tutorial -- I logged into phpMyAdmin and it seems you me you might have included some advice about what to do with this page.

 

Thanks.

 

Submitted by Anonymous (not registered) on Sat, 2010-05-15 22:23.

Thank you for the simple and clear walk-through--it was very easy and is very much appreciated!

Submitted by Anonymous (not registered) on Fri, 2010-04-30 13:21.

HI, this artical is great.... i used this ... its very easy to learn... thanks for this ..............

Thanks

Jatin

Submitted by Anonymous (not registered) on Sun, 2010-04-11 22:15.
this is an amazing tutorial. been trying to get this stuff setup on mac and scratching my head. such a quick setup process on ubuntu.
Submitted by Shahzad (not registered) on Wed, 2010-03-17 12:59.

Great tutorial...

I couldn't move forward from the following step 

vi /var/www/info.php this command opens editor but do nothing and i have to exit from terminal

where to write the following code

<?php
phpinfo();
?>

aptitude search php5 this works fine gives a list of options

aptitude install php5-mysql php5-curl php5-gd php5-idn php-pear
php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming
php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy
php5-xmlrpc php5-xsl php5-json

/etc/init.d/apache2 restart  this command fails and displays the following information

 * Restarting web server apache2                                                apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
(13)Permission denied: make_sock: could not bind to address [::]:80
(13)Permission denied: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs

aptitude install phpmyadmin this also fails and displays following msg

shahzad@shahzad-desktop:~$ aptitude install phpmyadmin
Reading package lists... Done
Building dependency tree      
Reading state information... Done
Reading extended state information     
Initializing package states... Done
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
shahzad@shahzad-desktop:~$

now please suggest me what to do

 

Thanks & Regards

Shahzad

Submitted by Anonymous (not registered) on Tue, 2010-05-25 05:38.

frist become a super userver

$sudo su

tell put the install commond

# aptitude install phpmyadmin

Submitted by chamala (not registered) on Mon, 2010-04-05 19:57.

Hey guys tx fr de tutorial...it was nice....

hi Shahzad,

if you are using vi editor, you have to use Esc+i (press Escape and i keys) to insert or enter values in a file. to save the file use Esc+wq!, Esc+q! for exit without modifications.

 

i hope this helps u....

have a nice day....

 

Submitted by MrBadger (not registered) on Fri, 2010-02-26 00:55.

Yes, great tutorial.

Worked just as advertised.

 One note however. If you install PhpMyAdmin the default user name is "root" and the associated password. Took me a moment to figure out how to create a new user until I realized what it had defaulted to.

Submitted by Anonymous (not registered) on Tue, 2010-02-23 22:39.
Great tutorial, thanks !!
Submitted by Anonymous (not registered) on Fri, 2010-01-29 22:54.
Thank you very much))
Submitted by AKC (not registered) on Tue, 2010-01-26 15:02.
Great tutorial, thank you very much.
Submitted by JimmyK (not registered) on Mon, 2010-01-25 01:46.

If you want to install it all in one go, just use:

sudo tasksel install lamp-server

You'll have to do phpmyadmin yourself if you want it, but that command will set up all the rest for you.

Submitted by tarabo (not registered) on Wed, 2010-01-20 20:33.

Step 7.

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

Submitted by Anonymous (not registered) on Thu, 2011-12-08 21:25.
Big help!!
Submitted by ejac (not registered) on Wed, 2011-05-11 14:35.
What if you already transfer the webroot to /user/public_html?
Anyway its still the same you just have to change its directory... :) Thanks for the contribution.. :)
Submitted by Jemli Aymen (not registered) on Fri, 2011-02-18 11:32.
:-) thks
Submitted by Deb (not registered) on Mon, 2010-04-26 07:30.

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

That made my day!

I can not thank you enough! Excellent tutorial , brief and to-the-point !!

Best regards, 

-Deb

 

Submitted by Anonymous (not registered) on Thu, 2009-12-24 17:56.
thanks a lot..  very nice tutorial.
Submitted by heiner (not registered) on Mon, 2009-12-21 11:29.
very nice summary. saves a lot of work. THANKS !!!!
Submitted by Anonymous (not registered) on Tue, 2009-12-15 04:27.
Thanks for the great information.  This really made it simple to install :)
Submitted by Anonymous (not registered) on Thu, 2009-12-03 17:21.
Maybe you also could add how to get ruby, ruby on rails to this.
Submitted by don (not registered) on Fri, 2009-11-27 00:32.
When I installed and started apache2 I got this message * Restarting web server apache2 apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName ... waiting apache2: Could not reliably determine the server's fully qualified domain name. Using 127.0.1.1 for ServerName The rest of the installation went fine (substituting 127.0.1.1 instead of 192.168.0.100) until I installed phpmyadmin. Then when I browsed to 127.0.1.1/phpmyadmin I got a 404-not found message. I searched for phpmyadmin but could not locate it. For folk (read 'idiots') like me it might be a good idea to include some guidance on what to do when things don't work out the way they should :)
Submitted by Dasha Salo (not registered) on Tue, 2009-12-01 12:11.

To make PhpMyAdmin work try to configure apache2.conf to use PHPMyAdmin via browser:

$ sudo gedit /etc/apache2/apache2.conf

Then insert the line below into apache2.conf:

Include /etc/phpmyadmin/apache.conf

Dasha

Submitted by Proteus (not registered) on Sat, 2009-11-28 18:17.

This is one of the serious omissions in this article/tutorial. One should never leave the Apache directive ServerName at its default value. This default is useless. It should always be explicitly set to something useful.

It is a good idea, for example, to include the port in ServerName.

The name has to resolve, so unless you want to share only the IP address, it should be a name that will resolve under DNS.

 

Submitted by chenhaw (not registered) on Thu, 2009-11-26 09:51.
I suggest to add in FTP installation guide.
Submitted by Anonymous (not registered) on Wed, 2009-11-25 00:44.
"sudo su" is NEVER necessary, use "sudo -i" to setup the environment properly. Telling people to use "sudo su" is just bad practice.
Submitted by jeremy (not registered) on Sat, 2009-12-19 08:23.
well i cant say much for this guy but i think it is grate what you guys are doing for the new linux guy that knows a lot on windows but trying to find his way to the lite