How to Install LAMP Stack on Rocky Linux 9
A LAMP stack is a group of open-source software that is typically installed together to enable a server to host dynamic websites and web apps. This term is actually an acronym that represents the Linux operating system, with the Apache web server. The site data is stored in a MySQL database, and dynamic content is processed by PHP.
Pre-requisites :
-
A system with Rocky Linux 9 installed and running.
root
access to the system.
Install Apache Web Server
First, we will start by installing the Apache web server. To complete the installation, use the following command.
dnf install httpd httpd-tools
Output:
[root@server ~]# dnf install httpd httpd-tools
Last metadata expiration check: 0:59:50 ago on Fri 15 Jul 2022 09:35:02 PM CEST.
Dependencies resolved.
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
httpd x86_64 2.4.51-7.el9_0 appstream 1.4 M
httpd-tools x86_64 2.4.51-7.el9_0 appstream 81 k
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
mailcap noarch 2.1.49-5.el9 baseos 32 k
rocky-logos-httpd noarch 90.11-1.el9 appstream 24 k
Once the installation is complete, enable Apache (to start automatically upon system boot), start the web server and verify the status using the commands below.
systemctl enable httpd
systemctl start httpd
systemctl status httpd
Output:
[root@server ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor pre>
Active: active (running) since Fri 2022-07-15 22:35:40 CEST; 6s ago
Docs: man:httpd.service(8)
Main PID: 1496 (httpd)
Status: "Started, listening on: port 80"
Tasks: 213 (limit: 11120)
Memory: 29.3M
CPU: 105ms
CGroup: /system.slice/httpd.service
├─1496 /usr/sbin/httpd -DFOREGROUND
├─1497 /usr/sbin/httpd -DFOREGROUND
├─1498 /usr/sbin/httpd -DFOREGROUND
├─1499 /usr/sbin/httpd -DFOREGROUND
└─1500 /usr/sbin/httpd -DFOREGROUND
Jul 15 22:35:40 server systemd[1]: Starting The Apache HTTP Server...
Jul 15 22:35:40 server httpd[1496]: AH00558: httpd: Could not reliably determin>
Jul 15 22:35:40 server httpd[1496]: Server configured, listening on: port 80
Jul 15 22:35:40 server systemd[1]: Started The Apache HTTP Server.
To make your pages available to the public, you will have to edit your firewall rules to allow HTTP and HTTPS requests on your web server by using the following commands.
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload
Output:
[root@server ~]# firewall-cmd --permanent --zone=public --add-service=http
success
[root@server ~]# firewall-cmd --permanent --zone=public --add-service=https
success
[root@server ~]# firewall-cmd --reload
success
Verify that the web server is running and accessible by accessing your server’s IP address.
echo "Hello there, Apache webserver is now running" > /var/www/html/index.html
And restart the Web Server to reflect the changes made.
systemctl restart httpd
From your browser,
http://IP_address
Install PHP 8
To add EPEL and REMI Repository.
dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm
To install yum utilities.
yum -y install yum-utils
To install remaining updates
dnf update
To install PHP along with a few commonly used PHP extensions on your Rocky Linux 9 use the command below.
dnf install -y 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
Check PHP Version.
php -v
Output:
[root@server ~]# php -v
PHP 8.0.13 (cli) (built: Nov 16 2021 18:07:21) ( NTS gcc x86_64 )
Copyright (c) The PHP Group
Zend Engine v4.0.13, Copyright (c) Zend Technologies
with Zend OPcache v8.0.13, Copyright (c), by Zend Technologies
Install MariaDB Server
MariaDB is a popular database server. The installation is simple and requires just a few steps as shown.
dnf install mariadb-server mariadb
Output:
[root@server ~]# dnf install mariadb-server mariadb
Last metadata expiration check: 0:03:02 ago on Fri 15 Jul 2022 10:44:26 PM CEST.
Dependencies resolved.
======================================================================================
Package Arch Version Repository 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:
checkpolicy x86_64 3.3-1.el9 appstream 339 k
libaio x86_64 0.3.111-13.el9 baseos 23 k
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-AutoLoader noarch 5.74-479.el9 appstream 30 k
perl-B x86_64 1.80-479.el9 appstream 188 k
perl-Carp noarch 1.50-460.el9 appstream 29 k
perl-Class-Struct noarch 0.66-479.el9 appstream 31 k
Once the installation is complete, enable MariaDB (to start automatically upon system boot), start the MariaDB, and verify the status using the commands below.
systemctl enable mariadb
systemctl start mariadb
systemctl status mariadb
Output:
[root@server ~]# systemctl status mariadb
● mariadb.service - MariaDB 10.5 database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disab>
Active: active (running) since Fri 2022-07-15 23:14:13 CEST; 9s ago
Docs: man:mariadbd(8)
https://mariadb.com/kb/en/library/systemd/
Process: 5174 ExecStartPre=/usr/libexec/mariadb-check-socket (code=exited, status=0/SUC>
Process: 5196 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir mariadb.service (code=ex>
Process: 5292 ExecStartPost=/usr/libexec/mariadb-check-upgrade (code=exited, status=0/S>
Main PID: 5278 (mariadbd)
Status: "Taking your SQL requests now..."
Tasks: 13 (limit: 11120)
Memory: 75.6M
CPU: 572ms
CGroup: /system.slice/mariadb.service
└─5278 /usr/libexec/mariadbd --basedir=/usr
Finally, you will want to secure your MariaDB installation by issuing the following command.
mysql_secure_installation
Output:
[root@server ~]# mysql_secure_installation
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
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
Once secured, you can connect to MySQL and review the existing databases on your database server by using the following command.
mysql -e "SHOW DATABASES;" -p
Output:
[root@server ~]# mysql -e "SHOW DATABASES;" -p
Enter password:
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
Done!
CrownCloud - Get a SSD powered KVM VPS at $4.5/month!
Use the code WELCOME
for 10% off!
1 GB RAM / 25 GB SSD / 1 CPU Core / 1 TB Bandwidth per month
Available Locations: LAX | MIA | ATL | FRA | AMS