How to Install LAMP Stack on AlmaLinux 8
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 which 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.
Install Apache Web Server
First, we will start by installing the Apache web server. To complete the installation, use the following command.
yum install httpd httpd-tools
Output:
[root@server ~]# yum install httpd
AlmaLinux 8.3 - BaseOS 14 MB/s | 2.6 MB 00:00
AlmaLinux 8.3 - AppStream 21 MB/s | 6.5 MB 00:00
AlmaLinux 8.3 - PowerTools 8.0 MB/s | 1.9 MB 00:00
AlmaLinux 8.3 - Extras 12 kB/s | 1.2 kB 00:00
Dependencies resolved.
================================================================================
Package Arch Version Repo Size
================================================================================
Installing:
httpd x86_64 2.4.37-30.module_el8.3.0+2016+8bf57d29.alma appstream 1.4 M
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 prese>
Active: active (running) since Mon 2021-02-08 15:03:51 EST; 5s ago
Docs: man:httpd.service(8)
Main PID: 26398 (httpd)
Status: "Started, listening on: port 80"
Tasks: 213 (limit: 23680)
Memory: 29.1M
CGroup: /system.slice/httpd.service
├─26398 /usr/sbin/httpd -DFOREGROUND
├─26399 /usr/sbin/httpd -DFOREGROUND
To make your pages available to 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.
And restart tht Web Server to reflect the changes made.
systemctl restart httpd
From your browser,
http://IP_address
Install PHP
By default, AlmaLinux uses PHP 7.2 and since it is EOL, we will install PHP 7.4 instead.
If you would like to install a different version of PHP from remi repository, please refer Install PHP 7.X wiki.
We will install the EPEL Repository,
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
To install PHP 7.4 on AlmaLinux, use the command below.
dnf module install php:7.4
Alternatively, to see which versions of PHP are available and which version is selected by default, use the following command,
dnf module list php
Which should return output similar to,
[root@vps ~]# dnf module list php
Last metadata expiration check: 2:34:31 ago on Thu 27 Jun 2024 06:39:12 PM UTC.
AlmaLinux 8 - AppStream
Name Stream Profiles Summary
php 7.2 [d] common [d], devel, minimal PHP scripting language
php 7.3 common [d], devel, minimal PHP scripting language
php 7.4 common [d], devel, minimal PHP scripting language
php 8.0 common [d], devel, minimal PHP scripting language
php 8.2 common [d], devel, minimal PHP scripting language
Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
[root@vps ~]#
We will need other PHP modules as well,
yum install -y php-mysqlnd php-dom php-simplexml php-xml php-intl php-xmlreader php-curl php-exif php-ftp php-gd php-iconv php-json php-mbstring php-posix php-sockets php-tokenizer
Now restart your web server so that Apache knows that it will be serving PHP requests as well.
systemctl restart httpd
Test your PHP, by creating a simple info.php file with a phinfo() in it. The file should be placed in the directory root for your web server, which is /var/www/html
.
To create the file use:
echo "<?php phpinfo() ?>" > /var/www/html/info.php
Now again, access http://localhost/info.php or http://yourserver-ip-address/info.php. You should see a page similar to below one.
Install MariaDB Server
MariaDB is a popular database server. The installation is simple and requires just a few steps as shown.
yum install mariadb-server mariadb
Output:
[root@server ~]# yum install mariadb-server mariadb
Last metadata expiration check: 0:05:56 ago on Mon 08 Feb 2021 03:03:08 PM EST.
Dependencies resolved.
================================================================================
Package Arch Version Repo Size
================================================================================
Installing:
mariadb x86_64 3:10.3.27-3.module_el8.3.0+2028+5e3224e9
appstream 6.0 M
mariadb-server x86_64 3:10.3.27-3.module_el8.3.0+2028+5e3224e9
appstream 16 M
Installing dependencies:
mariadb-common x86_64 3:10.3.27-3.module_el8.3.0+2028+5e3224e9
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.3 database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor pre>
Active: active (running) since Mon 2021-02-08 15:10:12 EST; 5s ago
Docs: man:mysqld(8)
https://mariadb.com/kb/en/library/systemd/
Process: 30138 ExecStartPost=/usr/libexec/mysql-check-upgrade (code=exited, s>
Process: 30004 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mariadb.service>
Process: 29979 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, sta>
Main PID: 30107 (mysqld)
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