HowTo: Install LAMP on CentOS/RHEL

In this guide, I will show you, how to install LAMP (Linux, Apache, MySQL, PHP) – a stack of free, open source software for building a web server for general purpose.

1. Install Apache HTTP Server

yum install httpd

Backup the apache configuration file ‘httpd.conf’.

cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.backup

Set the apache service to start at boot.

chkconfig httpd on

Open the httpd configuration file and un-comment the line, containing the text “NameVirtualHost *:80”.

vi /etc/httpd/conf/httpd.conf

Add the rules to IPTABLES.

vi /etc/sysconfig/iptables

Append the following lines before the REJECT line, to open http and https ports 80 and 443:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT

Save and close the file. Restart the firewall.

service iptables restart

Start the Apache HTTP Server daemon.

service httpd start

Visit http://localhost/ in your web browser, if you’ve installed server on your local machine, or enter the server’s IP address. You should see an Apache Test Page.

2. Install MySQL

yum install mysql-server

Set the MySQL service to start at boot.

chkconfig mysqld on

Start the MySQL service.

service mysqld start

Set the root password for MySQL.

mysqladmin -u root password NEWPASSWORD

Test connectivity to MySQL.

mysql -u root -p

3. Install PHP

yum install php php-mysql

Restart Apache.

service httpd restart

You should now have the latest PHP installed:

php -v
Was it useful? Share this post with the world!

Leave a Reply