The LAMP stack allows for many web applications and CMSs to function. WordPress, Drupal, Joomla and many other content management systems depend on the LAMP to function properly.
The LAMP stack is just short reference for Linux, Apache2, MySQL and PHP. The L stands for Linux operating system (Ubuntu, CentOS, RedHat, etc). The A stands for Apache2 which is a web server. Some users are beginning to use alternative web servers instead of Apache2 for their setup.
The M stands for MySQL which is a database server. Alternatively, you can use MariaDB server server which is a drop-in replacement for MySQL. The P stands for PHP which is a scripting computer language. When you combine all of these, you get the LAMP stack.
This brief tutorial is going to show you how to install and configure the LAMP stack on CentOS 7. This is a must if you wish to run WordPress or other content management systems on CentOS.
To get started, update your system’s packages and continue below with installing Apache2, MySQL and PHP.
One very important thing to remember is that MySQL database server is no longer supported in CentOS 7 and up. If you try to run the commands to install MySQL server packages in CentOS 7, it will not work and will send an error that the packages can’t be found.
So in order to complete the LAMP stack without MySQL, you must install MariaDB database server. MariaDB is a drop-in replacement for MySQL which means it’s 100% MySQL but with a different name.
- Installing LAMP on CentOS 7
First install a Linux operating system of your choice. This post is based on CentOS 7. Since we’re using CentOS, continue below to continue installing the other packages.
- Installing Apache2 on CentOS 7
To install Apache2 on CentOS 7, run the commands below.
sudo yum install httpd
After installing Apache2, you may run the commands below to always start Apache2 everytime your computer starts. Doing this will ensure that Apache2 is running all the time.
sudo systemctl enable httpd.service
To manually start up Apache2, run the commands below
sudo systemctl start httpd.service
- Installing MariaDB instead of MySQL
To install MariaDB on CentOS 7, run the commands below. The commands below install MariaDB server and its client.
sudo yum install mariadb-server mariadb
After installing MariaDB, run the commands below so that MariaDB automatically starts when your server comes up..
sudo systemctl enable mariadb.service
To manually start MariaDB, run the commands below.
sudo systemctl start mariadb.service
Next, run the commands below to configure MariaDB and protect it.
sudo mysql_secure_installation
Next, choose Yes for the rest of the prompts until you’re done.
- Enter current password for root (enter for none): press Enter
- Set root password? Y
- New password: Type new root password
- Re-enter new password: Confirm the password
- Remove anonymous users? Y
- Disallow root login remotely? Y
- Remove test database and access to it? Y
- Reload privilege tables now? Y
- Installing PHP On CentOS 7
Finally, run the commands below to install PHP along with other good-to-have modules.
sudo yum install php php-mysql php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel
After that, reload Apache2 for PHP to get loaded.
sudo systemctl reload httpd.service
Because everything is blocked by default on CentOS 7, you must enable HTTP/HTTPS traffic through the firewall. To enable web traffic, run the commands below.
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload
Reload Apache2 again for it to be accessible.
This is how to install the LAMP stack on CentOS 7.
You can begin testing each of the services installed. To test out Apache2, open your web browser and browse to the host via IP address or name.
Apache2 test page should come up by default.
To test PHP, create a test file named phptest.php with he content below. Save the file, then browse to it to see if PHP is working.
<?php
phpinfo();
?>
That’s it!
Frequently Asked Questions
How do I install the LAMP stack on CentOS 7?
To install the LAMP stack on CentOS 7, follow a tutorial that guides you through installing Linux, Apache2, MariaDB (or MySQL), and PHP on your CentOS 7 system.
What are some web applications that depend on the LAMP stack?
Popular web applications like WordPress, Drupal, and Joomla depend on the LAMP stack to function properly.
Is Apache2 the only web server option for the LAMP stack?
While Apache2 is commonly used, some users are beginning to explore alternative web servers for their LAMP stack setup.
What is MariaDB and how does it relate to MySQL in the LAMP stack?
MariaDB is a drop-in replacement for MySQL, offering the same functionality. In CentOS 7, MariaDB is recommended as MySQL is no longer supported.
What does the P stand for in the LAMP stack?
In the LAMP stack, the P stands for PHP, which is a popular scripting language used for web development.
Why is it important to update system packages before installing the LAMP stack on CentOS 7?
Updating system packages ensures that you have the latest software versions and security patches, which is crucial for a stable and secure LAMP stack installation.
Can I run WordPress on CentOS without installing the LAMP stack?
WordPress and many other content management systems require the LAMP stack to function properly on CentOS. Installing the LAMP stack is essential for hosting such applications.
What should I do if I encounter errors installing MySQL on CentOS 7?
If you encounter errors installing MySQL on CentOS 7, opt for installing MariaDB instead. MariaDB is fully compatible with MySQL and serves as a suitable replacement.