CentOS – How to Install PHP on CentOS with Preinstalled Apache HTTPD

apache-2.4centoscentos7PHPphp7

I'm using CentOS 7. I wanted to install PHP 7 so I used remi-php (latest PHP version of yum is 5.4). Since the HTTPD version of yum is too old, I compiled the latest HTTPD version from the source code.

HTTPD compilation goes perfectly, however, when I try to install remi-php using the following command:

yum --enablerepo=remi-php71 install php php-cli php-intl php-mbstring php-mcrypt php-mysqlnd

To install php, yum will also install the old version of httpd (although I have compiled and used the latest HTTPD version). If I continue with the installation, my HTTPD will throw an error (and won't start), but if I don't continue with the installation, I won't have the php*.so file and apache won't parse the .php files.

So, how do I install php without affecting the Apache HTTPD that I have compiled before? I don't want my server to have two instances of Apache HTTPD at the same time and may have problems in the future.

Your answer given will be very helpful to me.

I will appreciate your answer.

Best Answer

"mod_php" (the main "php" package) is build with system httpd, so cannot be installed without it.

Using FPM (php-fpm) you can use any webserver.

I recommend you read PHP Configuration Tips which explain how to switch to FPM, and why it is better.

Notice:

  • httpd 2.4 in CentOS 7 is maintained and have all security fixes, see Backporting Security Fixes
  • More recent version is also available, with new features in the httpd24 Software Collections, maintain by the SCLo SIG from RHSCL.
  • httpd 2.4 in CentOS 8 is also more recent (and use FPM by default)