1

Summary: My CentOS 7 server with PHP 7.4 fpm is not executing PHP files instead they provide a raw PHP file to the client. In the next section, I will explain the environment.


I have set up a minimal CentOS in a virtualbox.

The server has no apt, no GUI, no virtual box guest addition (please do not expect me copy pasting texts instead of screenshots) and no any fancy feature.

I am also very strict on which URL I get a package from. That's why I never download a package by

yum install <xxx> 

instead, I use this way to install any package

rpm -Uhv --reinstall <http://.... .rpm> 

After installation of minimal CentOS 7,

Installed Apache httpd24u-2.4.54 from IUS repository:

rpm -Uvh --reinstall https://repo.ius.io/7/x86_64/packages/a/apr15u-1.5.2-2.ius.el7.x86_64.rpm rpm -Uvh --reinstall https://repo.ius.io/7/x86_64/packages/a/apr15u-util-1.5.4-3.ius.el7.x86_64.rpm rpm -Uvh --reinstall https://repo.ius.io/7/x86_64/packages/h/httpd24u-filesystem-2.4.54-2.el7.ius.noarch.rpm rpm -Uvh --reinstall https://repo.ius.io/7/x86_64/packages/h/httpd24u-tools-2.4.54-2.el7.ius.x86_64.rpm rpm -Uvh --reinstall https://download-ib01.fedoraproject.org/pub/epel/7/x86_64/Packages/l/libnghttp2-1.33.0-1.1.el7.x86_64.rpm rpm -Uvh --reinstall https://download-ib01.fedoraproject.org/pub/epel/7/x86_64/Packages/b/brotli-1.0.7-5.el7.x86_64.rpm rpm -Uvh --reinstall http://mirror.centos.org/centos/7/os/x86_64/Packages/mailcap-2.1.41-2.el7.noarch.rpm rpm -Uvh --reinstall https://repo.ius.io/7/x86_64/packages/h/httpd24u-2.4.54-2.el7.ius.x86_64.rpm 

Then, installed Apache modules,

rpm -Uvh --reinstall https://repo.ius.io/7/x86_64/packages/a/apr15u-util-ldap-1.5.4-3.ius.el7.x86_64.rpm rpm -Uvh --reinstall https://repo.ius.io/7/x86_64/packages/h/httpd24u-mod_ldap-2.4.54-2.el7.ius.x86_64.rpm rpm -Uvh --reinstall https://repo.ius.io/7/x86_64/packages/h/httpd24u-mod_ssl-2.4.54-2.el7.ius.x86_64.rpm rpm -Uvh --reinstall https://repo.ius.io/7/x86_64/packages/h/httpd24u-mod_session-2.4.54-2.el7.ius.x86_64.rpm 

Then, installed PHP 7.4 fpm:

rpm -Uvh --reinstall https://repo.ius.io/7/x86_64/packages/p/php74-common-7.4.30-1.el7.ius.x86_64.rpm rpm -Uvh --reinstall https://repo.ius.io/7/x86_64/packages/p/php74-fpm-7.4.30-1.el7.ius.x86_64.rpm rpm -Uvh --reinstall https://repo.ius.io/7/x86_64/packages/p/php74-fpm-httpd-7.4.30-1.el7.ius.noarch.rpm rpm -Uvh --reinstall https://repo.ius.io/7/x86_64/packages/m/mod_php74-7.4.30-1.el7.ius.x86_64.rpm 

Then installed PHP modules:

rpm -Uvh --reinstall http://mirror.centos.org/centos/7/os/x86_64/Packages/libxslt-1.1.28-6.el7.x86_64.rpm rpm -Uvh --reinstall http://mirror.centos.org/centos/7/updates/x86_64/Packages/libxml2-2.9.1-6.el7_9.6.x86_64.rpm rpm -Uvh --reinstall http://mirror.centos.org/centos/7/updates/x86_64/Packages/net-snmp-5.7.2-49.el7_9.2.x86_64.rpm rpm -Uvh --reinstall http://mirror.centos.org/centos/7/updates/x86_64/Packages/net-snmp-libs-5.7.2-49.el7_9.2.x86_64.rpm rpm -Uvh --reinstall http://www6.atomicorp.com/channels/atomic/centos/7/x86_64/RPMS/oniguruma-6.8.2-1.el7.x86_64.rpm rpm -Uvh --reinstall https://repo.ius.io/7/x86_64/packages/p/php74-ldap-7.4.30-1.el7.ius.x86_64.rpm rpm -Uvh --reinstall https://repo.ius.io/7/x86_64/packages/p/php74-mbstring-7.4.30-1.el7.ius.x86_64.rpm rpm -Uvh --reinstall https://repo.ius.io/7/x86_64/packages/p/php74-mysqlnd-7.4.30-1.el7.ius.x86_64.rpm rpm -Uvh --reinstall https://repo.ius.io/7/x86_64/packages/p/php74-pdo-7.4.30-1.el7.ius.x86_64.rpm rpm -Uvh --reinstall https://repo.ius.io/7/x86_64/packages/p/php74-snmp-7.4.30-1.el7.ius.x86_64.rpm rpm -Uvh --reinstall https://repo.ius.io/7/x86_64/packages/p/php74-soap-7.4.30-1.el7.ius.x86_64.rpm rpm -Uvh --reinstall https://repo.ius.io/7/x86_64/packages/p/php74-xml-7.4.30-1.el7.ius.x86_64.rpm rpm -Uvh --reinstall http://mirror.centos.org/centos/7/os/x86_64/Packages/perl-Data-Dumper-2.145-3.el7.x86_64.rpm rpm -Uvh --reinstall http://mirror.centos.org/centos/7/updates/x86_64/Packages/net-snmp-agent-libs-5.7.2-49.el7_9.2.x86_64.rpm rpm -Uvh --reinstall http://mirror.centos.org/centos/7/os/x86_64/Packages/lm_sensors-libs-3.4.0-8.20160601gitf9185e5.el7.x86_64.rpm # required by Net-snmp 

I installed Perl and Mysql8 and Unix lsof command. I can provide their details too but they are not relevant to this question.


Allowed the http and https through firewall:

firewall-cmd --zone=public --add-port=80/tcp --permanent firewall-cmd --zone=public --add-port=443/tcp --permanent firewall-cmd --reload 

In the /etc/httpd/conf/httpd.conf,

The modules are

LoadModule authn_file_module modules/mod_authn_file.so LoadModule authn_dbm_module modules/mod_authn_dbm.so LoadModule authn_anon_module modules/mod_authn_anon.so LoadModule authn_dbd_module modules/mod_authn_dbd.so LoadModule authn_socache_module modules/mod_authn_socache.so LoadModule authn_core_module modules/mod_authn_core.so LoadModule authz_host_module modules/mod_authz_host.so LoadModule authz_groupfile_module modules/mod_authz_groupfile.so LoadModule authz_user_module modules/mod_authz_user.so LoadModule authz_dbm_module modules/mod_authz_dbm.so LoadModule authz_owner_module modules/mod_authz_owner.so LoadModule authz_dbd_module modules/mod_authz_dbd.so LoadModule authz_core_module modules/mod_authz_core.so LoadModule authnz_ldap_module modules/mod_authnz_ldap.so LoadModule access_compat_module modules/mod_access_compat.so LoadModule auth_basic_module modules/mod_auth_basic.so LoadModule auth_form_module modules/mod_auth_form.so LoadModule auth_digest_module modules/mod_auth_digest.so LoadModule allowmethods_module modules/mod_allowmethods.so #LoadModule file_cache_module modules/mod_file_cache.so LoadModule cache_module modules/mod_cache.so LoadModule cache_disk_module modules/mod_cache_disk.so LoadModule socache_shmcb_module modules/mod_socache_shmcb.so LoadModule socache_dbm_module modules/mod_socache_dbm.so LoadModule socache_memcache_module modules/mod_socache_memcache.so LoadModule dbd_module modules/mod_dbd.so #LoadModule bucketeer_module modules/mod_bucketeer.so LoadModule dumpio_module modules/mod_dumpio.so LoadModule echo_module modules/mod_echo.so #LoadModule case_filter_module modules/mod_case_filter.so #LoadModule case_filter_in_module modules/mod_case_filter_in.so LoadModule buffer_module modules/mod_buffer.so LoadModule ratelimit_module modules/mod_ratelimit.so LoadModule reqtimeout_module modules/mod_reqtimeout.so LoadModule ext_filter_module modules/mod_ext_filter.so LoadModule request_module modules/mod_request.so LoadModule include_module modules/mod_include.so LoadModule filter_module modules/mod_filter.so LoadModule substitute_module modules/mod_substitute.so LoadModule sed_module modules/mod_sed.so LoadModule charset_lite_module modules/mod_charset_lite.so LoadModule deflate_module modules/mod_deflate.so LoadModule mime_module modules/mod_mime.so LoadModule mpm_prefork_module modules/mod_mpm_prefork.so LoadModule ldap_module modules/mod_ldap.so LoadModule log_config_module modules/mod_log_config.so LoadModule log_debug_module modules/mod_log_debug.so LoadModule logio_module modules/mod_logio.so LoadModule env_module modules/mod_env.so LoadModule mime_magic_module modules/mod_mime_magic.so #LoadModule cern_meta_module modules/mod_cern_meta.so LoadModule expires_module modules/mod_expires.so LoadModule headers_module modules/mod_headers.so LoadModule usertrack_module modules/mod_usertrack.so LoadModule unique_id_module modules/mod_unique_id.so LoadModule setenvif_module modules/mod_setenvif.so LoadModule version_module modules/mod_version.so LoadModule remoteip_module modules/mod_remoteip.so LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_connect_module modules/mod_proxy_connect.so LoadModule proxy_ftp_module modules/mod_proxy_ftp.so LoadModule proxy_http_module modules/mod_proxy_http.so LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so LoadModule proxy_scgi_module modules/mod_proxy_scgi.so LoadModule proxy_ajp_module modules/mod_proxy_ajp.so LoadModule proxy_balancer_module modules/mod_proxy_balancer.so LoadModule proxy_express_module modules/mod_proxy_express.so LoadModule session_module modules/mod_session.so LoadModule session_cookie_module modules/mod_session_cookie.so LoadModule session_dbd_module modules/mod_session_dbd.so LoadModule slotmem_shm_module modules/mod_slotmem_shm.so LoadModule ssl_module modules/mod_ssl.so LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so LoadModule lbmethod_bytraffic_module modules/mod_lbmethod_bytraffic.so LoadModule lbmethod_bybusyness_module modules/mod_lbmethod_bybusyness.so #LoadModule lbmethod_heartbeat_module modules/mod_lbmethod_heartbeat.so LoadModule unixd_module modules/mod_unixd.so LoadModule dav_module modules/mod_dav.so LoadModule status_module modules/mod_status.so LoadModule autoindex_module modules/mod_autoindex.so LoadModule info_module modules/mod_info.so LoadModule suexec_module modules/mod_suexec.so LoadModule cgi_module modules/mod_cgi.so LoadModule cgid_module modules/mod_cgid.so LoadModule dav_fs_module modules/mod_dav_fs.so LoadModule vhost_alias_module modules/mod_vhost_alias.so LoadModule negotiation_module modules/mod_negotiation.so LoadModule dir_module modules/mod_dir.so LoadModule actions_module modules/mod_actions.so LoadModule speling_module modules/mod_speling.so LoadModule userdir_module modules/mod_userdir.so LoadModule alias_module modules/mod_alias.so LoadModule rewrite_module modules/mod_rewrite.so LoadModule systemd_module modules/mod_systemd.so LoadModule php7_module modules/libphp7.so 

