This guide will take you through how to install LAMP Stack on Rocky Linux 9. The LAMP Stack is a set of open-source tools that are used to power websites and online applications. LAMP is an acronym for Linux, Apache, MariaDB/MySQL, and PHP.
How to Install LAMP Stack on Rocky Linux 9
- Update your system.
sudo dnf update
- Run the command below to install HTTPD.
sudo dnf install httpd
Sample output
Last metadata expiration check: 0:00:21 ago on Sat 23 Jul 2022 12:09:32 PM EAT. Dependencies resolved. ===================================================================== Package Arch Version Repository Size ===================================================================== Installing: httpd x86_64 2.4.51-7.el9_0 appstream 1.4 M Installing dependencies: apr x86_64 1.7.0-11.el9 appstream 123 k apr-util x86_64 1.6.1-20.el9 appstream 94 k apr-util-bdb x86_64 1.6.1-20.el9 appstream 13 k httpd-filesystem noarch 2.4.51-7.el9_0 appstream 14 k httpd-tools x86_64 2.4.51-7.el9_0 appstream 81 k rocky-logos-httpd noarch 90.11-1.el9 appstream 24 k Installing weak dependencies: apr-util-openssl x86_64 1.6.1-20.el9 appstream 15 k mod_http2 x86_64 1.15.19-2.el9 appstream 149 k mod_lua x86_64 2.4.51-7.el9_0 appstream 61 k Transaction Summary ===================================================================== Install 10 Packages Total download size: 1.9 M Installed size: 5.9 M Is this ok [y/N]: y Downloading Packages: (1/10): mod_lua-2.4.51-7.el9_0.x86_6 63 kB/s | 61 kB 00:00 (2/10): rocky-logos-httpd-90.11-1.el 18 kB/s | 24 kB 00:01 (3/10): httpd-tools-2.4.51-7.el9_0.x 44 kB/s | 81 kB 00:01 (4/10): httpd-filesystem-2.4.51-7.el 4.4 kB/s | 14 kB 00:03 (5/10): apr-util-openssl-1.6.1-20.el 5.8 kB/s | 15 kB 00:02 (6/10): apr-util-bdb-1.6.1-20.el9.x8 17 kB/s | 13 kB 00:00 (7/10): apr-util-1.6.1-20.el9.x86_64 101 kB/s | 94 kB 00:00 (8/10): mod_http2-1.15.19-2.el9.x86_ 157 kB/s | 149 kB 00:00 (9/10): apr-1.7.0-11.el9.x86_64.rpm 130 kB/s | 123 kB 00:00 (10/10): httpd-2.4.51-7.el9_0.x86_64 210 kB/s | 1.4 MB 00:06 --------------------------------------------------------------------- Total 215 kB/s | 1.9 MB 00:09 Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : apr-1.7.0-11.el9.x86_64 1/10 Installing : apr-util-bdb-1.6.1-20.el9.x86_64 2/10 Installing : apr-util-1.6.1-20.el9.x86_64 3/10 Installing : apr-util-openssl-1.6.1-20.el9.x86_64 4/10 Installing : httpd-tools-2.4.51-7.el9_0.x86_64 5/10 Running scriptlet: httpd-filesystem-2.4.51-7.el9_0.noarch 6/10 useradd warning: apache's uid 48 outside of the SYS_UID_MIN 201 and SYS_UID_MAX 999 range. Installing : httpd-filesystem-2.4.51-7.el9_0.noarch 6/10 Installing : rocky-logos-httpd-90.11-1.el9.noarch 7/10 Installing : mod_lua-2.4.51-7.el9_0.x86_64 8/10 Installing : mod_http2-1.15.19-2.el9.x86_64 9/10 Installing : httpd-2.4.51-7.el9_0.x86_64 10/10 Running scriptlet: httpd-2.4.51-7.el9_0.x86_64 10/10 Verifying : rocky-logos-httpd-90.11-1.el9.noarch 1/10 Verifying : mod_lua-2.4.51-7.el9_0.x86_64 2/10 Verifying : httpd-tools-2.4.51-7.el9_0.x86_64 3/10 Verifying : httpd-2.4.51-7.el9_0.x86_64 4/10 Verifying : httpd-filesystem-2.4.51-7.el9_0.noarch 5/10 Verifying : apr-util-openssl-1.6.1-20.el9.x86_64 6/10 Verifying : apr-util-bdb-1.6.1-20.el9.x86_64 7/10 Verifying : apr-util-1.6.1-20.el9.x86_64 8/10 Verifying : mod_http2-1.15.19-2.el9.x86_64 9/10 Verifying : apr-1.7.0-11.el9.x86_64 10/10 Installed: apr-1.7.0-11.el9.x86_64 apr-util-1.6.1-20.el9.x86_64 apr-util-bdb-1.6.1-20.el9.x86_64 apr-util-openssl-1.6.1-20.el9.x86_64 httpd-2.4.51-7.el9_0.x86_64 httpd-filesystem-2.4.51-7.el9_0.noarch httpd-tools-2.4.51-7.el9_0.x86_64 mod_http2-1.15.19-2.el9.x86_64 mod_lua-2.4.51-7.el9_0.x86_64 rocky-logos-httpd-90.11-1.el9.noarch Complete!
- Next, enable and start the Apache server using the following command.
sudo systemctl enable httpd --now
- Check Apache status.
sudo systemctl status httpd
Sample output
● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled) Active: active (running) since Sat 2022-07-23 12:12:12 EAT; 51s ago Docs: man:httpd.service(8) Main PID: 50893 (httpd) Status: "Total requests: 0; Idle/Busy workers 100/0;Requests/sec: 0; Bytes served/sec: 0 B/sec" Tasks: 213 (limit: 23272) Memory: 26.9M CPU: 155ms CGroup: /system.slice/httpd.service ├─50893 /usr/sbin/httpd -DFOREGROUND ├─50894 /usr/sbin/httpd -DFOREGROUND ├─50899 /usr/sbin/httpd -DFOREGROUND ├─50900 /usr/sbin/httpd -DFOREGROUND └─50901 /usr/sbin/httpd -DFOREGROUND Jul 23 12:12:11 localhost.localdomain systemd[1]: Starting The Apache HTTP Server... Jul 23 12:12:12 localhost.localdomain httpd[50893]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to> Jul 23 12:12:12 localhost.localdomain systemd[1]: Started The Apache HTTP Server. Jul 23 12:12:12 localhost.localdomain httpd[50893]: Server configured, listening on: port 80
- Enter your domain name or server IP address to confirm the test page is working. e.g.
htttp://localhost
orhttp://127.0.0.1
Add Apache server to firewall
- Run the command below to add port 80 to the firewall.
sudo firewall-cmd --permanent --zone=public --add-service=http
- Then add port 433 using the following command.
sudo firewall-cmd --permanent --zone=public --add-service=https
- Next, reload your firewall to apply changes.
sudo firewall-cmd --reload
Install MariaDB on Rocky Linux
- Install MariaDB by running the command below.
sudo dnf install mariadb-server mariadb
Sample output
Last metadata expiration check: 0:12:04 ago on Sat 23 Jul 2022 12:09:32 PM EAT. Dependencies resolved. ==================================================================== Package Arch Version Repo Size ==================================================================== Installing: mariadb x86_64 3:10.5.13-2.el9 appstream 1.6 M mariadb-server x86_64 3:10.5.13-2.el9 appstream 9.3 M Installing dependencies: mariadb-common x86_64 3:10.5.13-2.el9 appstream 32 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.13-2.el9 appstream 188 k mysql-selinux noarch 1.0.4-2.el9 appstream 35 k perl-DBD-MariaDB x86_64 1.21-16.el9_0 appstream 151 k perl-File-Copy noarch 2.34-479.el9 appstream 29 k perl-Sys-Hostname x86_64 1.23-479.el9 appstream 26 k Installing weak dependencies: mariadb-backup x86_64 3:10.5.13-2.el9 appstream 6.4 M mariadb-gssapi-server x86_64 3:10.5.13-2.el9 appstream 20 k mariadb-server-utils x86_64 3:10.5.13-2.el9 appstream 211 k Transaction Summary ==================================================================== Install 13 Packages Total download size: 18 M Installed size: 107 M Is this ok [y/N]: y Downloading Packages: (1/13): mariadb-connector-c-config- 13 kB/s | 9.8 kB 00:00 (2/13): mysql-selinux-1.0.4-2.el9.n 29 kB/s | 35 kB 00:01 (3/13): perl-Sys-Hostname-1.23-479. 52 kB/s | 26 kB 00:00 (4/13): perl-File-Copy-2.34-479.el9 209 kB/s | 29 kB 00:00 (5/13): mariadb-connector-c-3.2.6-1 92 kB/s | 195 kB 00:02 (6/13): mariadb-server-utils-10.5.1 236 kB/s | 211 kB 00:00 (7/13): mariadb-gssapi-server-10.5. 29 kB/s | 20 kB 00:00 (8/13): mariadb-errmsg-10.5.13-2.el 155 kB/s | 188 kB 00:01 (9/13): mariadb-common-10.5.13-2.el 50 kB/s | 32 kB 00:00 (10/13): mariadb-10.5.13-2.el9.x86_ 149 kB/s | 1.6 MB 00:10 (11/13): perl-DBD-MariaDB-1.21-16.e 86 kB/s | 151 kB 00:01 (12/13): mariadb-server-10.5.13-2.e 269 kB/s | 9.3 MB 00:35 (13/13): mariadb-backup-10.5.13-2.e 182 kB/s | 6.4 MB 00:35 -------------------------------------------------------------------- Total 457 kB/s | 18 MB 00:40 Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : mariadb-connector-c-config-3.2.6-1.el9 1/13 Installing : mariadb-common-3:10.5.13-2.el9.x86_64 2/13 Installing : mariadb-connector-c-3.2.6-1.el9_0.x86_ 3/13 Installing : perl-Sys-Hostname-1.23-479.el9.x86_64 4/13 Installing : perl-DBD-MariaDB-1.21-16.el9_0.x86_64 5/13 Installing : mariadb-errmsg-3:10.5.13-2.el9.x86_64 6/13 Installing : perl-File-Copy-2.34-479.el9.noarch 7/13 Running scriptlet: mysql-selinux-1.0.4-2.el9.noarch 8/13 Installing : mysql-selinux-1.0.4-2.el9.noarch 8/13 Running scriptlet: mysql-selinux-1.0.4-2.el9.noarch 8/13 libsemanage.semanage_direct_install_info: Overriding mysql module at lower priority 100 with module at priority 200. Installing : mariadb-server-utils-3:10.5.13-2.el9.x 9/13 Installing : mariadb-gssapi-server-3:10.5.13-2.el9. 10/13 Installing : mariadb-backup-3:10.5.13-2.el9.x86_64 11/13 Installing : mariadb-3:10.5.13-2.el9.x86_64 12/13 Running scriptlet: mariadb-server-3:10.5.13-2.el9.x86_64 13/13 Installing : mariadb-server-3:10.5.13-2.el9.x86_64 13/13 Running scriptlet: mariadb-server-3:10.5.13-2.el9.x86_64 13/13 Running scriptlet: mysql-selinux-1.0.4-2.el9.noarch 13/13 Running scriptlet: mariadb-server-3:10.5.13-2.el9.x86_64 13/13 Verifying : mysql-selinux-1.0.4-2.el9.noarch 1/13 Verifying : mariadb-connector-c-3.2.6-1.el9_0.x86_ 2/13 Verifying : mariadb-connector-c-config-3.2.6-1.el9 3/13 Verifying : perl-Sys-Hostname-1.23-479.el9.x86_64 4/13 Verifying : perl-File-Copy-2.34-479.el9.noarch 5/13 Verifying : mariadb-server-utils-3:10.5.13-2.el9.x 6/13 Verifying : mariadb-server-3:10.5.13-2.el9.x86_64 7/13 Verifying : mariadb-gssapi-server-3:10.5.13-2.el9. 8/13 Verifying : mariadb-errmsg-3:10.5.13-2.el9.x86_64 9/13 Verifying : mariadb-common-3:10.5.13-2.el9.x86_64 10/13 Verifying : mariadb-backup-3:10.5.13-2.el9.x86_64 11/13 Verifying : mariadb-3:10.5.13-2.el9.x86_64 12/13 Verifying : perl-DBD-MariaDB-1.21-16.el9_0.x86_64 13/13 Installed: mariadb-3:10.5.13-2.el9.x86_64 mariadb-backup-3:10.5.13-2.el9.x86_64 mariadb-common-3:10.5.13-2.el9.x86_64 mariadb-connector-c-3.2.6-1.el9_0.x86_64 mariadb-connector-c-config-3.2.6-1.el9_0.noarch mariadb-errmsg-3:10.5.13-2.el9.x86_64 mariadb-gssapi-server-3:10.5.13-2.el9.x86_64 mariadb-server-3:10.5.13-2.el9.x86_64 mariadb-server-utils-3:10.5.13-2.el9.x86_64 mysql-selinux-1.0.4-2.el9.noarch perl-DBD-MariaDB-1.21-16.el9_0.x86_64 perl-File-Copy-2.34-479.el9.noarch perl-Sys-Hostname-1.23-479.el9.x86_64 Complete!
- Check the MariaDB version installed using the command below.
mariadb --version
- Start and enable MariaDB.
sudo systemctl enable mariadb --now
- Confirm MariaDB is running.
systemctl status mariadb
Sample output
● mariadb.service - MariaDB 10.5 database server Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled) Active: active (running) since Sat 2022-07-23 12:25:30 EAT; 26s ago Docs: man:mariadbd(8) https://mariadb.com/kb/en/library/systemd/ Process: 52668 ExecStartPre=/usr/libexec/mariadb-check-socket (code=exited, status=0/SUCCESS) Process: 52690 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir mariadb.service (code=exited, status=0/SUCCESS) Process: 52785 ExecStartPost=/usr/libexec/mariadb-check-upgrade (code=exited, status=0/SUCCESS) Main PID: 52771 (mariadbd) Status: "Taking your SQL requests now..." Tasks: 13 (limit: 23272) Memory: 69.5M CPU: 717ms CGroup: /system.slice/mariadb.service └─52771 /usr/libexec/mariadbd --basedir=/usr
- In case MariaDB is not running simply start it using the following command.
sudo systemctl start mariadb
- Next, secure MariaDB.
sudo mariadb-secure-installation
Sample output
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and haven't set the root password yet, you should just press enter here. Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password or using the unix_socket ensures that nobody can log into the MariaDB root user without the proper authorisation. You already have your root account protected, so you can safely answer 'n'. Switch to unix_socket authentication [Y/n] n ... skipping. You already have your root account protected, so you can safely answer 'n'. Change the root password? [Y/n] n ... skipping. By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] y ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] y ... Success! By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] y - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] y ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB!
Install PHP on Rocky Linux
- Install PHP by running the command below.
sudo dnf install php php-curl php-zip php-opcache php-mysqlnd
Sample output
Last metadata expiration check: 0:20:28 ago on Sat 23 Jul 2022 12:09:32 PM EAT. Dependencies resolved. ===================================================================== Package Arch Version Repository Size ===================================================================== Installing: php x86_64 8.0.13-1.el9 appstream 14 k php-common x86_64 8.0.13-1.el9 appstream 667 k php-mysqlnd x86_64 8.0.13-1.el9 appstream 154 k php-opcache x86_64 8.0.13-1.el9 appstream 511 k php-pecl-zip x86_64 1.19.2-6.el9 appstream 54 k Installing dependencies: libzip x86_64 1.7.3-7.el9 appstream 62 k nginx-filesystem noarch 1:1.20.1-10.el9 appstream 11 k php-pdo x86_64 8.0.13-1.el9 appstream 87 k Installing weak dependencies: php-cli x86_64 8.0.13-1.el9 appstream 3.1 M php-fpm x86_64 8.0.13-1.el9 appstream 1.6 M php-mbstring x86_64 8.0.13-1.el9 appstream 474 k php-xml x86_64 8.0.13-1.el9 appstream 136 k Transaction Summary ===================================================================== Install 12 Packages Total download size: 6.8 M Installed size: 36 M Is this ok [y/N]: y Downloading Packages: (1/12): nginx-filesystem-1.20.1-10.e 10 kB/s | 11 kB 00:01 (2/12): libzip-1.7.3-7.el9.x86_64.rp 60 kB/s | 62 kB 00:01 (3/12): php-pecl-zip-1.19.2-6.el9.x8 52 kB/s | 54 kB 00:01 (4/12): php-xml-8.0.13-1.el9.x86_64. 393 kB/s | 136 kB 00:00 (5/12): php-pdo-8.0.13-1.el9.x86_64. 116 kB/s | 87 kB 00:00 (6/12): php-mysqlnd-8.0.13-1.el9.x86 159 kB/s | 154 kB 00:00 (7/12): php-opcache-8.0.13-1.el9.x86 249 kB/s | 511 kB 00:02 (8/12): php-mbstring-8.0.13-1.el9.x8 255 kB/s | 474 kB 00:01 (9/12): php-common-8.0.13-1.el9.x86_ 95 kB/s | 667 kB 00:07 (10/12): php-8.0.13-1.el9.x86_64.rpm 22 kB/s | 14 kB 00:00 (11/12): php-fpm-8.0.13-1.el9.x86_64 170 kB/s | 1.6 MB 00:09 (12/12): php-cli-8.0.13-1.el9.x86_64 295 kB/s | 3.1 MB 00:10 --------------------------------------------------------------------- Total 449 kB/s | 6.8 MB 00:15 Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : php-common-8.0.13-1.el9.x86_64 1/12 Installing : php-pdo-8.0.13-1.el9.x86_64 2/12 Installing : php-xml-8.0.13-1.el9.x86_64 3/12 Installing : php-opcache-8.0.13-1.el9.x86_64 4/12 Installing : php-mbstring-8.0.13-1.el9.x86_64 5/12 Installing : php-cli-8.0.13-1.el9.x86_64 6/12 Installing : libzip-1.7.3-7.el9.x86_64 7/12 Running scriptlet: nginx-filesystem-1:1.20.1-10.el9.noarch 8/12 Installing : nginx-filesystem-1:1.20.1-10.el9.noarch 8/12 Installing : php-fpm-8.0.13-1.el9.x86_64 9/12 Running scriptlet: php-fpm-8.0.13-1.el9.x86_64 9/12 Installing : php-8.0.13-1.el9.x86_64 10/12 Installing : php-pecl-zip-1.19.2-6.el9.x86_64 11/12 Installing : php-mysqlnd-8.0.13-1.el9.x86_64 12/12 Running scriptlet: php-mysqlnd-8.0.13-1.el9.x86_64 12/12 Verifying : nginx-filesystem-1:1.20.1-10.el9.noarch 1/12 Verifying : libzip-1.7.3-7.el9.x86_64 2/12 Verifying : php-pecl-zip-1.19.2-6.el9.x86_64 3/12 Verifying : php-xml-8.0.13-1.el9.x86_64 4/12 Verifying : php-pdo-8.0.13-1.el9.x86_64 5/12 Verifying : php-opcache-8.0.13-1.el9.x86_64 6/12 Verifying : php-mysqlnd-8.0.13-1.el9.x86_64 7/12 Verifying : php-mbstring-8.0.13-1.el9.x86_64 8/12 Verifying : php-fpm-8.0.13-1.el9.x86_64 9/12 Verifying : php-common-8.0.13-1.el9.x86_64 10/12 Verifying : php-cli-8.0.13-1.el9.x86_64 11/12 Verifying : php-8.0.13-1.el9.x86_64 12/12 Installed: libzip-1.7.3-7.el9.x86_64 nginx-filesystem-1:1.20.1-10.el9.noarch php-8.0.13-1.el9.x86_64 php-cli-8.0.13-1.el9.x86_64 php-common-8.0.13-1.el9.x86_64 php-fpm-8.0.13-1.el9.x86_64 php-mbstring-8.0.13-1.el9.x86_64 php-mysqlnd-8.0.13-1.el9.x86_64 php-opcache-8.0.13-1.el9.x86_64 php-pdo-8.0.13-1.el9.x86_64 php-pecl-zip-1.19.2-6.el9.x86_64 php-xml-8.0.13-1.el9.x86_64 Complete!
- Restart the Apache server.
sudo systemctl restart httpd
- Then create a PHP test page to confirm it’s working with the Apache server.
sudo nano /var/www/html/info.php
Paste the code below then save(ctrl+s) and close(ctrx+x) the file.
- View the test page on your browser by entering your server IP or domain name followed by info.php e.g.
localhost/info.php
or127.0.0.1/info.php
- You have made it to the end of our article. We have gone through how to install LAMP Stack on Rocky Linux 9.
Read more on Apache Documentation
Read more on MariaDB Documentation
Read more on PHP Documentation