Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

How to install LAMP on CentOS 6

This guide shows you how to install Apache, MySQL and PHP on CentOS 6. It needs root access, so it fits VPS and dedicated servers.

How-To Guides1 min read13 steps
Tip: CentOS 6 is very old and no longer gets updates. Newer versions use similar steps, but with dnf or systemctl in place of yum and service.

What is LAMP?

LAMP is a bundle of four tools that run most websites.

  • L is Linux, the operating system.
  • A is Apache, the web server that sends pages to visitors.
  • M is MySQL, a database that stores your data.
  • P is PHP, a language that builds dynamic pages.

Steps

  1. Log in to your server over SSH as root.
  2. Update your packages.
yum update -y
  1. Install Apache.
yum install -y httpd
  1. Start Apache and make it start after each reboot.
service httpd start
chkconfig httpd on
  1. Open port 80 in the firewall so visitors can reach the site.
iptables -I INPUT -p tcp --dport 80 -j ACCEPT
service iptables save

This adds a rule to allow web traffic and saves it.

  1. Visit http://YOUR-SERVER-IP. You should see the Apache test page.
  2. Install MySQL.
yum install -y mysql-server
service mysqld start
chkconfig mysqld on
  1. Make MySQL safer.
mysql_secure_installation

Follow the prompts. Set a root password and remove the test database. Keep the password safe.

  1. Install PHP and the MySQL connector.
yum install -y php php-mysql
  1. Restart Apache so it loads PHP.
service httpd restart

Test PHP

  1. Create a test file.
echo "<?php phpinfo(); ?>" > /var/www/html/info.php
  1. Open http://YOUR-SERVER-IP/info.php. A page full of PHP details appears.
  2. Delete the file when done.
rm /var/www/html/info.php

This matters because the page shows private server details.

Quick recap

  • LAMP means Linux, Apache, MySQL and PHP.
  • Install each with yum and start it with service.
  • Open port 80 and secure MySQL.
  • Remove your test file afterwards.