For all the web services on CentOS / Red Hat you will need web server, database and a few more bits. This is why LAMP (Linux, Apache, MySQL/MariaDB, PHP) stack is needed.
Here is a quick tutorial with basic installation and security steps. All commands are executed as root user.
Prerequisites
Following command will install all the packages, tools and basics needed for LAMP installation.
dnf install php-mysqlnd php-fpm mariadb-server httpd
Confirm installation with y
Next step is to let through HTTP 80 and HTTPS 443 through firewall
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload
We will now start Apache and MariaDB services
systemctl start mariadb
systemctl start httpd
We will also enable automatic starting of Apache and MariaDB after reboot
systemctl enable httpd.service
systemctl enable mariadb
After service start, we are going to secure MariaDB install and set root pass
mysql_secure_installation
First, we will just confirm with enter since password is not set, then set new password (always set strong pass) and then confirm as you like, I pressed “y” for every option.
Following step will to create info.php file within /var/www/html/ directory
vi /var/www/html/info.php
Enter following content
<?php phpinfo(); ?>
When done – save and exit.
We will also need to change permissions and security of SELinux
chown -R apache:apache /var/www/html/*
chcon -t httpd_sys_rw_content_t /var/www/html/ -R
Lets now visit our “website” on address http://localhost/info.php to confirm working installation.
Success!
Now, this is just basic installation and you will probably need more PHP modules for your installation. To list PHP modules, enter following command
dnf search php
–
To install some of the modules you will enter following,
dnf install PACKAGENAME
Example would be
dnf install php-gd.x86_64
Once you installed all the PHP packages you need, restart httpd service
systemctl reload httpd