The LAMP stack is commonly used for web servers. LAMP stands for Linux, Apache, MySQL and PHP (Python and Perl could also be included as the “P”). The following steps will show you how-to install Linux, Apache, MySQL and PHP on CentOS 7.I’ll be using a 512 MB VPS from Digital Ocean. It’s only $5 per month and CentOS 7 is pre-installed!

Install Apache

To install Apache, type and enter the following command:

sudo yum install httpd

Now let’s make sure Apache is installed:

rpm -qa | grep httpd

You should see something like this:

httpd-tools-2.4.6-19.el7.centos.x86_64
httpd-2.4.6-19.el7.centos.x86_64

Now, we can start Apache:

sudo systemctl start httpd.service

You could also use the old command to start Apache, as it’ll redirect to the above command, but try to use the one above.

sudo service httpd start

Install MySQL

To install MySQL, type and enter the following command:

sudo yum install mariadb-server mariadb

You’ll notice that we are install mariadb-server and not mysql-server as what it was in CentOS 6. This is because CentOS 7 does not include MySQL. It has been replaced with mariadb, which is a fork of MySQL.

Start MariaDB like so:

sudo systemctl start mariadb

To set the root password for MariaDB, type and enter the following command:

sudo mysqlsecureinstallation

The prompt will ask you for your current password, which should be nothing, before setting up the new password.

Next, the prompt will ask you five (5) questions. Read each question carefully and enter Y for yes or n for No for each question.

MariaDB is now installed!

We should also make sure that Apache and MySQL is started upon boot:

sudo systemctl enable httpd.service

or you could use the old command, but again it just forwards to the new command, so try to use the new command.

sudo chkconfig httpd on

and then:

sudo systemctl enable mariadb.service

or you could use the old command, but again it just forwards to the new command, so try to use the new command.

sudo chkconfig mariadb on

Install PHP

To install PHP, type and enter the following command:

sudo yum install php php-mysql

You can type the following to see if PHP is installed and what version:

php -v

We can also create a file to check PHP’s configuration settings and available predefined variables.

sudo vi /var/www/html/phpinfo.php

Note: If the path to the public folder is different, make sure you change the path to the file in the command.

In the file add:

<?php
phpinfo();
?>

Save and exit the file. You can type :wq! to do this.

Next, restart Apache:

sudo systemctl restart httpd.service

Now, to see the results, you can go to:

http://<IP Address>/phpinfo.php

Where is the IP address of the VPS. Or:

http://yourdomain.com/phpinfo.php

Where yourdomain.com is the hostname (or domain, depending on how you setup the VPS) of the VPS.

Once you are done, let’s remove the phpinfo.php file:

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

You’re done!