- CentOS 7.5
- Apache 2.4.33
- PHP-FPM 7.2 (installed through the Remi repo)
So I’m trying to get this manually-compiled version of Apache running with PHP. Apache is all fine and dandy, but I’m not sure if I’ve installed things on the PHP side of things correctly or if the problem could be in my virtual host configuration. I’m going to try and add any relevant information:
PHP packages that are currently installed
mod_fcgid-2.3.9-15.el7.x86_64
php-7.2.7-1.el7.remi.x86_64
php-cli-7.2.7-1.el7.remi.x86_64
php-common-7.2.7-1.el7.remi.x86_64
php-fpm-7.2.7-1.el7.remi.x86_64
php-gd-7.2.7-1.el7.remi.x86_64
php-json-7.2.7-1.el7.remi.x86_64
php-mbstring-7.2.7-1.el7.remi.x86_64
php-mysqlnd-7.2.7-1.el7.remi.x86_64
php-opcache-7.2.7-1.el7.remi.x86_64
php-pdo-7.2.7-1.el7.remi.x86_64
php-xml-7.2.7-1.el7.remi.x86_64
php-xmlrpc-7.2.7-1.el7.remi.x86_64
Loaded modules
access_compat_module (shared)
auth_basic_module (shared)
authn_core_module (shared)
authn_file_module (shared)
authz_core_module (shared)
authz_groupfile_module (shared)
authz_host_module (shared)
authz_user_module (shared)
autoindex_module (shared)
core_module (static)
deflate_module (shared)
dir_module (shared)
env_module (shared)
fcgid_module (shared)
filter_module (shared)
headers_module (shared)
http2_module (shared)
http_module (static)
log_config_module (shared)
mime_module (shared)
mpm_event_module (static)
proxy_fcgi_module (shared)
proxy_module (shared)
reqtimeout_module (shared)
rewrite_module (shared)
setenvif_module (shared)
socache_shmcb_module (shared)
so_module (static)
ssl_module (shared)
unixd_module (shared)
version_module (shared)
User for Apache is httpd, group is www-data.
Below is the virtual host config (tried mashing things together based on some articles but the implementation wasn’t entirely clear to me).
<VirtualHost *:80>
ServerName domain.com
ServerAlias www.domain.com
DocumentRoot /var/www/domain.com/httpdocs
ErrorLog /var/www/domain.com/logs/error_log
CustomLog /var/www/domain.com/logs/access_log combined
# <LocationMatch "^/(.*.php(/.*)?)$">
# ProxyPass fcgi://127.0.0.1:9000/var/www/domain.com/httpdocs/$1
# </LocationMatch>
<IfModule mod_fastcgi.c>
AddHandler php7-fcgi-webmin .php
Action php7-fcgi-webmin /php7-fcgi-webmin
Alias /php7-fcgi-webmin /usr/lib/cgi-bin/php7-fcgi-webmin
<Directory "/usr/lib/cgi-bin">
Require all granted
</Directory>
<FilesMatch ".+.ph(p[345]?|t|tml)$">
SetHandler php7-fcgi-webmin
</FilesMatch>
</IfModule>
<Directory /var/www/domain.com/httpdocs>
AllowOverride All
Require all granted
Options +FollowSymLinks -Indexes -Includes
</Directory>
</VirtualHost>
Below is the FPM pool configuration for the site.
[domain_com]
user = webmin
group = www-data
listen = 127.0.0.1:9000
listen.allowed_clients = 127.0.0.1
listen.owner = webmin
listen.group = www-data
pm = dynamic
pm.max_children = 50
pm.start_servers = 2
pm.min_spare_servers = 2
pm.max_spare_servers = 35
slowlog = /var/www/domain.com/logs/php_fpm_slow_log
php_flag[display_errors] = off
php_admin_value[error_log] = /var/www/domain.com/logs/php_fpm_error_log
php_admin_flag[log_errors] = on
php_admin_value[memory_limit] = 64M
php_admin_value[open_basedir] = /var/www/domain.com/httpdocs
php_value[session.save_handler] = files
php_value[session.save_path] = /var/lib/php/session
php_value[soap.wsdl_cache_dir] = /var/lib/php/wsdlcache
And that’s where I’m at. When I visit a phpinfo page, it just prints the contents of the PHP file. There’s not anything logged in Apache or PHP-FPM logs. Can someone tell me where I may have gone wrong? I have no problem with running through the whole process again if needed, or repairing things if that’s possible.
2
Answers
With apache 2.4, best way is to use FPM and a SetHandler to proxy
And you can read PHP Configuration Tips where the switch to FPM is explained.
You can remove the “php” package (which provides the mod_php which is uneeded)
[PHP-fpm With apache]
yum -y install httpd
systemctl start httpd.service
systemctl enable httpd.service
mkdir /etc/httpd/sites-available
mkdir /etc/httpd/sites-enabled
Add this line to the end of the file
vim /etc/httpd/conf/httpd.conf
IncludeOptional sites-enabled/*.conf
vim /etc/httpd/sites-available/example.com.conf
<VirtualHost *:80>
ProxyPassMatch ^/(.*.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/html/$1
</VirtualHost>
ln -s /etc/httpd/sites-available/example.com.conf /etc/httpd/sites-enabled/example.com.conf
systemctl restart httpd.service