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 onVerify 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 onRun the security script to set a root password and remove insecure defaults:
sudo mysql_secure_installationFollow 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-mysqlRestart Apache to load the PHP module:
sudo service httpd restartTest PHP
Create a test file:
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.phpOpen 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.phpStep 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 saveUseful additional PHP modules
sudo yum install php-gd php-mbstring php-xml php-xmlrpc
sudo service httpd restartSummary
| Component | Service name | Default port |
|---|---|---|
| Apache | httpd | 80, 443 |
| MySQL | mysqld | 3306 |
| PHP | (module) | — |
Your LAMP stack is now ready for deploying web applications.