This guide will show you the steps needed to install a LAMP stack on your Cloud Server running CentOS. All the commands shown will need to be run as root on your server via SSH.
Installing LAMP stack on CentOS
- Connect to your server as the root user via SSH.
- Before installing we need to ensure your packages and repositories are up to date by running the following command. You will be prompted to continue after it has finished checking for updates by pressing y (yes) or n (no). Hit y and then enter to continue.
- Apache uses port 80 for non-SSL traffic and 443 for SSL traffic. Both of these ports need to be open in the firewall. Run the following three commands to open them.
service firewalld start
firewall-cmd –permanent –zone=public –add-service=http
firewall-cmd –permanent –zone=public –add-service=https
- Install Apache(httpd) by running the following command. You will be prompted to continue, press y for yes and hit enter.
yum install httpd
After the install has finished you need to start the service by running the command below.
systemctl start httpd.service
- We will now install MariaDB (MySQL). MariaDB is the recommended service for MySQL currently included in the CentOS repositories.
yum install mariadb-server mariadb
Before starting some edits are recommended to /etc/my.cnf to ensure safe limits for mysql by setting the below parameters.
Once installed and configured start the service by running the command below.
systemctl start mariadb
The default install of MySQL contains settings and users for testing that are not secure. To secure the installation run the command below. You will be asked if you want to set a root password for MariaDB and should press y and hit enter to continue. You will then be prompted to set a password for MariaDB, ensure this password is set to a strong password. After setting the password you will get more yes or no prompts. Just hit enter until you have completed the prompts. You will see the message “installation should now be secure. Thanks for using MariaDB!” When complete.
- Install PHP and some common extensions for PHP by running the following command. You may be prompted to press y and enter again.
yum install php70u php70u-mcrypt php70u-mbstring php70u-mysqlnd php70u-ioncube-loader php70u-soap php70u-common php70u-tidy php70u-pecl-imagick php70u-pspell php70u-pdo php70u-bcmath php70u-cli php70u-pear php70u-enchant php70u-xml php70u-pspell php70u-pear php70u-enchant php70u-xml php70u-pspell php70u-fpm php70u-fpm-httpd.noarch
Once the install has finished restart Apache so it can use PHP and any installed modules using the command below.
systemctl restart httpd.service
Now we need to test PHP to ensure its working, You can run the following command to place a PHP info page in your document root.
echo “<?php phpinfo();” > /var/www/html/phpinfo.php
After running that command browse to https://yourservers_IP/phpinfo.php. You should receive a page showing your PHP configuration information.
- To ensure your services start automatically on reboot we need to enable them in Systemd(The software that manages services by default on CentOS). Run the following commands.
systemctl enable mariadb.service
systemctl enable httpd.service
Congratulations, you should now have a working LAMP stack! You now know how to install a LAMP stack on your Cloud Server running CentOS.
Learn more from our Cloud Server Hosting Product Guide.
If you don’t need cPanel, don't pay for it. Only pay for what you need with our scalable Cloud VPS Hosting.
CentOS, Debian, or Ubuntu No Bloatware SSH and Root Access