LAMP stands for “Linux, Apache, MariaDB, and PHP,” a free, open-source, widely used software stack to host web applications. LAMP is a collection of free software solutions that are used together to enable a server to host dynamic websites and web applications. Each component of the LAMP stack contributes essential capabilities. Linux is a free and open-source operating system, Apache is an open-source web server that processes requests and serves web pages, MySQL is an open-source relational database management system for storing application data, and PHP is an open-source scripting language that works with Apache to help you create dynamic web pages.

In this post, we will explain how to install the LAMP stack on Oracle Linux 8.

Step 1 – Install Apache Web Server on Oracle Linux 8

By default, the Apache webserver is available in the Oracle Linux 8 default repo. You can install it by running the following command:

dnf install httpd -y

You should see the following output:

Oracle Linux 8 BaseOS Latest (x86_64)                                                                          31 MB/s |  44 MB     00:01    
Oracle Linux 8 Application Stream (x86_64)                                                                     29 MB/s |  33 MB     00:01    
Latest Unbreakable Enterprise Kernel Release 6 for Oracle Linux 8 (x86_64)                                     37 MB/s |  43 MB     00:01    
Last metadata expiration check: 0:00:12 ago on Tuesday 03 May 2022 06:00:19 AM EDT.
Dependencies resolved.
==============================================================================================================================================
 Package                       Architecture      Version                                                   Repository                    Size
==============================================================================================================================================
Installing:
 httpd                         x86_64            2.4.37-43.0.3.module+el8.5.0+20624+5d3b49d0.3             ol8_appstream                1.4 M
Installing dependencies:
 apr                           x86_64            1.6.3-12.el8                                              ol8_appstream                129 k
 apr-util                      x86_64            1.6.1-6.el8                                               ol8_appstream                105 k
 httpd-filesystem              noarch            2.4.37-43.0.3.module+el8.5.0+20624+5d3b49d0.3             ol8_appstream                 40 k
 httpd-tools                   x86_64            2.4.37-43.0.3.module+el8.5.0+20624+5d3b49d0.3             ol8_appstream                108 k
 mod_http2                     x86_64            1.15.7-3.module+el8.4.0+20024+b87b2deb                    ol8_appstream                154 k
 oracle-logos-httpd            noarch            84.5-1.0.1.el8                                            ol8_baseos_latest             29 k
Enabling module streams:
 httpd                                           2.4                                                                                         

Transaction Summary
==============================================================================================================================================
Install  7 Packages

Total download size: 2.0 M
Installed size: 5.4 M
Is this ok [y/N]: 

Once the Apache web server is installed, start the Apache service and enable it to start at system reboot.

systemctl start httpd
systemctl enable httpd

Next, check the running status of the Apache service using the following command:

systemctl status httpd

You should see the following output:

● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Tue 2022-05-03 06:01:07 EDT; 7s ago
     Docs: man:httpd.service(8)
 Main PID: 1689 (httpd)
   Status: "Started, listening on: port 80"
    Tasks: 213 (limit: 23694)
   Memory: 25.1M
   CGroup: /system.slice/httpd.service
           ├─1689 /usr/sbin/httpd -DFOREGROUND
           ├─1690 /usr/sbin/httpd -DFOREGROUND
           ├─1691 /usr/sbin/httpd -DFOREGROUND
           ├─1692 /usr/sbin/httpd -DFOREGROUND
           └─1693 /usr/sbin/httpd -DFOREGROUND

May 03 06:01:07 oraclelinux8 systemd[1]: Starting The Apache HTTP Server...

Next, open your web browser and verify the Apache test page using the URL http://your-server-ip. You should see the Apache test page on the following screen:
LAMP server Apache test page

Also Read

How to Install and Configure Apache Web Server on Oracle Linux 8

Step 2 – Install MariaDB Database Server on Oracle Linux 8

By default, the MariaDB or MySQL package is included on the Oracle Linux default repo. I would recommend installing a MariaDB server due to its numerous enhancements like high-performance storage engines and backward compatibility with MySQL.

You can install the MariaDB server with the following command:

dnf install mariadb-server -y

Once the MariaDB package is installed, start the MariaDB service and enable it to start at system reboot:

systemctl start mariadb
systemctl enable mariadb

Next, verify the MariaDB service status using the following command:

systemctl status mariadb

Next, you will need to run the mysql_secure_installation script to secure the MariaDB installation.

You can run it using the following command:

mysql_secure_installation

You will then be prompted to set a MariaDB root password, remove anonymous users, disallow root login, and remove the test database as shown below:

Enter current password for root (enter for none): 
Set root password? [Y/n] Y
New password: 
Re-enter new password: 
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

Step 3 – Install PHP on Oracle Linux 8

Next, you will need to install PHP (PHP Hypertext Preprocessor) in your system. By default, the Oracle Linux AppStream repo provides multiple versions of PHP.

You can check all available PHP versions using the following command:

dnf module list php

You should see the following output:

Last metadata expiration check: 0:02:34 ago on Tuesday 03 May 2022 06:00:19 AM EDT.
Oracle Linux 8 Application Stream (x86_64)
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                    

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

The default PHP version is set to PHP 7.2. If you want to install the latest PHP 7.4, you will need to reset the default PHP steams.

Run the following command to reset the default PHP:

dnf module reset php

Next, enable PHP version 7.4 using the following command:

dnf module enable php:7.4
Last metadata expiration check: 0:02:57 ago on Tuesday 03 May 2022 06:00:19 AM EDT.
Dependencies resolved.
==============================================================================================================================================
 Package                           Architecture                     Version                           Repository                         Size
==============================================================================================================================================
Enabling module streams:
 nginx                                                              1.14                                                                     
 php                                                                7.4                                                                      

Transaction Summary
==============================================================================================================================================

Is this ok [y/N]: y

Next, install PHP 7.4 with other extensions using the following command:

dnf install php php-cli php-curl php-zip php-mysqli -y

Once PHP is installed, verify the installed version of PHP with the following command:

php -v

You should see the following command:

PHP 7.4.19 (cli) (built: May  4 2021 11:06:37) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

You can also test the PHP version through the web browser.

To do so, create an info.php file:

nano /usr/share/httpd/noindex/info.php

Add the following code:

<?php
phpinfo();
?>

Save and close the file, then restart the Apache service to apply the changes:

Next, edit the Apache default configuration file:

nano /etc/httpd/conf.d/welcome.conf

Find the following line:

AllowOverride None

And replace it with the following line:

AllowOverride All

Next, restart the Apache service to apply the changes:

systemctl restart httpd

Now, open your web browser and access the info.php page using the URL http://your-server-ip/info.php. You should see the PHP information on the following screen:
LAMP server PHP test page

Also Read

Best Practice for Creating a HIPAA-Compliant LAMP Stack

Conclusion

In the above guide, we learned how to install the LAMP stack on Oracle Linux 8. You can now start developing a PHP-based web application and host it using the LAMP stack. Give it a try on your virtual private server from Atlantic.Net!