additional relevant parts:

Listen 80 <IfModule php7_module> AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps </IfModule> <IfModule unixd_module> User nobody Group nobody </IfModule> <Directory /> AllowOverride none Require all denied </Directory> DocumentRoot "/my/webpages" <Directory "/my/webpages"> Options Indexes FollowSymLinks ExecCGI Includes AllowOverride All Require all granted </Directory> <IfModule dir_module> DirectoryIndex index.html index.html.var index.php index.php3 index.php4 </IfModule> <Files ".ht*"> Require all denied </Files> <IfModule mime_module> TypesConfig /etc/mime.types AddType application/x-compress .Z AddType application/x-gzip .gz .tgz AddHandler cgi-script .cgi .pl AddType text/html .shtml AddOutputFilter INCLUDES .shtml </IfModule> Include /etc/httpd/extra/httpd-vhosts.conf <IfModule ssl_module> Listen 443 <IfDefine SSL> Include /etc/httpd/extra/httpd-ssl.conf </IfDefine> </IfModule> <IfModule ssl_module> Include /etc/httpd/extra/httpd-ssl.conf SSLRandomSeed startup builtin SSLRandomSeed connect builtin </IfModule> TraceEnable Off ServerTokens Prod ServerSignature Off <IfModule mod_headers.c> Header unset X-Powered-By </IfModule> 

And /etc/httpd/extra/httpd-ssl.conf:

AddType application/x-x509-ca-cert .crt AddType application/x-pkcs7-crl .crl SSLPassPhraseDialog builtin SSLSessionCache "shmcb:/run/httpd/sslcache(512000)" SSLSessionCacheTimeout 300 <VirtualHost _default_:443> DocumentRot "/my/webpages" ServerName localhost:443 ServerAdmin [email protected] ErrorLog "logs/ssl_error_log" TransferLog "logs/access_log" SSLEngine on SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL SSLCertificateFile "/etc/httpd/conf/ssl/my.crt" SSLCertificateKeyFile "/etc/httpd/conf/ssl/my.key" <FilesMatch "\.(cgi|shtml|phtml|php)$"> SSLOptions +StdEnvVars </FilesMatch> <FilesMatch "\.php$"> SetHandler application/x-httpd-php </FilesMatch> <Directory "/var/www/cgi-bin"> SSLOptions +StdEnvVars </Directory> BrowserMatch "MSIE [2-5]" \ nokeepalive ssl-unclean-shutdown \ downgrade-1.0 force-response-1.0 CustomLog "logs/ssl_request_log" \ "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b" </VirtualHost> 

Restarting the services:

systemctl restart httpd systemctl restart php-fpm 

feedback

systemctl status httpd systemctl status php-fpm 

both show as active (running).


I also resolved a forbidden 404 error when loading

https://192.168.1.133/install.php 

by these commands:

chcon --user system_u --type httpd_sys_content_t -Rv /my/webpages/ 

Notes: I am not sure what is the relationship between php and php-cli and php-fpm. I only found packages related to php-fpm from IUS and for PHP 7.4 .


Now, loading the

https://192.168.1.133/install.php 

gives me raw PHP. I cannot test it with http. Please don't ask.


Extra information:

php-fpm -v PHP 7.4.30 .... 

php-fpm -v

httpd -v .... Apache/2.4.54 (IUS) ... 

httpd -v

ls /etc/init.d functions jexec lampp netconsole network README 
httpd -M | grep php php7_module (shared) 
1
  • even any hint is welcome. Commented Sep 5, 2022 at 3:35

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.