How to config apache for php 8 in Centos 7? - php

I'm trying set proper configuration for apache in Centos 7 in below file:
/etc/httpd/conf/httpd.conf
My application is Laravel and it works with php 8.
Also I need a subdomain for second application too which is laravel.
These are my server block:
<VirtualHost IP:80>
SuexecUserGroup "#1000" "#1000"
DocumentRoot /home/example/public
ServerName example.com
<Directory /home/example/public>
Options -Indexes +IncludesNOEXEC +SymLinksIfOwnerMatch +ExecCGI
allow from all
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
Require all granted
AddType application/x-httpd-php .php
AddHandler fcgid-script .php
AddHandler fcgid-script .php5
AddHandler fcgid-script .php7.2
AddHandler fcgid-script .php8.0
FCGIWrapper /home/example/php8.0.fcgi .php
FCGIWrapper /home/example/fcgi-bin/php5.fcgi .php5
FCGIWrapper /home/example/fcgi-bin/php7.2.fcgi .php7.2
FCGIWrapper /home/example/fcgi-bin/php8.0.fcgi .php8.0
</Directory>
ErrorLog /var/log/virtualmin/example.com_error_log
CustomLog /var/log/virtualmin/example.com_access_log combined
ScriptAlias /cgi-bin/ /home/example/cgi-bin/
ScriptAlias /awstats/ /home/example/cgi-bin/
DirectoryIndex index.php index.php4 index.php5 index.htm index.html
<Directory /home/example/cgi-bin>
allow from all
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
Require all granted
</Directory>
RewriteEngine on
RewriteCond %{HTTP_HOST} =webmail.example.com
RewriteRule ^(?!/.well-known)(.*) https://example.com:20000/ [R]
RewriteCond %{HTTP_HOST} =admin.example.com
RewriteRule ^(?!/.well-known)(.*) https://subdomain.example.com:10000/ [R]
RemoveHandler .php
RemoveHandler .php5
RemoveHandler .php7.2
RemoveHandler .php8.0
FcgidMaxRequestLen 1073741824
<Files awstats.pl>
AuthName "example.com statistics"
AuthType Basic
AuthUserFile /home/example/.awstats-htpasswd
require valid-user
</Files>
RedirectMatch ^/(?!.well-known)(.*)$ http://example.com/$1
<FilesMatch \.php$>
SetHandler proxy:fcgi://localhost:8001
</FilesMatch>
</VirtualHost>
<VirtualHost IP:80>
SuexecUserGroup "#1000" "#1000"
DocumentRoot /home/subdomain.example/public
ServerName subdomain.example.com
<Directory /home/subdomain.example/public>
Options -Indexes +IncludesNOEXEC +SymLinksIfOwnerMatch +ExecCGI
allow from all
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
Require all granted
AddType application/x-httpd-php .php
AddHandler fcgid-script .php
AddHandler fcgid-script .php5
AddHandler fcgid-script .php7.2
AddHandler fcgid-script .php8.0
FCGIWrapper /home/example/php8.0.fcgi .php
FCGIWrapper /home/example/fcgi-bin/php5.fcgi .php5
FCGIWrapper /home/example/fcgi-bin/php7.2.fcgi .php7.2
FCGIWrapper /home/example/fcgi-bin/php8.0.fcgi .php8.0
</Directory>
ErrorLog /var/log/virtualmin/example.com_error_log
CustomLog /var/log/virtualmin/example.com_access_log combined
ScriptAlias /cgi-bin/ /home/example/cgi-bin/
ScriptAlias /awstats/ /home/example/cgi-bin/
DirectoryIndex index.php index.php4 index.php5 index.htm index.html
<Directory /home/subdomain.example/cgi-bin>
allow from all
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
Require all granted
</Directory>
RewriteEngine on
RewriteCond %{HTTP_HOST} =webmail.subdomain.example.com
RewriteRule ^(?!/.well-known)(.*) https://subdomain.example.com:20000/ [R]
RewriteCond %{HTTP_HOST} =admin.subdomain.example.com
RewriteRule ^(?!/.well-known)(.*) https://subdomain.example.com:10000/ [R]
RemoveHandler .php
RemoveHandler .php5
RemoveHandler .php7.2
RemoveHandler .php8.0
FcgidMaxRequestLen 1073741824
<Files awstats.pl>
AuthName "example.com statistics"
AuthType Basic
AuthUserFile /home/example/.awstats-htpasswd
require valid-user
</Files>
RedirectMatch ^/(?!.well-known)(.*)$ http://subdomain.example.com/$1
<FilesMatch \.php$>
SetHandler proxy:fcgi://localhost:8001
</FilesMatch>
</VirtualHost>
After changing this file I restarted apache server.
Also I set subdomain in dns manager.
Can anyone help me in this subject. Plus With no subdomain it work fine but subdomain not.

Add this block to all of <VirtualHost> blocks:
AddHandler php-fcgi .php
Action php-fcgi /php-cgi
Alias /php-cgi "/usr/bin/php-cgi -f"

Related

Problem Setting two PHP version on XAMPP on Windows

I am running a XAMPP installation with PHP 5.6 for compatibility reason with my existing projects, but my new project requires PHP 7+.
I'm trying to install PHP 7.4 alongside my existing PHP 5.6 following the guide in this question, but I only end up in a 404 page for that project.
My httpd-xampp.conf looks like this
#
# XAMPP settings
#
<IfModule env_module>
SetEnv MIBDIRS "C:/xampp/php/extras/mibs"
SetEnv MYSQL_HOME "\\xampp\\mysql\\bin"
SetEnv OPENSSL_CONF "C:/xampp/apache/bin/openssl.cnf"
SetEnv PHP_PEAR_SYSCONF_DIR "\\xampp\\php"
SetEnv PHPRC "\\xampp\\php"
SetEnv TMP "\\xampp\\tmp"
</IfModule>
#
# PHP-Module setup
#
LoadFile "C:/xampp/php/php5ts.dll"
LoadFile "C:/xampp/php/libpq.dll"
LoadModule php5_module "C:/xampp/php/php5apache2_4.dll"
<FilesMatch "\.php$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>
#
# PHP-CGI setup
#
#<FilesMatch "\.php$">
# SetHandler application/x-httpd-php-cgi
#</FilesMatch>
#<IfModule actions_module>
# Action application/x-httpd-php-cgi "/php-cgi/php-cgi.exe"
#</IfModule>
<IfModule php5_module>
PHPINIDir "C:/xampp/php"
</IfModule>
<IfModule mime_module>
AddType text/html .php .phps
</IfModule>
ScriptAlias /php-cgi/ "C:/xampp/php/"
<Directory "C:/xampp/php">
AllowOverride None
Options None
Require all denied
<Files "php-cgi.exe">
Require all granted
</Files>
</Directory>
<Directory "C:/xampp/cgi-bin">
<FilesMatch "\.php$">
SetHandler cgi-script
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler None
</FilesMatch>
</Directory>
<Directory "C:/xampp/htdocs/xampp">
<IfModule php5_module>
<Files "status.php">
php_admin_flag safe_mode off
</Files>
</IfModule>
AllowOverride AuthConfig
</Directory>
<IfModule alias_module>
Alias /security "C:/xampp/security/htdocs/"
<Directory "C:/xampp/security/htdocs">
<IfModule php5_module>
<Files "xamppsecurity.php">
php_admin_flag safe_mode off
</Files>
</IfModule>
AllowOverride AuthConfig
Require all granted
</Directory>
Alias /licenses "C:/xampp/licenses/"
<Directory "C:/xampp/licenses">
Options +Indexes
<IfModule autoindex_color_module>
DirectoryIndexTextColor "#000000"
DirectoryIndexBGColor "#f8e8a0"
DirectoryIndexLinkColor "#bb3902"
DirectoryIndexVLinkColor "#bb3902"
DirectoryIndexALinkColor "#bb3902"
</IfModule>
Require all granted
</Directory>
Alias /phpmyadmin "C:/xampp/phpMyAdmin/"
<Directory "C:/xampp/phpMyAdmin">
AllowOverride AuthConfig
Require all granted
</Directory>
Alias /webalizer "C:/xampp/webalizer/"
<Directory "C:/xampp/webalizer">
<IfModule php5_module>
<Files "webalizer.php">
php_admin_flag safe_mode off
</Files>
</IfModule>
AllowOverride AuthConfig
Require all granted
</Directory>
</IfModule>
#
# New XAMPP security concept
#
<LocationMatch "^/(?i:(?:xampp|security|licenses|phpmyadmin|webalizer|server-status|server-info))">
Require local
ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
</LocationMatch>
# Begin multi-php modifications
Listen 8081
ScriptAlias /php-cgi/ "C:/xampp/php7/"
<Directory "C:/xampp/php7">
AllowOverride None
Options None
Require all denied
<Files "php-cgi.exe">
Require all granted
</Files>
</Directory>
<VirtualHost *:8081 "C:/xampp/Telegram"> <--originally was C:/xampp/htdocs/Telegram
# UnsetEnv PHPRC <-- Tried to enable/disable this and the above settings, unsuccessfully
<FilesMatch "\.php$">
SetHandler application/x-httpd-php74-cgi
</FilesMatch>
</VirtualHost>
#End multi-php modifications
I feel there's something in the default settings forcing xampp to run PHP 5.6 and only scripts from the ./htdocs directory, but since I'm quite noob about xampp configuration, I'm asking here what to do.
HERE the result from Postman, trying to connect to the project.
P.S. without the multi-PHP modifications the page loads "correctly" (considering the PHP 7 requisite)

phpMyAdmin does not open no matter what I change in httpd-xampp.conf

I just installed xampp and I wanted to open phpMyAdmin.. However, what I get is
Access forbidden! You don't have permission to access the requested directory. etc (Error 403). I have seen many stackoverflow questions on this error but nothing works.This is my httpd-xampp:
#
# XAMPP settings
#
<IfModule env_module>
SetEnv MIBDIRS "C:/xampp/php/extras/mibs"
SetEnv MYSQL_HOME "\\xampp\\mysql\\bin"
SetEnv OPENSSL_CONF "C:/xampp/apache/bin/openssl.cnf"
SetEnv PHP_PEAR_SYSCONF_DIR "\\xampp\\php"
SetEnv PHPRC "\\xampp\\php"
SetEnv TMP "\\xampp\\tmp"
</IfModule>
#
# PHP-Module setup
#
LoadFile "C:/xampp/php/php7ts.dll"
LoadFile "C:/xampp/php/libpq.dll"
LoadModule php7_module "C:/xampp/php/php7apache2_4.dll"
<FilesMatch "\.php$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>
#
# PHP-CGI setup
#
#<FilesMatch "\.php$">
# SetHandler application/x-httpd-php-cgi
#</FilesMatch>
#<IfModule actions_module>
# Action application/x-httpd-php-cgi "/php-cgi/php-cgi.exe"
#</IfModule>
<IfModule php7_module>
PHPINIDir "C:/xampp/php"
</IfModule>
<IfModule mime_module>
AddType text/html .php .phps
</IfModule>
ScriptAlias /php-cgi/ "C:/xampp/php/"
<Directory "C:/xampp/php">
AllowOverride None
Options None
Require all denied
<Files "php-cgi.exe">
Require all granted
</Files>
</Directory>
<Directory "C:/xampp/cgi-bin">
<FilesMatch "\.php$">
SetHandler cgi-script
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler None
</FilesMatch>
</Directory>
<Directory "C:/xampp/htdocs/xampp">
<IfModule php7_module>
<Files "status.php">
php_admin_flag safe_mode off
</Files>
</IfModule>
AllowOverride AuthConfig
</Directory>
<IfModule alias_module>
Alias /licenses "C:/xampp/licenses/"
<Directory "C:/xampp/licenses">
Options +Indexes
<IfModule autoindex_color_module>
DirectoryIndexTextColor "#000000"
DirectoryIndexBGColor "#f8e8a0"
DirectoryIndexLinkColor "#bb3902"
DirectoryIndexVLinkColor "#bb3902"
DirectoryIndexALinkColor "#bb3902"
</IfModule>
Require local
ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
</Directory>
Alias /phpmyadmin "C:/xampp/phpMyAdmin/"
<Directory "C:/xampp/phpMyAdmin">
AllowOverride AuthConfig
#Require local
Require all granted
ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
</Directory>
Alias /webalizer "C:/xampp/webalizer/"
<Directory "C:/xampp/webalizer">
<IfModule php7_module>
<Files "webalizer.php">
php_admin_flag safe_mode off
</Files>
</IfModule>
AllowOverride AuthConfig
#Require local
ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
</Directory>
</IfModule>
I have set require all granted and allow from all but nothing works. I restart apache on each change but still nothing! All pages in localhost open successfully, but not phpMyAdmin..

phpmyadmin shows php code, but actual application code works fine

I am hosting my application on AWS server. I configured Virtualmin on it and created a new virtual server - mydomain.td.lr, and it created a user - mydomain.
I configured a virtual host for it too from the virtualmin interface.
<VirtualHost *:80>
SuexecUserGroup "#500" "#500"
ServerName mydomain.td.lr
ServerAlias www.mydomain.td.lr
ServerAlias webmail.mydomain.td.lr
DocumentRoot /var/www/public_html/mydomain
ErrorLog /var/log/virtualmin/mydomain.td.lr_error_log
CustomLog /var/log/virtualmin/mydomain.td.lr_access_log combined
ScriptAlias /cgi-bin/ /home/mydomain/cgi-bin/
ScriptAlias /awstats/ /home/mydomain/cgi-bin/
DirectoryIndex index.html index.htm index.php index.php4 index.php5
<Directory /var/www/public_html/mydomain>
Options -Indexes +IncludesNOEXEC +SymLinksIfOwnerMatch +ExecCGI
allow from all
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
Require all granted
AddType application/x-httpd-php .php
AddHandler fcgid-script .php
AddHandler fcgid-script .php5
FCGIWrapper /home/mydomain/fcgi-bin/php5.fcgi .php
FCGIWrapper /home/mydomain/fcgi-bin/php5.fcgi .php5
</Directory>
<Directory /home/mydomain/cgi-bin>
allow from all
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
Require all granted
</Directory>
RewriteEngine on
RewriteCond %{HTTP_HOST} =webmail.mydomain.td.lr
RewriteRule ^(.*) https://mydomain.td.lr:20000/ [R]
RemoveHandler .php
RemoveHandler .php5
php_admin_value engine Off
IPCCommTimeout 31
FcgidMaxRequestLen 1073741824
Alias /dav /home/mydomain/public_html
Alias /pipermail /var/lib/mailman/archives/public
<Location /dav>
DAV on
AuthType Basic
AuthName "mydomain.td.lr"
AuthUserFile /home/mydomain/etc/dav.digest.passwd
Require valid-user
ForceType text/plain
Satisfy All
RemoveHandler .php
RemoveHandler .php5
RewriteEngine off
</Location>
<Files awstats.pl>
AuthName "mydomain.td.lr statistics"
AuthType Basic
AuthUserFile /home/mydomain/.awstats-htpasswd
require valid-user
</Files>
RedirectMatch /cgi-bin/mailman/([^/\.]*)(.cgi)?(.*) https://mydomain.td.lr:10000/virtualmin-mailman/unauthenticated/$1.cgi$3
RedirectMatch /mailman/([^/\.]*)(.cgi)?(.*) https://mydomain.td.lr:10000/virtualmin-mailman/unauthenticated/$1.cgi$3
</VirtualHost>
This got appended to the httpd.conf.
When I open my application at mydomain.td.lr, the application shows up; but when I open phpmhyadmin, I see a php code there.
Also, when I see source code of phpmyadmin page, all the php code is commented out and code inside html which is php is being shown
I reinstalled phpmyadmin on the server, but still no success.
What went wrong with the configuration???
Removing these two lines does the job for me.
RemoveHandler .php
RemoveHandler .php5
Have you made modification in apache.conf which exists in /etc/phpmyadmin folder?
I think you have to also make entry in phpmyadmin apache.conf and make sure that short tag is not commented in php.ini file.
Hope this will help.
In my case it was
php_admin_value engine Off
in httpd.config Virtual host section.
Once disabled,
# php_admin_value engine Off
everything (virtual sites, phpMyAdmin) worked just fine.
Consider security issue, but mod_php could be enabled either in custom or default template > Apache_website under Virtualmin Server Template

New wordpress site forces me to download index.php

I'm setting up a Wordpress site on my VPS and currently when I try to visit the website's root URL I am forced to download the contents of index.php (instead of having the php file be executed).
I suspect the problem may be with my /etc/apache2/sites-enabled/foobar.com.conf:
SuexecUserGroup "#1007" "#1007"
ServerName foobar.com
ServerAlias www.foobar.com
ServerAlias webmail.foobar.com
ServerAlias admin.foobar.com
DocumentRoot /home/foobar/www
ErrorLog /var/log/virtualmin/foobar.com_error_log
CustomLog /var/log/virtualmin/foobar.com_access_log combined
ScriptAlias /cgi-bin/ /home/foobar/cgi-bin/
ScriptAlias /awstats/ /home/foobar/cgi-bin/
AddType application/x-httpd-php .html .htm
DirectoryIndex index.php
<Directory /home/foobar/public_html>
Options -Indexes +IncludesNOEXEC +SymLinksIfOwnerMatch +ExecCGI
allow from all
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
AddHandler fcgid-script .php
AddHandler fcgid-script .php5
FCGIWrapper /home/foobar/fcgi-bin/php5.fcgi .php
FCGIWrapper /home/foobar/fcgi-bin/php5.fcgi .php5
</Directory>
<Directory /home/foobar/cgi-bin>
allow from all
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
</Directory>
<Directory /home/foobar/www>
allow from all
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
</Directory>
RewriteEngine on
RewriteCond %{HTTP_HOST} =webmail.foobar.com
RewriteRule ^(.*) https://foobar.com:20000/ [R]
RewriteCond %{HTTP_HOST} =admin.foobar.com
RewriteRule ^(.*) http://foobar.com:10000/ [R]
RemoveHandler .php
RemoveHandler .php5
php_admin_value engine Off
IPCCommTimeout 31
FcgidMaxRequestLen 1073741824
<Files awstats.pl>
AuthName "michaelarchinal.com statistics"
AuthType Basic
AuthUserFile /home/foobar/.awstats-htpasswd
require valid-user
</Files>
RedirectMatch /cgi-bin/mailman/([^/\.]*)(.cgi)?(.*) http://foobar.com:10000/virtualmin-mailman/unauthenticated/$1.cgi$3
RedirectMatch /mailman/([^/\.]*)(.cgi)?(.*) http://foobar.com:10000/virtualmin-mailman/unauthenticated/$1.cgi$3
Alias /pipermail /var/lib/mailman/archives/public
(Note: The url is not actually www.foobar.com - I've changed it to that for the sake of example)

Disable MOD_PHP in vhosts and activate suphp

I need to desactivate mod_php on a vhost and let it working for other vhosts, I need to disable it in order to activate suphp.
here is the vhost config :
Options +Indexes
ServerName www.native.org
ServerAlias native.org
DocumentRoot /home/user/www/native/current
ServerAdmin info#native.org
UseCanonicalName Off
CustomLog /var/log/apache2/native_access.log combined
ErrorLog /var/log/apache2/native_error.log
<Directory /home/user/www/native/current>
RemoveHandler .php
AllowOverride All
Options FollowSymLinks
Order allow,deny
allow from all
</Directory>
suPHP_Engine on
SuexecUserGroup user native
<IfModule mod_suphp.c>
suPHP_UserGroup user native
AddHandler x-httpd-php .php .php3 .php4 .php5
suPHP_AddHandler x-httpd-php
</IfModule>
NB: mod_php is activated by default for all vhosts
You don't have to remove handlers, types or to turn PHP's engine off.
In your <VirtualHost ...> add the following lines:
<FilesMatch \.php$>
SetHandler None
</FilesMatch>
In this way, you will remove the handler added by /etc/httpd/conf.d/php.conf (or php5.conf, or whatever) which says:
#
# Cause the PHP interpreter to handle files with a .php extension.
#
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
Edit: It's better also to disable PHP's engine according to suphp.conf file:
# Disable php when suphp is used, to avoid having both.
<IfModule mod_php5.c>
php_admin_flag engine off
</IfModule>
Your site will run under suPHP now. (Also, if you have installed phpMyAdmin in /usr/share/phpMyAdmin, it will work under mod_php, which is great.)
At the end, take a look of one of my VirtualHosts configuration:
<VirtualHost 1.2.3.4:80>
ServerName site.com
ServerAlias www.site.com
ServerAdmin admin#site.com
DocumentRoot /home/site/public_html
Options -Indexes
suPHP_Engine on
suPHP_UserGroup site site
suPHP_ConfigPath "/home/site/public_html"
suPHP_AddHandler x-httpd-php
AddHandler x-httpd-php .php .php3 .php4 .php5
# Remove the handler added by php.conf
<FilesMatch \.php$>
SetHandler None
</FilesMatch>
# Disable php when suphp is used, to avoid having both.
<IfModule mod_php5.c>
php_admin_flag engine off
</IfModule>
ErrorLog "|cronolog /home/site/.logs/error_%Y_%m.log"
CustomLog "|cronolog /home/site/.logs/access_%Y_%m.log" combined
</VirtualHost>
Final Note:
If your phpMyAdmin located in /usr/share/phpMyAdmin is not working, add the following lines at the end of your httpd.conf or in your master VirtualHost:
<Directory /usr/share/phpMyAdmin>
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
<IfModule mod_php5.c>
php_admin_flag engine on
</IfModule>
</Directory>
For example:
<VirtualHost 1.2.3.4:80>
ServerAdmin admin#master-site.com
DocumentRoot /var/www/html
Options -Indexes
<Directory /usr/share/phpMyAdmin>
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
<IfModule mod_php5.c>
php_admin_flag engine on
</IfModule>
</Directory>
ErrorLog "|cronolog /var/www/.logs/error_%Y_%m.log"
CustomLog "|cronolog /var/www/.logs/access_%Y_%m.log" combined
</VirtualHost>
You should be able to do
<Directory /home/user/www/native/current>
RemoveHandler .php .phtml .php3 .php5
RemoveType .php .phtml .php3 .php5
php_flag engine off
AllowOverride All
Options FollowSymLinks
Order allow,deny
allow from all
</Directory>

Categories