In this guide, we will learn how to install LAMP Stack on Rocky Linux 9|AlmaLinux 9. LAMP is an open-source software component that is put together to create effective websites and online applications.
What is LAMP Stack Used for?
LAMP Stack is used to create and distribute web-based applications. Because of its versatility and effectiveness, smaller developers may compete with commercial software development solutions.
LAMP Stack comprises the four elements required to create a fully functional environment for web development.
The acronym LAMP is made up of the initial letters of the component names:
- Linux – is the operating system that runs the rest of the components.
- Apache – HTTP Server is a web server software used to serve static web pages.
- MySQL – is a relational database management system that is used not just for establishing and administering web databases, but also for data warehousing, application logging, e-commerce, and other purposes.
- PHP/Perl, and Python – are programming languages used to construct web applications.
Each part symbolizes a crucial tier of the stack. The elements work together to build dynamic, database-driven web pages.
Install LAMP Stack on Rocky Linux 9|AlmaLinux 9
The following steps will guide you on how to install the LAMP Stack on Rocky Linux 9| AlmaLinux 9 successfully.
Step 1. Update the system
Execute the command below to update the system to the latest version:
sudo dnf update
Step 2. Install the Apache web server
Use the following command to finish the installation.
sudo yum install httpd httpd-tools
Sample results:
Last metadata expiration check: 0:05:26 ago on Tue 18 Oct 2022 05:45:07 PM EAT.
Package httpd-2.4.51-7.el9_0.x86_64 is already installed.
Package httpd-tools-2.4.51-7.el9_0.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
Once the installation is complete, use the following commands to start the web server, enable Apache (so that it boots up automatically), and check its status.
sudo systemctl enable httpd
sudo systemctl start httpd
Output;
$ systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2023-04-10 01:58:55 EAT; 32s ago
Docs: man:httpd.service(8)
Main PID: 11391 (httpd)
Status: "Total requests: 0; Idle/Busy workers 100/0;Requests/sec: 0; Bytes served/sec: 0 B/sec"
Tasks: 213 (limit: 23448)
Memory: 23.0M
CPU: 150ms
CGroup: /system.slice/httpd.service
├─11391 /usr/sbin/httpd -DFOREGROUND
├─11399 /usr/sbin/httpd -DFOREGROUND
├─11400 /usr/sbin/httpd -DFOREGROUND
├─11401 /usr/sbin/httpd -DFOREGROUND
└─11402 /usr/sbin/httpd -DFOREGROUND
Apr 10 01:00:15 localhost.localdomain systemd[1]: Starting The Apache HTTP Server... Apr 10 01:00:15 localhost.localdomain httpd[3593]: AH00558: httpd: Could not reliably determine the server's fully qual>
You must modify your firewall rules to permit HTTP and HTTPS queries on your web server using the following commands before making your pages publicly accessible.
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload
By going to your server’s IP address, you can confirm that the web server is operational and reachable through http://server-IP>.
Step 3. Install PHP on Rocky Linux 9|AlmaLinux 9
Install the EPEL repository on Rocky Linux 9 | AlmaLinux 9
sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm -y
To set up the yum utilities, run the command below.
sudo yum install yum-utils -y
Use the command below to install PHP as well as a few commonly used PHP extensions on your Rocky Linux 9| AlmaLinux 9.
sudo yum install php php-zip php-intl php-mysqlnd php-dom php-simplexml php-xml php-xmlreader php-curl php-exif php-ftp php-gd php-iconv php-json php-mbstring php-posix php-sockets php-tokenizer -y
After installation has been completed, check the PHP Version.
$ php -v
PHP 8.0.27 (cli) (built: Jan 3 2023 16:17:26) ( NTS gcc x86_64 ) Copyright (c) The PHP Group Zend Engine v4.0.27, Copyright (c) Zend Technologies with Zend OPcache v8.0.27, Copyright (c), by Zend Technologies
Test PHP on Rocky Linux 9|AlmaLinux 9
In addition to checking the version mentioned below, you can test PHP to ensure that it is operating as needed.
##switch to root user
$ su -
##paste the following command
cat > /var/www/html/test.php << EOL
<?php
phpinfo();
?>
EOL
Restart the Apache web server;
sudo systemctl restart httpd
Go to the browser and type http://server-IP>/test.php into the address bar. You will the page as shown in the screenshot below;
Remember to remove the PHP test page;
sudo rm -rf /var/www/html/test.php
Step 3. Install MariaDB Server on Rocky Linux 9|AlmaLinux 9
MariaDB is a well-known database server. The installation is straightforward, with only a few steps as shown.
sudo yum install mariadb-server mariadb
Dependency Tree:
Last metadata expiration check: 2:42:16 ago on Tue 18 Oct 2022 05:45:07 PM EAT.
Dependencies resolved.
=======================================================================================================================
Package Architecture Version Repository Size
=======================================================================================================================
Installing:
mariadb x86_64 3:10.5.16-2.el9_0 appstream 1.6 M
mariadb-server x86_64 3:10.5.16-2.el9_0 appstream 9.4 M
Installing dependencies:
mariadb-common x86_64 3:10.5.16-2.el9_0 appstream 31 k
mariadb-connector-c x86_64 3.2.6-1.el9_0 appstream 195 k
mariadb-connector-c-config noarch 3.2.6-1.el9_0 appstream 9.8 k
mariadb-errmsg x86_64 3:10.5.16-2.el9_0 appstream 215 k
mysql-selinux noarch 1.0.5-1.el9_0 appstream 35 k
perl-DBD-MariaDB x86_64 1.21-16.el9_0 appstream 151 k
Installing weak dependencies:
mariadb-backup x86_64 3:10.5.16-2.el9_0 appstream 6.4 M
mariadb-gssapi-server x86_64 3:10.5.16-2.el9_0 appstream 19 k
mariadb-server-utils x86_64 3:10.5.16-2.el9_0 appstream 213 k
Transaction Summary
=======================================================================================================================
Install 11 Packages
Total download size: 18 M
Installed size: 108 M
Is this ok [y/N]: y
Once the installation is complete, use the following commands to start MariaDB, enable it to start automatically when the system boots, and check its status.
sudo systemctl enable mariadb
sudo systemctl start mariadb
Output;
$ systemctl status mariadb
● mariadb.service - MariaDB 10.5 database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2023-04-10 01:25:44 EAT; 5s ago
Docs: man:mariadbd(8)
https://mariadb.com/kb/en/library/systemd/
Process: 18811 ExecStartPre=/usr/libexec/mariadb-check-socket (code=exited, status=0/SUCCESS)
Process: 18839 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir mariadb.service (code=exited, status=0/SUCCESS)
Process: 18953 ExecStartPost=/usr/libexec/mariadb-check-upgrade (code=exited, status=0/SUCCESS)
Main PID: 18938 (mariadbd)
Status: "Taking your SQL requests now..."
Tasks: 14 (limit: 23448)
Memory: 73.5M
CPU: 769ms
CGroup: /system.slice/mariadb.service
└─18938 /usr/libexec/mariadbd --basedir=/usr
Finally, you should secure your MariaDB installation by running the command below.
sudo mysql_secure_installation
Sample results:
Enter current password for root (enter for none): <PRESS ENTER>
OK, successfully used password, moving on...
....
Switch to unix_socket authentication [Y/n] y
....
Change the root password? [Y/n] y
New password: <ENTER NEW PASSWORD>
Re-enter new password: <RE-ENTER NEW PASSWORD>
Password updated successfully!
Reloading privilege tables..
... Success!
...
Remove anonymous users? [Y/n] y
... Success!
....
Disallow root login remotely? [Y/n] y
... Success!
....
Remove test database and access to it? [Y/n] y
....
Reload privilege tables now? [Y/n] y
...
Thanks for using MariaDB!
Using the following command, you can log in to MySQL after it has been secured and look over the current databases on your database server.
mysql -e "SHOW DATABASES;" -p
Sample results:
Enter password: <ENTER PASSWORD>
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
Your LAMP stack is now ready for use in web development projects.
Conclusion
After following the instructions above, you have successfully installed LAMP Stack on Rocky Linux 9|AlmaLinux 9. Hope this guide was helpful.
Read more about Apache, MariaDB, and PHP.
You may need these other resources: