Skip to content
Bots!
Bots!
  • About
    • Myself
    • আমার দোয়া
  • Bookmarks
    • Bookmarks
    • My OCI Bookmarks
    • Useful Proxmox Commands & Links
    • Learning Nano
    • Useful Sites
    • Useful Virtualbox Command
    • Useful MySQL Command
    • Useful Linux Command
    • BTT-CAS
  • Resources
    • Webinar on Cloud Adoption for Project Managers
  • Photos
  • Videos
  • Downloads
Bots!

Install LAMP with PHP 7.4 on FastCGI/CGI configuration on CentOS 7

Rumi, March 24, 2021

Step 1 – Setup Yum Repository

In the first step install all the required yum repositories in your system used in the remaining tutorial for various installations. You are adding REMI, EPEL, Webtatic & MySQL community server repositories in your system.

CentOS / RHEL 7

yum install epel-release
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
rpm -Uvh http://repo.mysql.com/mysql-community-release-el7-7.noarch.rpm

Step 2 – Install PHP 7.4

Now install php 7 packages from webtatic rpm repository using following command.

yum --enablerepo=remi-php74 install php

Now install required php modules. Use following command to list available modules in yum repositories.

yum --enablerepo=remi-php74 search php

Now check all listed modules in above command and install required modules like below.

yum --enablerepo=remi-php74 install php-mysql php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt

For additonal php function to install use the command syntax below-

yum --enablerepo=remi-php74 install <your-php-funciton>

Step 3 – Install Apache 2.4

Apache (HTTPD) is the most popular web server used on Linux systems. Let’s install Apache web server using following command with enabling epel and remi yum repositories.

yum --enablerepo=epel,remi install httpd

Now start httpd service and enable to start on boot using below commands.

systemctl start httpd.service
systemctl enable httpd.service

Step 4 – Install MySQL 5.6

In step 1 we already have installed required yum repository in your system. Let’s use the following command to install MySQL server on your system. If you want to install MySQL 5.7 visit this tutorial.

yum install mysql-server

Apply security on mysql and also set root user password.

systemctl start mysqld.service
mysql_secure_installation

Now restart MySQL service and enable to start on system boot.

systemctl restart mysqld.service
systemctl enable mysqld.service

Step 5 – Open Port in Firewall

Finally open firewall ports for HTTP (80) and https (443) services using the following command.

firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload

Step 6 – Check Installed Version

Let’s check the installed versions of packages on system using following commands one by one.

php -v
PHP 7.2.0 (cli) (built: Nov 28 2017 20:22:21) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2017 Zend Technologies
httpd -v
Server version: Apache/2.4.6 (CentOS)
Server built: Nov 19 2015 21:43:13
mysql -V
mysql Ver 14.14 Distrib 5.6.28, for Linux (x86_64) using EditLine wrapper

Now you have successfully configured LAMP setup on your CentOS / RHEL 7.4 & 6.9 systems.

Step 7 – Install PHP and FastCGI

After installing the Apache web server, let’s install PHP and FastCGI Apache module on your system. You can install any version of the required PHP or simply use the following command to install available PHP packages. This tutorial doesn’t include installing PHP modules, So you can also install required PHP modules.

yum --enablerepo=remi-php74 install php php-cli mod_fcgid

Step 8 – Disable Default PHP Handler

