As is always recommended, it’s a good idea to update software packages before embarking on any installation. So log in to your server and run the command below.
With the system packages up to date, the next step is installing the Apache Web Server and some crucial tools and utilities run the command.
If you are a little curious, you can get the version of apache among other details related to Apache by running the rpm command.
Additionally, you can open your web browser and visit your server’s IP a shown.
http://server-IP
Step 3: Install MariaDB on CentOS 8
MariaDB is a fork of MySQL database . It was developed by a former team of MySQL who had concerns that Oracle may turn MySQL to a closed-source project. It ships with innovative and better features than MySQL that make it a better option than MySQL.
To install MariaDB, run the command.
$ dnf install mariadb-server mariadb -y
Next, start and enable MariaDB on startup, run the command.
$ systemctl start mariadb
$ systemctl enable mariadb
You can verify the status of MariaDB by running the command.
$ systemctl status mariadb
Lastly, we need to secure our MariaDB database engine by running.
$ mysql_secure_installation
You will be prompted to enter the root password ( if you already have a root password in place) or set it up. Thereafter, answer Y
for every subsequent prompt.
Step 4: Install PHP 7 on CentOS 8
The last component in the LAMP stack we need to install is PHP, and as mentioned earlier, PHP is a scripting web programming language used for developing dynamic web pages.
We are going to install the latest version of PHP ( PHP 7.4 by the time of penning down this guide) using the Remi repository.
First, install the EPEL repository.
$ sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
Next, install yum utils and enable remi-repository using the command below.
$ sudo dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-latest-8.noarch.rpm
After the successful installation of yum-utils and Remi-packages, search for the PHP modules which are available for download by running the command.
$ sudo dnf module list php
The output will include the available PHP modules, stream and installation profiles as shown below.
List PHP Module in CentOS 8
The output indicates that the currently installed version of PHP is PHP 7.2. To install the newer release, PHP 7.4, reset the PHP modules.
$ sudo dnf module reset php
Reset PHP Module in CentOS 8
Having reset the PHP modules, enable the PHP 7.4 module by running.
$ sudo dnf module enable php:remi-7.4
Enable PHP Module in CentOS 8
Finally, install PHP, PHP-FPM (FastCGI Process Manager) and associated PHP modules using the command.
$ sudo dnf install php php-opcache php-gd php-curl php-mysqlnd
Install PHP Modules in CentOS 8
To verify the version installed to run.
$ php -v
Check PHP Version in CentOS 8
Perfect! We now have PHP 7.4 installed. Equally important, we need to start and enable PHP-FPM on boot-up.
$ sudo systemctl start php-fpm
$ sudo systemctl enable php-fpm
To check its status execute the command.
$ sudo systemctl status php-fpm
Check PHP-FPM Status
To instruct SELinux to allow Apache to execute the PHP code via PHP-FPM run.
$ setsebool -P httpd_execmem 1
Finally, restart Apache web server for PHP to work with Apache web server.
$ sudo systemctl restart httpd
Step 5: Testing PHP Information
To test PHP with the web server, you’ll have to create an info.php file to the document root directory.
$ v /var/www/html/info.php
Insert the PHP code below and save the file.
<?php
phpinfo ();
?>
Then head out to your browser, and type the URL below. Remember to replace the server IP address with your server’s actual IP address.
http://server-ip-address/info.php