No matter how new you may be to hosting websites or how experienced you may be developing websites, you’ve probably heard of the LAMP stack. With the help of this article, we will be learning to install LAMP Stack on CentOS 7. Let’s get started without any further ado.
A “LAMP” stack is a group of open-source software typically installed together to enable a server to host dynamic websites and web apps.
This term is actually an acronym that represents the Linux operating system, with the Apache webserver. The site data is stored in a MySQL database (using MariaDB), and dynamic content is processed by PHP.
Together, they provide a proven set of software for delivering high-performance web applications. Each component contributes essential capabilities to the stack. Learn To Install uTorrent on your Linux Device.
The following guide demonstrates how to install LAMP on CentOS 7 and similar distros such as RHEL, Fedora, and many more.
Linux is the first component of the stack. You do not need to worry about installing your operating system or making any modifications since it is already installed. However, if you don’t have Linux you can install it easily by just simply searching the distro you want to install. If you need CentOS 7 you can download its image from its official website. For additional installation instructions, you can refer to CentOS’s helpful installation guide.
What if I say, you can install Apache, MariaDB (MySQL), and PHP in a single command line!!!! Won’t it be astonishing, but you can do so by writing the following command on your terminal:
sudo sh -c "yum install httpd mariadb104 mariadb104-server mod_php74 -y; systemctl start mariadb && mysql_secure_installation && systemctl restart mariadb && systemctl start httpd && systemctl enable httpd && systemctl enable mariadb && firewall-cmd --permanent --zone=public --add-service=http && firewall-cmd --permanent --zone=public --add-service=https && firewall-cmd --reload"
Now many prompts will appear, follow the given instructions to write exactly what is needed.
Enter current password for root (enter for none): press enter Switch to unix_socket authentication [Y/n]: 'N' Set root password? [Y/n]: 'Y' New password: "Enter a password for your database" 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'
Kudos, you have successfully installed your LAMP stack within a single command. However, if you wish to install it individually you can continue reading the current article.
Before you begin, you should have a separate, non-root user account set up on your server.
Apache is a web server software responsible for serving web content from the server to your browser. It takes the requests that it receives and sends back the HTML code for your browser to interpret.
We can easily install Apache using CentOS package manager known as yum. Execute the following sudo command on your terminal.
sudo yum install httpd
Since we are using a sudo command, you need to verify yourself by entering your password. After successful verification, your web server has been installed. Now, we need to start apache on our VPS. This can be done by inputting the following command.
sudo systemctl start httpd.service
You can crosscheck that everything went well by visiting the server’s public IP address in your web browser.
You will be more likely to see the default CentOS Apache web page something like this. Now we need to enable Apache to start on boot. To do so, execute the following command on your terminal:
sudo systemctl enable httpd.service
Also Read– The Ultimate Guide To Install Java 9 on Linux
Our web server is up and running. The next thing is we need to install a relational database system. As MariaDB is becoming more popular, we’ll use it for installation. Basically, it will organize and make access to databases where information will be stored on our website. Input the following commands on your terminal:
sudo yum install mariadb-server mariadb
After entering credentials, MariaDB is successfully installed and we can run MariaDB with the following command:
sudo systemctl start mariadb
We need to set a password for our database. We can run a script that will remove some hazardous defaults and lock down access to our database system.
It will open a prompt that will ask whether you want to set a root password or not. Enter ‘Y’ and follow the given instructions.
New password: "Enter your new password" Re-enter new password: "Re-enter password"
You have successfully created a password for your database. Now just press enter in each prompt to remain it as default. The only thing left is to enable MariaDB to start on boot. Use the following command to do so:
sudo systemctl enable mariadb.service
Now let’s move to the last component of the stack which is PHP.
We need a setup that will process code to display dynamic content on our server. For that, we will use PHP.
PHP (recursive acronym for PHP: Hypertext Preprocessor ) is an open-source general-purpose scripting language that is particularly suited to web development, as it can be embedded into HTML.
To install PHP using yum input the following command on your terminal:
sudo yum install php php-mysql
We have also installed php-mysql as we need it to interact with our database. Now restart the Apache server to implement the new changes. This can be done by executing the following command:
sudo systemctl restart httpd.service
With this, we have successfully installed the LAMP stack on our machine. If the website’s code requires additional PHP and Apache modules, they can be installed using yum.
This tutorial explored different methods to install the LAMP stack on CentOS 7 and other similar distros such as RHEL, Fedora and many more. If you encounter any issues, share them in the comments section, and I would be more than happy to assist you.