Before using PHP/FastCGI handler, you have to disable the default PHP handler on your system. Edit PHP configuration file for Apache (/etc/httpd/conf.d/php.conf) in your favorite text editor and comment following lines showing in below screenshot by adding the hash (#) sign at the start of the lines.

Step 9 – Setup FastCGI Handler

At this point we have successfully installed Apache FastCGI Module. Now nagigate to /var/www/cgi-bin directory, If not exists create directory. Then create a php.fastcgi file and add the following content to this file. Also make sure the php.ini file and php-cgi exist on your system.

vim /var/www/cgi-bin/php.fastcgi
#!/bin/bash

PHPRC="/etc/php.ini"
PHP_FCGI_CHILDREN=4
PHP_FCGI_MAX_REQUESTS=1000
export PHPRC
export PHP_FCGI_CHILDREN
export PHP_FCGI_MAX_REQUESTS
exec /usr/bin/php-cgi

Change permissions of php.fastcgi script to make it executable by Apache server.

chown apache:apache /var/www/cgi-bin/php.fastcgi
chmod +x /var/www/cgi-bin/php.fastcgi

Step 10 – Setup VirtualHost with FastCGI

Finally, create a VirtualHost in our Apache configuration file with FastCGI support. VirtualHosts are used to configure multiple sites with a single IP. Below configuration will allow siting svr1.tecadmin.net with any system IP on port 80.

<VirtualHost *:80>
ServerName svr1.tecadmin.net
ServerAdmin admin@tecadmin.net
DocumentRoot /var/www/html
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
<Directory "/var/www/html">
Options +Indexes +FollowSymLinks +ExecCGI
AddHandler php-fastcgi .php
Action php-fastcgi /cgi-bin/php.fastcgi
AllowOverride All
Order allow,deny
Allow from All
</Directory>
</VirtualHost>

Step 11 – Restart Apache and Test Setup

At this point, you have completed the Apache configuration with FastCGI support. Let’s restart the Apache server using the following command.

service httpd restart

Now create a file in your document root /var/www/html/info.php and add following content to check detailed php information.

<?php
  phpinfo();
?>

Access your Apache server using an IP address for domain name followed by php.info file in your web browser like below. This will show the current configuration of PHP in your system. Look the value of Server API option, if you get this value CGI/FastCGI, it means server is properly configured to use FastCGI.

Src:

https://tecadmin.net/setup-httpd-with-fastcgi-and-php-on-centos-redhat/
https://tecadmin.net/install-php-7-apache-2-4-mysql-on-centos-rhel/

Administrations Configurations (Linux) CentOS 7LAMPPHP 7.4

Post navigation

Previous post
Next post

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Myself…

Hi, I am Hasan T. Emdad Rumi, an IT Project Manager & Consultant, Virtualization & Cloud Savvyfrom Dhaka, Bangladesh. I have prior experience in managing numerous local and international projects in the area of Telco VAS & NMC, National Data Center & PKI Naitonal Root and CA Infrastructure. Also engaged with several Offshore Software Development Team.

Worked with Orascom Telecom-Banglalink, Network Elites as VAS partner, BTRC, BTT (Turkey) , Mango Teleservices Limited and Access to Informaiton (A2I-UNDP)

Currently working at Oracle Corporation as Principal Technology Solution and Cloud Architect.

You can reach me [h.t.emdad at gmail.com] and I will be delighted to exchange my views.

Tags

Apache Bind Cacti CentOS CentOS 6 CentOS 7 Debain Debian Debian 10 Debian 11 Debian 12 DKIM Docker endian icinga iptables Jitsi LAMP Letsencrypt Linux Munin MySQL Nagios Nextcloud NFS nginx pfsense php Postfix powerdns Proxmox RDP squid SSH SSL Ubuntu Ubuntu 16 Ubuntu 18 Ubuntu 20 Varnish virtualbox vpn Webmin XCP-NG zimbra

Topics

Recent Posts

  • Install Jitsi on Ubuntu 22.04 / 22.10 April 30, 2025
  • Key Lessons in life April 26, 2025
  • Create Proxmox Backup Server (PBS) on Debian 12 April 19, 2025
  • Add Physical Drive in Proxmox VM Guest April 19, 2025
  • Mount a drive permanently with fstab in Linux April 16, 2025
  • Proxmox 1:1 NAT routing March 30, 2025
  • Installation steps of WSL – Windows Subsystem for Linux March 8, 2025
  • Enabling Nested Virtualization In Proxmox March 8, 2025
  • How to Modify/Change console/SSH login banner for Proxmox Virtual Environment (Proxmox VE / PVE) March 3, 2025
  • Install Proxmox Backup Server on Debian 12 February 12, 2025

Archives

Top Posts & Pages

  • Install Jitsi on Ubuntu 22.04 / 22.10
©2025 Bots! | WordPress Theme by SuperbThemes