How to install a LAMP stack on Oracle Linux

How to install a LAMP stack on Oracle Linux

The open-source software frameworks Linux, Apache, MySQL, and PHP (LAMP) work together to create strong web applications. The operating system used in this context is Linux. The web server is Apache (httpd in Redhat operating systems), and MySQL is a database management system. The backend programming language is PHP (Hypertext Pre-processor). In this blog, we'll look at the detailed steps on how to install MySQL, Apache, and PHP (the LAMP stack) on Oracle Linux 8.

Step 1: Apache Web Server Installation

Httpd is already available in Oracle Linux 8's official repository. We'll use the dnf command to install it, as seen.

sudo dnf -y install httpd

Start the httpd service and configure it to start when the device boots up.

sudo systemctl start httpd
sudo systemctl enable httpd

We'll configure our web application to run on port 80, so we'll need to open port 80 on the firewall.

sudo firewall-cmd --permanent --add-service={http,https}/tcp
sudo firewall-cmd --reload

Check that the Apache Web Server was successfully installed using your browser. Type http://your-server-ip> into your browser. As shown, you will be able to access the Apache default page:

Apache HTTP Server Test Page

Step 2: PHP installation on Oracle Linux 8

PHP is included in the Oracle Linux 8 official repository, much like httpd, making installation simple. Install the php modules mentioned as shown below. Please keep in mind that the command below will install php 7.2, which is presently available on Oracle Linux 8.

sudo dnf -y install php php-fpm php-mysqlnd php-opcache php-gd php-xml php-mbstring

Instead of mod_php, Rhel 8 uses php-fpm by default. We'll need to start php-fpm and make it available at boot time.

sudo systemctl start php-fpm

sudo systemctl enable php-fpm

Check the status of php-fpm to make sure it's up and running.

sudo systemctl status php-fpm

The end outcome must look like this:

PHP FPM Status

To use php, restart httpd.

sudo systemctl restart httpd

We must also test php in a browser. Make a file named info.php in the /var/www/html directory.

sudo vim /var/www/html/info.php

Save the file with the following lines of code.


Restart httpd after saving.

sudo systemctl restart httpd

Now navigate to http://your-server-ip>/info.php in your browser. The following should be the outcome of it:


Step 3: MySQL server installation on Oracle Linux 8

MySQL, which would be used to manage web application databases, is another module of LAMP. Install it on Oracle Linux 8 by running the command below.

sudo dnf -y install mariadb mariadb-server

Start MariaDB after it has been installed, and set it to start automatically when the device is rebooted.

sudo systemctl start mariadb
sudo systemctl enable mariadb

Run the following command to secure MySQL and set the root password:

sudo mysql_secure_installation

If you have a root password, enter it when prompted; otherwise, press Enter and proceed to set a new root password as well as the other parameters mentioned below:

Enter current password for root (enter for none): Just press Enter
Set root password? [Y/n] Y 
New password:  New-root-password
Re-enter new password: Re-enter New-root-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 
Thanks for using MariaDB!

You can now set up a database and a database user for our application. Run the following command to connect to MySQL:

mysql -u root -p

Enter the root password you created earlier. Run the commands below once you've connected:

CREATE USER [email protected] identified by ‘[email protected]$word’;

Step 4: Build Apache virtual host for your Website

Build a virtual host for your site using your chosen editor, as shown:

sudo vim /etc/httpd/conf.d/

Include the following information:

<VirtualHost *:80>
    DocumentRoot /var/www/
    ErrorLog /var/www/
    CustomLog /var/www/ combined

Let's make a sample web page now.

sudo mkdir /var/www/
sudo vim /var/www/

Add the following lines of markup to the page:

    <title>This is a test page</title>
    <h1>This is Working!</h1>

Restart httpd after saving the file and granting Apache ownership of the root directory.

sudo chown -R apache:apache /var/www/*
sudo chmod -R 755 /var/www
sudo systemctl restart httpd

To ensure that your virtual host is fully functional, launch your demo web page in your browser. You can see the content from your demo Html file if all is set up properly.

Working Page HTTPD


The LAMP stack is an essential element of any modern server. Hence, it is vital to have it installed and configured correctly and run web applications. In this blog, you have learned how to install Apache Web Server, PHP installation on Oracle Linux 8, Installation of MySQL Server on Oracle Linux 8, and how to create a virtual host using Apache for your website. You can also learn the concepts of Oracle such as what is Oracle Service Bus, an overview of installing Oracle Service Bus, various functions and routes involved in learning oracle services etc, through our Oracle service bus tutorial available online. This would also assist you in transforming your career into an Oracle platform and helps in upgrading your professional skills which is helpful while developing your projects on web servers such as Apache connecting MySQL databases as its backend with PHP implementation.

This could interest you

Become a more social person