Quick 'n' Easy LAMP Server For CentOS/RHEL

Want to support HowtoForge? Become a subscriber!
 
Submitted by olddocks (Contact Author) (Forums) on Wed, 2008-05-28 19:16. :: CentOS | Apache | MySQL | PHP

Quick 'n' Easy LAMP Server For CentOS/RHEL

This tutorial shows a quick way of installing a LAMP server (Linux + Apache + MySQL + PHP/Perl together commonly known as LAMP Server.) on CentOS and RHEL server systems. 

  • Apache Web Server 2.0
  • MySQL Database Server 5.0
  • PHP Scripting Language 5.0
  • phpMyAdmin - Web based MySQL Administration Tool
  • Webmin - A free web based hosting control panel

 

Goal

To set up a LAMP server on a fresh VPS/Dedicated server running CentOS 5.0 with atleast 256mb of RAM. We will also be installing Webmin, a free server control panel for linux. If you are using a Debian/Ubuntu refer to this article.

 

Install Apache

Apache is the most popular Web HTTP server for a Linux servers.

yum install httpd httpd-devel

We might need the httpd-devel libraries to compile and install other modules from the sources, just to be on the safer side. /etc/httpd/conf/httpd.conf - Apache configuration file location.

/etc/init.d/httpd start

 

Install MySQL Database Server

MySQL is a widely used open source database server on most Linux servers and can very well integrate to PHP and Apache server on CentOS/RHEL.

yum install mysql mysql-server mysql-devel

If you attempt to type mysql in command prompt, you will be getting this nasty error.

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’

This is because you are not running the mysqld daemon before launching the mysql client. The file /var/lib/mysql/mysql.sock will be automatically created upon running the first instance of mysql.

To fix:

First start the mysql daemon, then type mysql:

/etc/init.d/mysqld start
mysql

 

Changing MySQL Root Password

By default the root password is empty for the mysql database. It is a good idea to change the mysql root password to a new one from a security point of view.

mysql> USE mysql;
mysql> UPDATE user SET Password=PASSWORD('newpassword') WHERE user='root';
mysql> FLUSH PRIVILEGES;

Once done, check by logging in:

mysql -u root -p
Enter Password: <your new password>

 

To Create A New MySQL User

To create a new mysql user 'guest' with 'all privileges' on the database 'demo':

mysql > create database demo
mysql >GRANT ALL PRIVILEGES ON demo.* TO 'guest'@'localhost' IDENTIFIED BY 'guest' WITH GRANT OPTION;
mysql> UPDATE user SET Password=PASSWORD('guest') WHERE user='guest';

That's it! MySQL is ready! Don't forget to remember the root password as we might be using it with phpmyadmin.

 

Install PHP5 Scripting Language

Installing PHP5 with the necessary modules is so easy and can be configured for both the Apache and mysql environment.

yum install php php-mysql php-common php-gd php-mbstring php-mcrypt php-devel php-xml

Don't forget to install php-gd (gd library). It is very important if we plan to run captcha scripts on our server and so as other which are dependent on mysql and other functions.

Restart Apache to load php.

/etc/init.d/httpd restart

 

To Test If PHP Is Working Or Not:

Create a file named /var/www/html/test.php with the following phpinfo() function inside php quotes.

// test.php
  <?php
  phpinfo();
  ?>

Then point your browser to http://ip.address/test.php.

That's it! You should see a php configuration file displaying all kind of paths and installed modules.

Closely observe the installed configuration on your server.

* PHP Paths (php.ini path)
* Apache paths and Loaded Modules (mod_security, mod_evasive if installed_
* PHP GD Library
* MySQL paths and other information

 

Install phpMyAdmin

phpMyAdmin is a free web based MySQL database Administration Tool. Without phpMyAdmin it is almost impossible to mysql db operations in the command line. phpMyAdmin has become so convenient and it is absolutely sought by most webmasters to be present along with the mysql server.

yum install phpmyadmin

Point your browser to: http://ip.address/phpmyadmin.

 

Common Errors

You might encounter the following errors while configuring phpmyadmin.

Forbidden
You don't have permission to access /phpmyadmin/ on this server.

To fix:

Edit the /etc/httpd/conf.d/phpmyadmin.conf and uncomment the line deny from all.

nano /etc/httpd/conf.d/phpmyadmin.conf

<Directory "/usr/share/phpmyadmin">
  Order Deny,Allow
  # Deny from all
  Allow from 127.0.0.1
  </Directory>

 

Error
The configuration file now needs a secret passphrase (blowfish_secret)

To fix:

nano /usr/share/phpmyadmin/conf.inc.php

Look for a line and enter any password. Just dont leave it empty!

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

It worked for me using the above methods!
Log into the phpmyadmin with the mysql root password we changed while installing the mysql database.

 

Install Webmin

Webmin a free server hosting control panel  for Linux. It is a web based hosting administration tool and can be handy to tweak settings in your server if you are a beginner to Linux! You can download webmin here. Since webmin cannot be installed using yum, we can download an RPM package and install it on our server.

wget <webmin rpm path>
rpm - i webmin-1.410-1.noarch.rpm

That should be a pretty easy installation! Remember webmin uses port 10000 and should not be blocked by your firewall.

Point your browser to: http://ip.address:10000

You should see a webmin login. But we don't know the login and password yet! To set up the webmin password run the script below...

/usr/libexec/webmin/changepass.pl /etc/webmin admin <newpasswd>

Log in with the admin username and new webmin password!
To uninstall webmin, just run:

/etc/webmin/uninstall.sh

 

Final Steps

We want the Apache and mysql to be loaded at every boot so we switch them on using chkconfig:

chkconfig httpd on
chkconfig mysqld on

You can also place comments in my blog. I would appreciate any feedbacks as well!

This tutorial was written and contributed to HowToForge by Mr.Balakrishnan  who currently runs MySQL-Apache-PHP.com. Permission is fully granted to copy/republish this tutorial in any form, provided a source is mentioned with a live link back to the authors site.


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 Anonymous (not registered) on Thu, 2012-09-27 10:23.

If you can't find this with yum, consider adding epel to your repolist.

 # find and download the latest rpm from: http://fedoraproject.org/wiki/EPEL

su -

wget http://mirrors.ukfast.co.uk/sites/dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-7.noarch.rpm

# install it..

rpm -ivh epel-release-6-7.noarch.rpm

# and check it is there..

yum repolist


Submitted by Anonymous (not registered) on Mon, 2012-07-16 22:10.
This helped me out a lot. Thank you!
Submitted by Michael Reed (not registered) on Sat, 2012-01-28 17:56.
Very concise and easy.  I wish I had this the first time I created a LAMP server!
Submitted by Anonymous (not registered) on Tue, 2011-11-08 13:14.

Hi,

 PhpMyAdmin no longer ships with RHEL6.  Sadly RedHatNetwork does not have it in their repo.  ( Wonders why we pay for this...)

# yum install phpmyadmin
Loaded plugins: product-id, rhnplugin, subscription-manager
Updating Red Hat repositories.
Setting up Install Process
No package phpmyadmin available.
Error: Nothing to do
# yum repolist
Loaded plugins: product-id, rhnplugin, subscription-manager
Updating Red Hat repositories.
repo id                                                repo name                                                                                   status
rhel-x86_64-server-6                                   Red Hat Enterprise Linux Server (v. 6 for 64-bit x86_64)                                    5,557
repolist: 5,557
 

Submitted by geo (not registered) on Wed, 2011-06-08 07:17.

I have used this several times a do appreciate it.  It makes things so simple.  I found one problem this time that I think is likely due to a change in PHPMyAdmin.  In the blowfish secret you suggest editing the password in /usr/share/phpmyadmin/conf.inc.php.  It appears that there is a slight change in the file name.  It seems to now be /usr/share/phpmyadmin/config.inc.php.  Looks like conf.inc.php has changed to config.inc.php.   Everything else worked like a charm.

 I have set a LAMP server up from time to time when trying to expeirement with different things.  And I think this is my 3rd or 4th time using this step by step.  Each time it has worked great.  This is the first time I have ran into even the slightest glitch - and that is a pretty minor one. 

 

Thanks for a great step-by-step. 

Geo

Submitted by Allan Anderson (not registered) on Mon, 2011-04-18 22:59.

I am once again using your blog on installing lamp on Centos5 which works great and I really appreciate you putting it up for us newbies.  Unfortunately Your install for Webmin and Phpmyadmin do not work for Centos5 on your blog.

I then have to go to Matts  Blog to install Webmin and

Then I go to Khattam's Blog   To install PHPmyadmin.

I have told many newbies to see your Lamp  install and If you would have time I would love to see it updated.

Im not Complaining about anything but it would be good to send a newbie to your blog and not have them come back and say they can not get it all to work.

Just a FYI

Allan

Submitted by Dan (not registered) on Fri, 2011-08-05 13:46.

I am using CentOS 5 in one of my Virtual Servers and I wanted it to have phpMyAdmin. I tried installing it by doing yum install phpmyadmin but it said No package phpmyadmin available. So I add to add a repo. I discovered that rpmforge repo had this package. To add it, I executed the following commands:

wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.1-1.el5.rf.i386.rpm
rpm -Uhv rpmforge-release-0.5.1-1.el5.rf.i386.rpm

If you have 64-bit version installed, you should try this one out:

wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.1-1.el5.rf.x86_64.rpm
rpm -Uhv rpmforge-release-0.5.1-1.el5.rf.x86_64.rpm

If you get a 404 Not Found, then you will need to figure out the latest updated version of repo url from rpmforge usage page.

After that, you may like to update your packages by doing this:

yum update

and then continue installing phpmyadmin

yum install phpmyadmin

It should ask you for confirmation and you can continue installing phpMyAdmin with dependencies.

Submitted by Anonymous (not registered) on Mon, 2011-02-21 19:08.
Still quite useful!  Thanks!
Submitted by Gautam (not registered) on Fri, 2010-10-01 15:53.
Brilliant tutorial !!!
Submitted by joelski (not registered) on Fri, 2010-08-20 00:35.

php needs update from 5.1 to 5.2 for latest phpmyadmin, this link is very helpful

http://wiki.centos.org/HowTos/PHP_5.1_To_5.2

Submitted by Ahmed Alzayani (not registered) on Sun, 2010-07-18 10:13.

I wnated newer ver of php,mysql with latest phpmyadmin 3.3.4, turn out you need to use remi repro

 this work for me:

 == httpd server ==
yum install httpd httpd-devel
/etc/init.d/httpd start

==Add Remi Repo==
wget http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm
wget http://rpms.famillecollet.com/el5.i386/remi-release-5-7.el5.remi.noarch.rpm
rpm -Uvh remi-release-5-7.el5.remi.noarch.rpm epel-release-5.3.noarch.rpm

==install mysql===
yum --enablerepo remi install mysql mysql-server mysql-devel
/etc/init.d/mysqld start


==config mysql==
mysql

mysql> USE mysql;
mysql> UPDATE user SET Password=PASSWORD('newpassword') WHERE user='root';
mysql> FLUSH PRIVILEGES;

mysql -u root -p
Enter Password: <your new password>

==Install PHP==
yum --enablerepo
remi install php php-mysql php-common php-gd php-mbstring php-mcrypt php-devel php-xml

/etc/init.d/httpd restart

==Install PHPmyadmin (http://www.phpmyadmin.net/documentation/)==
cd /var/www/html/
wget http://downloads.sourceforge.net/project/phpmyadmin/phpMyAdmin/3.3.4/phpMyAdmin-3.3.4-all-languages.tar.gz?use_mirror=internode&ts=1279443739
tar -xzvf phpMyAdmin-3.3.4-english
mv phpMyAdmin-3.3.4-english phpmyadmin

configtr as per http://www.phpmyadmin.net/documentation/

==Last==
chkconfig httpd on
chkconfig mysqld on

Submitted by Anonymous (not registered) on Sat, 2010-06-19 03:34.

I follow this instruction step by step.. It goes fine except for

yum install phpmyadmin

did not work in VPS.  I received error that says no package available.

Is there something that I miss?

Submitted by DonO (not registered) on Tue, 2010-07-13 16:20.

I am getting the same message regarding "no package available".

 I'm using REL 5.0.

I tried...

yum install phpmyadmin --enablerepo=development

 Which I read in another post, but it also did not work. I also ran

# yum list php*

 To see if it would list phpmyadmin as an option, but it did not.

After some searching, I found this, which worked for me:

# rpm -Uv http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-3.noarch.rpm

(replace the x86_64 with i386 if it's a 32bit system)

# yum install phpMyAdmin

Submitted by DonO (not registered) on Tue, 2010-07-13 16:14.

I am getting the same message regarding "no package available".

 I'm using REL 5.0.

I tried...

yum install phpmyadmin --enablerepo=development

 Which I read in another post, but it also did not work. I also ran

# yum list php*

 To see if it would list phpmyadmin as an option, but it did not.

Submitted by Michael (not registered) on Sun, 2010-05-30 19:50.
Great tut, there was the first one to get me started ;-)
Submitted by Anonymous (not registered) on Tue, 2010-05-25 14:54.

I could not connect to the apache server remotely to test if php was working. I finally found the problem.

I added this line:

-A RH-Firewall-1-INPUT -m tcp -p tcp --dport 80 -j ACCEPT

 to /etc/sysconfig/iptables ABOVE the REJECT and COMMIT lines:

-A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited
COMMIT

This and a 'service iptables restart' fixed my problem.

Submitted by puneetsmail (not registered) on Fri, 2012-06-01 09:37.
After editing iptables PHPinfo test works.
But executing service iptables restart ends up with failure.

iptables: Flushing firewall rules:                         [  OK  ]
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Unloading modules:                               [  OK  ]
iptables: Applying firewall rules: iptables-restore: line 7 failed
                                                           [FAILED]
 
 
Submitted by Nasim (not registered) on Mon, 2009-12-14 08:47.

Hi, I tried to install phpmyadmin on my vps following the command you have shown (yum install phpmyadmin), its running on centos. I have also tried with other commands enableing repo. But still no luck. Getting following error:

 

 k
    self.doSetup()
  File "/usr/lib/python2.4/site-packages/yum/repos.py", line 71, in doSetup
    self.ayum.plugins.run('postreposetup')
  File "/usr/lib/python2.4/site-packages/yum/plugins.py", line 176, in run
    func(conduitcls(self, self.base, conf, **kwargs))
  File "/usr/lib/yum-plugins/fastestmirror.py", line 181, in postreposetup_hook
    all_urls = FastestMirror(all_urls).get_mirrorlist()
  File "/usr/lib/yum-plugins/fastestmirror.py", line 333, in get_mirrorlist
    self._poll_mirrors()
  File "/usr/lib/yum-plugins/fastestmirror.py", line 376, in _poll_mirrors
    pollThread.start()
  File "/usr/lib/python2.4/threading.py", line 416, in start
    _start_new_thread(self.__bootstrap, ())
thread.error: can't start new thread

 

Submitted by andres (not registered) on Mon, 2009-10-26 19:03.

Hi i have a question,

 I have created the test.php file into the html folder but whenever I open the browser it doesn´t show anything the page is in blank....I don´t know if the file is wrong or is there another problem?

 

I created a new document in the html folder by making right click and selecting Create Document then I chose Empty File and then I change the name as "test.php"  and it appears an icon with a symbol of a screwdriver with the .php extension. I open the file and edit it by inserting

<?php phpinfo(); ?> and save it....but when I open the browser with http://localhost/test.php or http://ip of the machine/test.php it just shows the browser in blank.....

 any suggestions?

 Thanks for your help

Submitted by hayson (not registered) on Wed, 2011-08-10 09:57.
I had same problem, solved with bash command line: # nano /test.php and used gui to move it to the html folder
Submitted by znif (not registered) on Tue, 2009-12-08 01:34.
The system wont open file named "info.*". Just rename it and anything works fine.
Submitted by Anonymous (not registered) on Sun, 2009-05-17 11:14.
Excelent, works fine to me. Thanks a lots !
Submitted by Anonymous (not registered) on Sun, 2008-11-09 07:19.

Finally some success! I've been trying to get a funambol server up and running with lamp on the same machine. This tutorial got me through! Just found a minor typo that I'll point out:

nano /usr/share/phpmyadmin/conf.inc.php should be:

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

Great tutorial! Thanks alot. 

Submitted by Anonymous (not registered) on Sat, 2008-11-01 11:35.
After installing phpmyadmin I received a 404 until restarting apache (httpd). I assume this is because the phpmyadmin file in httpd/conf.d (which contains the alias to the phpmyadmin folder in usr/share/phpmyadmin) is not loaded until apache is restarted? Is this (correct, and if so) also the case for any file in this folder?
Submitted by ccdan (not registered) on Wed, 2012-01-18 14:38.

i have some questions below:

Error: Package: phpmyadmin-2.11.11.3-2.el5.rf.noarch (rpmforge) Requires: php-mcrypt You could try using --skip-broken to work around the problem

 what can i do ?thanks!

Submitted by LAMP newbie. (not registered) on Fri, 2010-10-01 02:05.
Sincere thanks for the walk through.  Everything has worked exactly as described and I now have a functioning LAMP server after many previous failed attempts!  Very happy newbie.