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

Version 1.0
Author: Falko Timme , Christian Schmalfeld <c [dot] schmalfeld [at] projekfarm [dot] de>
Follow me on Twitter
Last edited 10/17/2011

LAMP is short for Linux, Apache, MySQL, PHP. This tutorial shows how you can install an Apache2 webserver on an Ubuntu 11.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.23. 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:

apt-get 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:

apt-get install apache2

Now direct your browser to http://192.168.0.23, 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:

apt-get install php5 libapache2-mod-php5

We must restart Apache afterwards:

/etc/init.d/apache2 restart

Share this page:

20 Comment(s)

Add comment

Comments

From: deeplite at: 2011-10-22 02:13:42

sudo apt-get install aptitude

sudo aptitude install lamp-server

From: Rob at: 2011-10-31 10:19:43

The result of running the previously-mentioned commands:

$ sudo aptitude install lamp-server
Couldn't find any package whose name or description matched "lamp-server"
Couldn't find any package whose name or description matched "lamp-server"

Trying to install the same package using apt-get:

$ sudo apt-get install lamp-server
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package lamp-server

From: Anonymous at: 2011-11-08 20:40:54

sudo apt-gets install lamp-server^

 

he was missing the ^

From: samita at: 2012-03-13 16:23:39

thanks a lot for this article. It's amazing how a small character like ^ has kept me in the dark for weeks now

From: Ronald Matte at: 2011-11-23 23:46:13

I just installed LAMP on a Dell Opti-Plex I recently loaded with Ubuntu 11.10 according to the article.

Everything went so smooth I had to double check to make sure everything was  installed properly. Yes. apt-get is now my best friend, and this article and the tasks herein are on-point.

My first encounter with a non-MS OS was SCO Unix (way) back in 1992.

Thank you to all who contribute their long-labored hours and talent to developing and maintaining such a wonderful flavor of Linux.

 

Ronald Matte

nrmuscom@yahoo.com

From: Anonymous at: 2012-03-05 02:15:31

this couldnt of been any easier on ubuntu 11.10

From: Ovidiu at: 2012-04-18 14:55:05

thank you it it works great

From: Anonymous at: 2012-08-09 18:33:36

use the ip of your server or (your pc)

From: Anonymous at: 2011-10-20 22:59:49

Why not just run "sudo apt-get install lamp-server^ phpmyadmin"?

From: Rob at: 2011-10-31 10:36:26

This worked for me:

sudo apt-get install lamp-server^ phpmyadmin

From: Anonymous at: 2012-02-15 11:11:21

Hello. I am new. I made it. But how tu make it visible for the others in my network?:D

 THX!

From: Anonymous at: 2012-03-14 00:51:32

if you have a firewall installed, you will need to open a port, If not you just need to know the ipaddress of the computer to access it.

The apache server runs on port 80, you can verify this by doing something like this 

http://192.168.0.2:80 or http://192.168.0.2 from any other machine on your network. Change the ipaddress of the machine to match the server machine, you can find this out easily by typing "ifconfig" in your terminal without quotes. depending on whether its wired or wireless you will want either eth0 or wlan0 in most cases. the ip address will be listed as follows (in my case its this)

inet addr:192.168.0.2  Bcast:192.168.0.255  Mask:255.255.255.0

The first ipaddress is the ip that your router has assigned to your machine the rest you can ignore for these purposes. If you intend keeping the machine on for a length of time, you may want to consider setting up a dedicated ip in the router for the machine, the method for this is way beyond the scope of this page, but you will find plenty of advice on the net for your specific router.

If you want to access it locally on the machine itself, 127.0.1.1 (thats how it installed on mine) 

From: Anonymous at: 2011-10-25 03:59:43

Excellent guide thank you very much. It helped me a lot, everything worked perfectly.

From: Chris at: 2012-01-25 06:07:52

Maybe I am a noob but wtf ever.... when i try vi /var/www/info.php I can't figure out what to do. I have gotten every sort of pattern error. All i get is "swap" files. No info.php. Just info.php.swp

 

Any help??

From: Anonymous at: 2012-01-26 18:35:08

sudo gedit /var/www/infp.php

From: Anonymous at: 2012-03-14 00:37:54

its better to use "gksu gedit" instead of "sudo gedit"

From: Anonymous at: 2012-02-04 04:51:59

I had to add:

 ln -s /usr/share/phpmyadmin phpmyadmin

to get it working

From: Anonymous at: 2012-02-05 02:01:58

Sorry, posted too quickly; it should read:

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

From: Dmitry at: 2012-03-22 02:41:34

Very good tutorial, thanks. One comment: to make phpmyadmin to work needed to add a link as following: 

sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf.d/phpmyadmin.conf

sudo /etc/init.d/apache2 reload

 (from: https://help.ubuntu.com/community/phpMyAdmin)

From: discount six flags tickets at: 2012-06-13 09:04:11

"http://192.168.0.2:80 or http://192.168.0.2 from any other machine on your network. Change the ipaddress of the machine to match the server machine, you can find this out easily by typing "ifconfig" in your terminal without quotes. depending on whether its wired or wireless you will want either eth0 or wlan0 in most cases. the ip address will be listed as follows (in my case its this)" - this worked for me.