LAMP represents a group of software applications that are used together to run a dynamic website. It represents Linux, Apache, MySQL, and PHP.
Linux is an open source Operating System while Apache is a web server. MySQL/MariaDB is a relational database management system and PHP is a server-side scripting language. All these software must be installed on your Virtual Private Server (VPS) if you want to run most dynamic websites like WordPress.
In this guide, we will cover the steps needed to install a LAMP stack on your VPS server running CentOs 7.
Consult with Hostadvice's Best Linux Hosting Services page to find the top Linux hosting services.
- A VPS plan running CentOs 7
- A non-root user with sudo privileges
Step 1: Update your system
Before you install the applications, make sure your CentOs 7 server is up to date by running the command below:
$ sudo yum update
Step 2: Install Apache
We are going to use the Yum package manager to install any software applications on CentOs 7. To install Apache web server, run the command below:
$ sudo yum install httpd
When prompted to confirm the installation, press Y and Enter to proceed.
We are installing the software using sudo command so that we can temporarily get administrative privileges.
Next, we need to start Apache service by running the command below:
$ sudo systemctl start httpd.service
At this point, you can enter your public IP address on a browser to confirm the installation. You should get the default Apache page as shown below:
The page above indicates that Apache was installed successfully on your CentOs 7 server.
Next, you need to activate Apache to start during system boot using the command below:
$ sudo systemctl enable httpd.service
Step 3: Install MariaDB Database
MariaDB is a forked version of MySQL. It is an open source software application developed by a community that wants it to remain free for everyone.
We will need MariaDB to store information for our dynamic websites. We can install MariaDB together with additional packages that we require on our CentOs server by running the commands below:
$ sudo yum install mariadb-server mariadb
Confirm the installation, by pressing Y and Enter.
Now that the MariaDB installation was completed successfully, we can run the command below to start the service.
$ sudo systemctl start mariadb
Step 4: Securing MariaDB
By default, our MariaDB is not secure by default, we need to remove the anonymous user and test database and configure other settings by running the command below:
$ sudo mysql_secure_installation
You will be prompted to enter your MariaDB root password, just press Enter because you haven’t set any password yet. Please note that this should not be confused by the root password of your server.
Once you have done this, you will be asked a series of questions. We have provided the answers below for simplicity:
Set root password? [Y/n] Y New password: Enter your password here Re-enter new password: repeat your password Remove anonymous users? [Y/n] Y Disallow root login remotely? [Y/n] Y Remove test database and access to it? [Y/n] Y Reload privilege tables now? [Y/n] Y
Finally, you will get a success message as shown below:
... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB Installation should now be secure.
Your MariaDB server is now secure. Type the command below to enable it during boot:
$ sudo systemctl enable mariadb.service
Step 5: Install PHP
PHP is a general-purpose server-side scripting language. PHP works together with HTML to display dynamic content on your website. It also has the correct drivers for connecting to the MariaDB database management system that we have installed above.
We can install PHP and MySQL extension using the yum package installer by typing the command below:
$ sudo yum install php php-mysql
Confirm the installation, by pressing Y and Enter.
We need to restart Apache web server one more time for it to work with PHP by typing:
$ sudo systemctl restart httpd.service
Apache installs a default website on the directory ‘/var/www/html/’. So to test PHP on our CentOs 7 Server, we need to create a file there using a nano editor.
First, let’s install nano by running the command below:
$ sudo yum install nano
Next, create our ‘info.php’ file by typing the command below:
$ sudo nano /var/www/html/info.php
A blank text file should be displayed, just copy paste the content below on the page:
<?php phpinfo(); ?>
Then press CTRL + X, Y and Enter to save the changes
You need to visit the following URL on your browser to check whether PHP is working:
Remember to replace the ‘ip_address’ part with your CentOs 7 server’s public IP address.
If the installation was completed without a problem, you should see the below page on the browser:
Your LAMP stack is now complete and you can run any type of dynamic website/software application provided it works on the Apache, MariaDB and PHP environment. You might also need to install or enable additional PHP extensions and Apache modules depending on your web hosting needs. We hope this guide will be a great starting point for installation the most common software applications required to run your website.
Check out the top 3 VPS services: