I have a new server with CentOS 8, and I wanna have LAMP on it. In order to integrate PHP with Apache, I can remember there are two solutions: CLI and Apache module. But all howtos that I found are using php-fpm (which apparently is the CLI config with Apache).
I wanna know is there a way to config PHP as an Apache module on CentOS? If so, which package I should install using dnf?
One more thing, I can remember it was recommended to use PHP as an Apache module rather than using it as CLI. Is that still correct?
2
Answers
First thing –
php-cli
is meant for console operation without knowledge of HTTP request, HTTP server env variables and so on. It is used for CLI tasks like scripts run byCRON
.What you need is to have
mod_php
package installed. Then you have to enable (and configure) it within apache configuration.According to this article the metapackage
php
should already includemod_php
, so it should suffice to enable it.The module can be enabled interactively using
a2enmod
or by adding config directives manually, like:The example is not from Centos, so YMMV.
By
php-cli
, you probably meant php-cgi.php-cli is meant for running scripts from within terminal, not to be invoked from web server.
mod_php is not threadsafe if used in threaded MPM like
event
.For best performance you should try FPM, which is separate pool of workers that could be invoked via socket, regardless of actual MPM used by Apache.