Bin-Blog logoBin-Blog

Learn about the latest in Web Development – as soon as I do.

Installing LAMP(Apache Web Server/PHP/MySQL) in Debian/Ubuntu

By • Sep 16th, 2008 • Category: Apache, Database, Linux, PHP, Web Development

LAMP - Linux, Apache, MySQL, PHP

Installing the LAMP environment on a Linux system is easy if you are comfortable with using the native package management software. If you on a Red Hat/Fedora/CentOS system, that will be yum – and for Debian/Ubuntu systems, that will be apt. This tutorial shows you how to install Apache 2, PHP 5 and MySQL 5 in Debian using apt.

Before installation, a few points to remember. These instruction are not for a production environment – this is for a development environment. To install the software, you need root access. You can get that using this command…

su -
[Enter root password]

Installing Apache 2

Use this command to install Apache 2.

apt-get install apache2

Make sure you specify ‘apache2′ – or else, apache 1.3 will be installed.

PHP Logo

Install PHP 5

Now, install the PHP 5 packages…

apt-get install libapache2-mod-php5 php5-cli php5-common php5-cgi

No go to the folder /etc/apache2/sites-enabled/ and edit the file in that directory(usually 000-default). Find the line that says
RedirectMatch ^/$ /apache2-default/
and remove it.

Now your document root is /var/www/ – place all your HTML documents and scripts in this folder. If you want to make some other configuration changes, edit the configuration files at /etc/apache2/apache2.conf

I also had to make the following changes…

  • Changed the owner of /var/log/apache2 to www-data – I used the command chown www-data:www-data apache2
  • Created an empty file at /etc/apache2/httpd.conf

This was to fix a few errors I saw on my system – you may not have to do it.

Install MySQL

This is the command to install MySQL server, its client and PHP’s MySQL libraries…

apt-get install mysql-client mysql-common mysql-server php5-mysql

Finally, Install the other packages you need as well

apt-get install php5-sqlite php5-gd ...

Testing the System

Go to your document root(/var/www) and create a php files called ‘info.php’ and put this code inside that…

<?php
phpinfo();

Start the Servers

First, turn on the MySQL database server…

/etc/init.d/mysql start

Then, start the Apache Web Server…

/etc/init.d/apache2 start

Now fire up a browser and go to localhost – you should see a file listing page with a ‘info.php’ in the list. Click on that link – if you see a PHP information page, your web server is setup correctly.

To make sure MySQL-PHP connection is working, install phpMyAdmin – or write a database connection script – whatever is easier for you.

Related Links

Shameless Plug: If you are a Linux user, you may want to check out my Linux Blog – LinDesk – its about Linux on the Desktop – Articles, Application Reviews and Tutorials about many aspects of Linux included configuration and scripting.


4 Responses »

  1. [...] Learn about the latest in Web Development – as soon as I do.   « Installing LAMP(Apache Web Server/PHP/MySQL) in Debian [...]

  2. [...] two articles on installing Apache, lets take a look at installing and configuring lighttpd web server on a linux [...]

  3. [...] Installing LAMP(Apache Web Server/PHP/MySQL) in Debian PHPIDS (PHP-Intrusion Detection System) No comments yet. [...]

  4. Thank you so much for this installation tutorial

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>