How to Setup LAMP Server on Rocky Linux 8
Introduction
LAMP stands for Linux, Apache, MySQL, and PHP.
It is one of the most popular stacks used to host dynamic websites and web applications.
In this guide, we will set up a LAMP server on Rocky Linux 8 step by step.
Step 1: Update System
Always update your system before installing new packages.
sudo dnf update -y
sudo reboot
Step 2: Install Apache (Web Server)
Apache is the web server that serves web pages.
sudo dnf install httpd -y
sudo systemctl start httpd
sudo systemctl enable httpd
Check status:
systemctl status httpd
Test in browser by visiting http://server-ip
. You should see the Apache test page.
Step 3: Install MySQL (Database Server)
Next, install MySQL 8.0 server.
sudo dnf install @mysql -y
sudo systemctl start mysqld
sudo systemctl enable mysqld
Secure MySQL installation:
sudo mysql_secure_installation
Step 4: Install PHP
PHP is needed to process dynamic web pages.
sudo dnf install php php-mysqlnd php-cli php-json php-opcache php-xml php-gd php-mbstring -y
Restart Apache to load PHP module:
sudo systemctl restart httpd
Step 5: Test PHP
Create a test PHP file:
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
Open browser and visit:
http://server-ip/info.php
You should see the PHP information page.
Step 6: Adjust Firewall
Allow Apache service through firewall:
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
Step 7: Test LAMP with a Sample Website
Create a simple PHP file:
echo "<?php echo 'Hello LAMP Server on Rocky Linux 8!'; ?>" | sudo tee /var/www/html/index.php
Now open http://server-ip/index.php
in your browser. You should see your message.
Conclusion
Congratulations! You have successfully set up a LAMP server on Rocky Linux 8.
This stack can now be used to host PHP applications such as WordPress, Joomla, or custom PHP websites.