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
- Log in to your server over SSH as root.
- Update your packages.
yum update -y
- Install Apache.
yum install -y httpd
- Start Apache and make it start after each reboot.
service httpd start
chkconfig httpd on
- 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.
- Visit
http://YOUR-SERVER-IP. You should see the Apache test page. - Install MySQL.
yum install -y mysql-server
service mysqld start
chkconfig mysqld on
- Make MySQL safer.
mysql_secure_installation
Follow the prompts. Set a root password and remove the test database. Keep the password safe.
- Install PHP and the MySQL connector.
yum install -y php php-mysql
- Restart Apache so it loads PHP.
service httpd restart
Test PHP
- Create a test file.
echo "<?php phpinfo(); ?>" > /var/www/html/info.php
- Open
http://YOUR-SERVER-IP/info.php. A page full of PHP details appears. - 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
yumand start it withservice. - Open port 80 and secure MySQL.
- Remove your test file afterwards.