Install LAMP server in Debian, Ubuntu, and CentOS

This is a simple tutorial about installing LAMP (Linux, Apache, MySQL, and PHP) and phpMyAdmin to help Linux newbie's to setup their own Web server. This tutorial specifically written for the following GNU/Linux distributions:

  • Debian Sarge
  • Debian Etch
  • Ubuntu Gutsy
  • Ubuntu Hardy
  • CentOS 4
  • CentOS 5

Installing LAMP in Debian Sarge

To install Apache, PHP, MySQL and phpMyAdmin in Debian Sarge, please type this command.

apt-get install apache2 libapache2-mod-php4 php4 php4-gd php4-mysql php4-cli php4-mcrypt mysql-client mysql-server libmysqlclient14-dev phpmyadmin

Installing LAMP in Debian Etch and Ubuntu Gutsy and Hardy Heron

The installation instruction for installing Apache, PHP, MySQL and phpMyAdmin in Debian Etch and Ubuntu is the same as above. The difference is in Debian Sarge, its using PHP4 and MySQL4 while in Debian Etch and Ubuntu is using PHP5 and MySQL5.

apt-get install apache2 libapache2-mod-php5 php5 php5-cli php5-mysql php5-gd php5-mcrypt mysql-client mysql-server libmysqlclient15-dev phpmyadmin

Installing LAMP in CentOS4

To install Apache, PHP, and MySQL in CentOS4 with phpMyAdmin, download and add the RPMforge repo.

wget http://packages.sw.be/packages/rpmforge-release/rpmforge-release-0.3.6-1.el4.rf.i386.rpm
rpm -ivh rpmforge-release-0.3.6-1.el4.rf.i386.rpm

We need to install RPMforge repository to install libmcrypt and phpMyAdmin using yum.
Now type:

yum install httpd php php-mysql php-gd php-mbstring mysql mysql-server mysql-devel libmcrypt phpmyadmin libtool

This will install Apache2, PHP4 and MySQL4 packages. PhpMyAdmin needs the php-mcrypt package, but it is not available in the CentOS4 repository. We will download the php-mcrypt from sourceforge.net.

wget http://downloads.sourceforge.net/phprpms/php-mcrypt-4.3.9-3.2.1.i386.rpm
rpm -ivh php-mcrypt-4.3.9-3.2.1.i386.rpm

Installing LAMP in CentOS 5

Download the RPMforge repo for CentOS5 and install Apache, PHP, MySQL and phpMyAdmin.

wget - http://packages.sw.be/packages/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
rpm -ivh rpmforge-release-0.3.6-1.el5.rf.i386.rpm
yum install httpd php php-mysql php-gd php-mbstring php-mcrypt mysql mysql-server phpmyadmin

Configure the Apache and MySQL to run during startup in CentOS 4 and 5

chkconfig httpd on
chkconfig mysqld on
service http start
service mysqld start

To check whether your php installation is running and configured properly, create a file called "phpinfo.php" and put it in your /vaw/www/ directory for Debian/Ubuntu and /var/www/html for CentOS.
Edit the "phpinfo.php" and add this line:

  1. <?php phpinfo(); ?>

Then open your web browser and point to http://localhost/phpinfo.php, you should see this page in your browser.

phpinfo.php

Configure phpMyAdmin in CentOS

phpmyadmin

To fix this problem, edit the file /usr/share/phpmyadmin/config.inc.php.

vi /usr/share/phpmyadmin/config.inc.php

and put a blowfish secret

  1. $cfg['blowfish_secret'] = 'secret'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

Then refresh your browser....

phpmyadmin

Cheers!
You have now a working Linux, Apache, MySQL and PHP server.

Your rating: None Average: 5 (1 vote)

Comments

Richard's picture
Member since:
28 May 2008
Last activity:
23 hours 4 min

try this command

mysql -u root

Anonymous wrote:
great...

but when im trying to log into mysql im getting this error
any ideas????

#1045 - Access denied for user 'root'@'localhost' (using password: YES)

i did not set up a password for any user

Anonymous's picture

great...

but when im trying to log into mysql im getting this error
any ideas????

#1045 - Access denied for user 'root'@'localhost' (using password: YES)

i did not set up a password for any user

Anonymous's picture

For centos 5 , maybe you should change the command to

./httpd start
./mysqld start

Anonymous's picture

hi,

Thanks you have helped me a lot ....
:)

Thanks,
Mohit Sharma

Anonymous's picture

thanks for this great tutrial, on centos 5, only edith the file /etc/httpd/conf.d/phpmyadmin.conf, replace the lines:
Order Deny,Allow
Deny from all
Allow from 127.0.0.1

to

AllowOverride All

Alias /phpmyadmin /usr/share/phpmyadmin
Alias /phpMyAdmin /usr/share/phpmyadmin
Alias /mysqladmin /usr/share/phpmyadmin

working very fine.

Anonymous's picture

for CentOS 5 change "service http start" to "service httpd start" Also, where is phpmyadmin stored, http://localhost/phpmyadmin is not working.

Anonymous's picture

How to to get run php script with GD in apache?

Anonymous's picture

Wow, thanks for great step by step tutorial.

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You may quote other posts using [quote] tags.

More information about formatting options