LAMP is made up of Apache Web Server, MySQL/MariaDB database server and PHP scripting language. It is a very Popular hosting stack widely used by developers to test-run and host websites at every stage of website development.
In this context, we shall look into the process of installing LAMP on Rocky Linux 8.4.
Follow the steps outlined below to successfully get LAMP Stack Installed on Rocky Linux.
To begin, we will begin with the installation of Apache web server as the first component of the LAMP stack. To achieve this, launch your browser and run the command:
$ sudo dnf install httpd
The command installs the Apache httpd package alongside other dependencies.
Next, be sure to enable Apache web server to start every time the system is started or booted:
$ sudo systemctl enable httpd
Once enabled, start the Apache systemd service:
$ sudo systemctl start httpd
To be cocksure that Apache is running on Rocky Linux 8, issue the command:
$ sudo systemctl status httpd
You can also verify on a web browser by browsing your server’s IP address or domain name:
This displays the Apache HTTP test page, and this indicates that the webserver has been successfully installed.
Once the Apache web server is in place, the next course of action is to install a database engine, in this case MariaDB server. The AppStream repos for Rocky Linux provide MariaDB 10.3 by the time of writing the tutorial. To install MariaDB, run the command:
$ sudo dnf install mariadb-server mariadb
Once installed, enable MariaDB on boot time with the below command:
$ sudo systemctl enable --now mariadb
Then start the service:
$ sudo systemctl start mariadb
To confirm MariaDB service is active and running, invoke the command:
$ sudo systemctl status mariadb
The default settings for MariaDB are weak and present security loopholes that can easily be exploited by hackers and unauthorized users. Therefore, additional steps must be taken to fortify the security of the database server.
To achieve this, run the script shown:
$ sudo mysql_secure_installation
Since we haven't yet set the root password, we will hit ENTER upon where we will be required to set the root password. Setting the root password is recommended as it ensures that no one can log into the root user without authorization.
Therefore, set the root account.
For the remaining prompts, type in 'Y' to secure MariaDB to the recommended standards. This purges the anonymous users , disallows remote root login and gets rid of the test database which is not required in a production database.
MariaDB database is now fully configured and secure.
The final component of the LAMP stack that we are going to install is PHP. Rocky Linux AppStream provides multiple versions as per the command provided below:
$ sudo dnf module list php
To install the latest module from the repository, perform a reset first:
$ sudo dnf module list reset php
Now, you can install your preferred PHP version. For instance, to install PHP 7.4, run the command:
$ sudo dnf module install php:7.4
To confirm PHP is installed, run the command:
$ php -v
Alternatively, you can verify the version installed by creating a test PHP file in the /var/www/html path:
$ sudo vim /var/www/html/info.php
Add the configuration below:
Finally, head over to your browser and browse the URL below:
This displays the following PHP page indicating the version installed and other detailed information such as the system architecture, build date, and PHP extensions.
You can now remove the test PHP file:
$ sudo rm -f /var/www/html/info.php
This article covers how to install LAMP stack on Rocky Linux 8.4. You can now proceed to test or host your website and applications. 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.
How to Install and configure Apache Web Server ?
1. First, we will start by installing the Apache web server. To complete the installation, use the following command:
$ yum install httpd httpd-tools
2. 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
3. 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
4. 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
5. And restart tht Web Server to reflect the changes made:
$ systemctl restart httpd
From your browser,
How to Install PHP on CentOS ?
1. To install PHP on your RHEL 8 use the command below:
$ yum install -y 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
2. Now restart your web server so that Apache knows that it will be serving PHP requests as well:
$ systemctl restart httpd