How to install LAMP on CentOS 6

LAMP is an acronym for Linux, Apache, MySQL, and PHP. Together these components form a complete web-server stack. Each component is responsible for a specific part of web hosting.

Step 1: Install Apache

sudo yum install httpd
sudo service httpd start
sudo chkconfig httpd on

Verify Apache is running by opening http://your-server-ip in a browser — you should see the default Apache test page.

Step 2: Install MySQL

sudo yum install mysql-server
sudo service mysqld start
sudo chkconfig mysqld on

Run the security script to set a root password and remove insecure defaults:

sudo mysql_secure_installation

Follow the prompts:

  • Set a root password.
  • Remove anonymous users: Yes.
  • Disallow remote root login: Yes.
  • Remove the test database: Yes.
  • Reload privilege tables: Yes.

Step 3: Install PHP

sudo yum install php php-mysql

Restart Apache to load the PHP module:

sudo service httpd restart

Test PHP

Create a test file:

echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php

Open http://your-server-ip/info.php in a browser. You should see the PHP information page. Remove this file after testing:

sudo rm /var/www/html/info.php

Step 4: Configure the firewall

Allow HTTP (and optionally HTTPS) traffic:

sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 443 -j ACCEPT
sudo service iptables save

Useful additional PHP modules

sudo yum install php-gd php-mbstring php-xml php-xmlrpc
sudo service httpd restart

Summary

ComponentService nameDefault port
Apachehttpd80, 443
MySQLmysqld3306
PHP(module)

Your LAMP stack is now ready for deploying web applications.

On this page