How to Install Apache, MySQL, PHP (LAMP Stack) on Rocky Linux 9?
The LAMP stack: Linux, Apache, MySQL, and PHP-is one of the widely used open-source platforms for hosting dynamic websites and applications. Rocky Linux is popular for its stability and security and serves as a perfect base for this stack. You can create a powerful environment for all your development needs with the capabilities of Apache to serve web content, MySQL’s database management, and the PHP’s scripting flexibility.
Prerequisites Before Installing Apache, MySQL, PHP on Rocky Linux 9
Before carrying out the installation process, you must ensure that!
- Get an updated system.
sudo dnf update -y
- It should have a rocky Linux 9 server with sudo privileges.
- Provide access to the terminal or SSH.
Steps to Install Apache on Rocky Linux 9
Here, we have mentioned the steps to install Apache on Rocky Linux 9!
Step 1: Apache Installation
sudo dnf install httpd -y
Step 2: Enable & Start Apache
sudo systemctl enable httpd sudo systemctl start httpd
Step 3: Apache Status Verification
sudo systemctl status httpd
As a result, now you can see that Apache is active and running.
Steps to Install MySQL on Rocky Linux 9
Let’s explore some of the ways to install MySQL on Linux 9!
Step 1: Apache Installation
sudo dnf install mysql-server -y
Step 2: Enable & Start Apache
sudo systemctl enable mysqld sudo systemctl start mysqld
Step 3: MySQL Installation
sudo mysql_secure_installation
Follow the above mentioned steps to set a root password and secure your MySQL installation.
Steps to Install PHP
Step 1: PHP Installation & necessary modules.
sudo dnf install php php-mysqlnd php-fpm -y
Step 2: Restart Apache to load PHP modules
sudo systemctl restart httpd
Test the LAMP Stack
Step 1: PHP File Info Creation
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
Step 2: Access the PHP Info Page.
Navigate to http://your_server_ip/info.php in your web browser. You will see the PHP information page, confirming that PHP has been installed correctly.
Conclusion
With the help of the above mentioned steps, you have successfully installed the LAMP stack on Rocky Linux 9. The whole stack provides a solid foundation for the hosting and development of dynamic web applications that leverage the strengths of each stack component.
Frequently Asked Questions
Is Rocky Linux 9 a good choice for hosting the LAMP stack?
Rocky Linux 9 tends to be a well-suited choice for deploying a LAMP stack owing to its enterprise-grade stability and top security for hosting.
How are we to manage the MySQL databases?
You have the option of either performing such database management with the mysql command-line tool or installing a web version like phpMyAdmin.
Is securing the MySQL installation of any necessity?
Yes, the running of the command mysql_secure_installation will help secure your database by setting a root password while also removing these defaults that may be considered dangerous.
How can I install extra PHP modules?
You should install the PHP modules with sudo dnf install php-module_name. For example, to install XML modules, use sudo dnf install php-xml.
Instead of MySQL, can I use MariaDB?
Yes, MariaDB is a drop-in replacement for MySQL and can be employed as part of the LAMP stack on Rocky Linux 9.