SetHandler directive failing in VirtualHost but OK in main config - php

The setup is CentOS 7, Apache 2.4.6, php-fpm 5.6 and 7.3 (via remi repo).
I recently converted my default phpmod setup to php-fpm and got PHP 5.4.16 working just fine. Now I'm trying to enable PHP 7.3 as an option per Virtual Host. I got php73-php-fpm installed and running then looked at the Apache side.
My /etc/httpd/conf.d/php.conf includes the following directive:
<FilesMatch \.php$>
# SetHandler application/x-httpd-php
SetHandler "proxy:fcgi://127.0.0.1:9000"
</FilesMatch>
That works fine for all hosts. Then I added this <FilesMatch> directive inside one Virtual Host .conf file:
<VirtualHost *:80>
ServerName www.sittingduck.co.nz
ServerAlias sittingduck.co.nz
DocumentRoot /var/www/sittingduck.co.nz/public_html
ErrorLog /var/log/httpd/sittingduck.co.nz.error.log
CustomLog /var/log/httpd/sittingduck.co.nz.requests.log combined
<FilesMatch \.php$>
SetHandler "proxy:fcgi://127.0.0.1:9073"
</FilesMatch>
</VirtualHost>
When I restart the httpd server, the following shows up in the ErrorLog specified above.
[proxy:error] [pid 17061] (111)Connection refused: AH00957: FCGI: attempt to connect to 127.0.0.1:9073 (*) failed
[proxy_fcgi:error] [pid 17061] [client 54.36.148.97:33788] AH01079: failed to make connection to backend: 127.0.0.1
After verifying that both php-fpm servers were indeed running...
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 16794/php-fpm: mast
tcp 0 0 127.0.0.1:9073 0.0.0.0:* LISTEN 17510/php-fpm: mast
...I next tried switching over the main php.conf to the 9073 port. When I do that, all sites work and I can confirm (using a phpinfo page on the site above) that I am running on PHP 7.3.
What am I missing here? The Virtual Host configs are definitely loaded after php.conf, as the error would suggest, and the fpm is definitely in working order, and the port clearly is accessible.
I feel like there's some rule or caveat to the way I have the directives defined. Any help would be appreciated.

The problem was http versus https. My configuration file was defining *:80 but I was unthinkingly viewing the https version of the test page. The *:443 Virtual Host was in a separate configuration file that had been added after installation by the certbot tool. A manual edit of this extra file resolved the problem.
I'm still not quite sure about why the errors in the log at the start and then not later, but possibly this was due to specific pages being requested over http and/or https at different times.

Related

mautic throws error php error during installation on aws ubuntu

mautic throws amazing error during installation :
The site is currently offline due to encountering an error. If the problem persists, please contact the system administrator.
so i went into server log which shows :
PHP Warning: include(): Failed opening '/var/www/myfolder/var/cache/prod/middlewares.cache.php' for inclusion (include_path='.:/usr/share/php') in /var/www/myfolder/app/middlewares/MiddlewareBuilder.php on line 82PHP message: PHP Warning - Invalid argument supplied for foreach() - in file /var/www/mauticwp/app/middlewares/MiddlewareBuilder.php - at line 84PHP message: PHP Warning: Invalid argument supplied for foreach() in /var/www/mauticwp/app/middlewares/MiddlewareBuilder.php on line 84PHP message: RuntimeException: Unable to create the "cache" directory (/var/www/myfolder/var/cache/prod). - in file /var/www/myfolder/vendor/symfony/http-kernel/Kernel.php - at line 765'
#NameVirtualHost *:8000
<VirtualHost *:8000>
ServerAdmin webmaster#localhost
ServerName somesubdomain.mydomains.com
ServerAlias www.somesubdomain.mydomains.com
DocumentRoot /var/www/some_directory
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<IfModule mpm_itk_module>
AssignUserId mauticadmin www-data
</IfModule>
<IfModule mod_fastcgi.c>
AddHandler php7.4-fcgi .php
Action php7.4-fcgi /php7.4-fcgi virtual
Alias /php7.4-fcgi /usr/lib/cgi-bin/php7.4-fcgi-somesubdomain.mydomains.com
FastCgiExternalServer /usr/lib/cgi-bin/php7.4-fcgi-test.com -socket /var/run/php/php7.4-fpm-mautic.ndedges.com.sock -pass-header Authorization
</IfModule>
<Directory /var/www/some_directory>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
<FilesMatch .php$>
# 2.4.10+ can proxy to unix socket
SetHandler "proxy:unix:/var/run/php/php7.4-fpm.sock|fcgi://localhost"
</FilesMatch>
</VirtualHost>
within fpm/pool.d/www.mautic.conf. i added
php_admin_value[disable_functions] = exec,passthru,shell_exec,system
php_admin_flag[allow_url_fopen] = off
as I have multiple PHP in the same server. I have Cloudflare configured within WordPress and redirects to HTTPS. but i am unable to use ip and port to use it.
I am completely clueless about what could be the reason.
thx
Most of the time it is Cache and Permission related Issue, In my opinion It has nothing to do with Apache configuration.
Use ps aux to identify which user owns the apache process,
Mostly it is www-data,
Make sure to chown on all directories and sub directories to change ownership to www-data.
Make sure files and directories have proper permissions for www-data, Mautic needs write access to Media, var/cache and var/logs directories.
https://tutorialsjoint.com/install-mautic/ in this tutorial checkout the section "Setting rights and permissions for Mautic Installation".
It'll work the same weather it is nginx or apache as this problem seems to be linux related only.
i also find some error
[mpm_prefork:notice] [pid 1440453] AH00163: Apache/2.4.41 (Ubuntu) mod_fcgid/2.3.9 mpm-itk/2.4.7-04 OpenSSL/1.1.1f configured -- resuming normal operations
<FilesMatch ".php$"> # Apache 2.4.10+ can proxy to unix socket
SetHandler "proxy:unix:/var/run/php/php7.4-fpm.sock|fcgi://localhost/"
this one did the job. i removed that fpm configuration but it works like a charm. actually, the same settings did not work for him but it worked for me.
ref: https://askubuntu.com/questions/1317077/apache-sethandler-not-working-with-multiple-php-version
maybe due to the apache2 version. but it has a different problem now i can access it through elastic ip and non SSL port but not with the A record.
now mautic is set with SES but i need to set a bounce endpoint with sns topic. and set a cronjob as www-data.
I was able to access with the IP not using the SSL of Cloudflare proxied A record because it doesn't support other than these ports to trust support.cloudflare.com/hc/en-us/articles/… Cloudflare only accept these ports nothing else. After changing those it was immediately turned into grey and secured. –
https://community.cloudflare.com/t/subdomains-are-not-getting-redirected-to-themselves/279745

test.php is returning page not found

It's my first webpage and everything was ok until I had to set up server and install PHP to star coding the back end part.
I installed MySQL 1.4, Visual Studio 2015, VC14, Apache 2.4 and PHP 7.1.
MySQL is running as well as Apache. I was able to open localhost:8080 with the message "It works" but when I try localhost:8080/test.php it opens a 404 page not found.
The error log in Apache folder says:
[php7:error] [pid 3276:tid 956] [client ::1:65240] script 'C:/Apache24/htdocs/test.php' not found or unable to stat
The test.php file is on Apache24/htdocs.
I've already tried so many options, installed and deinstalled versions of PHP, Visual Studio, and nothing. Thank you for helping me.
Here is the httpd file which I edited:
I added those 4 line at the beginning:
AddHandler application/x-httpd-php .php AddType
application/x-httpd-php .php .html LoadModule php7_module
"c:/php7/php7apache2_4.dll" PHPIniDir "c:/php7"
Definde the SeverRoot:
Define SRVROOT "c:/Apache24" ServerRoot "c:/Apache24"
Changed the Listen port
Listen 8080
List item
Changed the ServerName localhost: ServerName localhost:8080
DocumentRoot
DocumentRoot "c:/Apache24/htdocs"
"c:/Apache24/htdocs">
put your test.php at folder XAMPP/htdocs. XAMMP Panel, turn on Apache and MySQL. Then open your browser and type localhost/test.php

Apache 2.4 / php-fpm 7.1 on OSX Mac. php-fpm ignores all requests, logs nothing

php-fpm 7.1 seems to have a very poorly written version for OSX because I am getting problems that I never seen on Linux or on Windows.
First of all it does not have any logging. If it fails to start it does not report any errors. I have error log path set but it does not use it.
Secondly even if it starts and I can see the working threads then it still does solid nothing. It does not respond to apache requests and logs nothing into access_logs
php-fpm 70353 stan 7u IPv4 0x86d5d0a23f80531f 0t0 TCP 127.0.0.1:9000 (LISTEN)
Httpd config is below
<Proxy "fcgi://127.0.0.1:9000/" timeout=300>
</Proxy>
<FilesMatch \.php$>
SetHandler "proxy:fcgi://127.0.0.1/:9000"
</FilesMatch>
php-fpm config
listen = 127.0.0.1:9000
php_flag[display_errors] = on
php_admin_value[error_log] = /www-logs/fpm-php.www.log
php_admin_flag[log_errors] = on
Anyone had any luck making it works ?
Find ANOTHER configuration file where path to log defined another time. And this another config file apparently took precedence over www.conf that is inside php-fpm.d folder
/usr/local/etc/php/7.1/php-fpm.conf
This file has property
error_log
As for socket that I changed to unix socket. Was not able to figure out why it does not listen to port 9000. Nothing in the logs for that. So the bellow solution works
<IfDefine USE_PHP_FPM>
<Proxy "unix:/var/run/php/php7.0-fpm.sock|fcgi://www-fpm" timeout=300>
</Proxy>
<FilesMatch \.php$>
SetHandler "proxy:fcgi://www-fpm/"
</FilesMatch>
</IfDefine>
And php-fpm.d/www.conf
;listen = 127.0.0.1:9000
listen=/var/run/php/php7.0-fpm.sock

Apache 2.4 segmentation fault when accessing certain localhost Symfony 2 PHP files

I've run into a really odd problem. I have a new Linux Mint 17 install on my local machines, with Apache 2 and PHP 5.6 obtained through Ondrej Sury's PPA. I have cloned a Symfony 2 project to my system from GitHub.
After setting up the project (installing vendors through composer, giving read/write permissions to the cache and logs, etc.), I ran localhost/diva/web/config.php in the browser to ensure that my system was ready to go. It ran fine and gave me the green light. When attempting to look at the home page at localhost/diva/web/app_dev.php/ it gave me a 'The connection was reset' error. Very odd. app.php/ produced the same.
Looking at the server logs, I see a series of segmentation faults along the lines of:
[Thu Oct 30 18:15:10.291111 2014] [core:notice] [pid 1557] AH00052: child pid 2974 exit signal Segmentation fault (11)
I have moved the document root, from what was (I believe... it's been a while) /var/public/html to /home/kevin/www for my own ease of use. I did that with the following modifications:
/etc/apache2/sites-available/000-default.conf:
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster#localhost
DocumentRoot /home/kevin/www
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
and in /etc/apache2/apache2.conf:
<Directory /home/kevin/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
/etc/hosts simply has:
127.0.0.1 localhost
127.0.1.1 Shevat
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
I'm a newbie when it comes to setting up Apache. I've successfully moved my document root in older versions of both Apache and Mint, but this is the first time something like this has happened. I can't tell if I've messed something up with my configuration changes.
And, just to be perfectly clear, other PHP files work fine when accessing them through the browser. I can access my own test files at various nested directory depths within ~/www/*, and even Symfony's config.php works as expected. It's only when I attempt to access those two specific Symfony files - app_dev.php and app.php that the problem occurs.
What's even more strange is that the problem persists across two computers. It's happening on both my desktop and my Surface Pro 3. They use the same essential VirtualBox environment, but have been installed separately. They're not cloned environments.
I'm not sure where to go at this point.
Try
php -S localhost:8000
as a server, for me it works fine
Solved by rolling back to the versions of Apache and PHP that are available to Linux Mint by default (Apache 2.4.7 and PHP 5.4.8).

VirtualHost is not working under Apache 2.4.6 on CentOS 7

I'm trying to setup some VH in Apache 2.4.6 on CentOS 7 but without success since it's not working. This is what I've tried til now:
Since in /etc/httpd/conf/httpd.conf is this line Include conf.modules.d/*.conf then I create a file under /etc/httpd/conf.d/vhost.conf and place this inside it:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName webserver
ServerAlias localhost devserver development
DocumentRoot /var/www/html
</VirtualHost>
Reload/Restart Apache service (tried both):
service httpd reload|restart
At Windows side edit the file C:\Windows\system32\drivers\etc\hosts and add this line:
192.168.3.131 webserver localhost devserver development # this is the IP of Apache Server
Open the browser and tried: http://webserver, http://devserver and both goes to default Apache page so VH is not working.
Place a file under /var/www/html/index.php with this lines <?php phpinfo(); ?> just to know which modules is Apache loading, this is the result:
core mod_so http_core mod_access_compat mod_actions mod_alias mod_allowmethods mod_auth_basic mod_auth_digest
mod_authn_anon mod_authn_core mod_authn_dbd mod_authn_dbm mod_authn_file mod_authn_socache mod_authz_core
mod_authz_dbd mod_authz_dbm mod_authz_groupfile mod_authz_host mod_authz_owner mod_authz_user mod_autoindex
mod_cache mod_cache_disk mod_data mod_dbd mod_deflate mod_dir mod_dumpio mod_echo mod_env mod_expires mod_ext_filter
mod_filter mod_headers mod_include mod_info mod_log_config mod_logio mod_mime_magic mod_mime mod_negotiation
mod_remoteip mod_reqtimeout mod_rewrite mod_setenvif mod_slotmem_plain mod_slotmem_shm mod_socache_dbm
mod_socache_memcache mod_socache_shmcb mod_status mod_substitute mod_suexec mod_unique_id mod_unixd mod_userdir
mod_version mod_vhost_alias mod_dav mod_dav_fs mod_dav_lock mod_lua prefork mod_proxy mod_lbmethod_bybusyness
mod_lbmethod_byrequests mod_lbmethod_bytraffic mod_lbmethod_heartbeat mod_proxy_ajp mod_proxy_balancer mod_proxy_connect
mod_proxy_express mod_proxy_fcgi mod_proxy_fdpass mod_proxy_ftp mod_proxy_http mod_proxy_scgi mod_systemd mod_cgi mod_php5
And apparently mod_vhost is loaded but is not working, did I miss something? Any help or advice around this? Maybe I forgot something but I read Apache docs and doesn't found something helpful
Update: test1
I made some changes to VH definition and now this is what I have:
<VirtualHost *:80>
DocumentRoot /var/www/html
ServerName webserver
#ServerAlias localhost devserver development
<Directory "/var/www/html">
Options FollowSymLinks Includes ExecCGI
AllowOverride All
Allow from all
#Require local
#Require 192.168.3.0/16
#Require 192.168.1.0/16
</Directory>
</VirtualHost>
But I'm getting a 403 Forbidden
Forbidden
You don't have permission to access /index.php on this server.
What is failing here?
To elaborate on jap1968's post, CentOS 7 comes with SELinux's pain in the butt level set to enforcing. This causes all kinds of confusion when perfectly normal service configuration silently fail (Apache).
To disable SELinux you'll need to:
0) [optional] Crack open a shell and become root... or enjoy a shiny new, super fun, configuring sudo to let you do "root stuffs" project. Probably.
su -l
1) Get the current status of SELinux. Run sestatus:
sestatus
2) If SELinux is causing hair loss and premature aging you'll get something like this:
SELinux status: enabled
SELinuxfs mount: /sys/fs/selinux
SELinux root directory: /etc/selinux
Loaded policy name: targeted
Current mode: enforcing
Mode from config file: enforcing
Policy MLS status: enabled
Policy deny_unknown status: allowed
Max kernel policy version: 28
3) Edit the /etc/selinux/config file. Change SELINUX=enforcing to SELINUX=permissive. Doing this will set you up for endless joy next time you reboot. You'll end up with something like this:
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
# SELINUX=enforcing
# ===> VOODOO HERE <===
SELINUX=permissive
# ===> END VOODOO <===
#
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
4) Disable SELinux. You can reboot at this point but it's easier to tell SELinux to take time off from tormenting you. Run setenforce to reset SELinux's enforcement level to match the /etc/selinux/config file:
setenforce 0
5) Check sestatus again:
sestatus
If everything went as expected sestatus will return something like this:
SELinux status: enabled
SELinuxfs mount: /sys/fs/selinux
SELinux root directory: /etc/selinux
Loaded policy name: targeted
Current mode: permissive
Mode from config file: permissive
Policy MLS status: enabled
Policy deny_unknown status: allowed
Max kernel policy version: 28
6) Restart Apache. If your vhost's domain name is resolving to the server you're working on you'll see your shiny new virtual host:
# Restart apache:
systemctl restart httpd.service
# Be lazy by checking your virtual host from the command line:
curl www.example.com/new-file-that-only-exists-in-your-new-vhost.txt
6.5) Stop reading here. Or don't. I'm a message board post, not your Mom.
Everything below is beyond the scope of the original question and only included because you really should be running with SELinux enabled.
7) Work towards re-enabling selinux. Start by watching the selinux logs to see some awesome alphabet soup:
tail -f /var/log/audit/audit.log
8) Be amazed at the depth of features, crazy number of poorly named utilities, and ugly UX mess that constitutes SELinux. You should probably put on your big boy pants and drink a whole pot of coffee before you dive in. Here's some Info:
CentoOS HowTo: https://wiki.centos.org/HowTos/SELinux
Project: http://selinuxproject.org/page/Main_Page
A couple of thing that may be causing you problems :-
NameVirtualHost *:80
Is no longer a valid syntax for Apache 2.4.x you should remove it completely.
On the Windows side once you have changed the HOSTS file, you need to reload the DNS Client service, so either reboot or better still, launch a command window using "Run as Administrator" and do this :-
net stop dnscache
net start dnscache
Lastly, within your virtual hosts definition, it will help to tell apache from where it is allowed to accept connections to this Virtual Host like so :-
<VirtualHost *:80>
ServerName webserver
ServerAlias localhost devserver development
DocumentRoot /var/www/html
<Directory "/var/www/html">
AllowOverride All
Require local
Require ip 192.168.3
</Directory>
</VirtualHost>
This will allow access from the machine running apache Require local and from any ip address on the local network Require ip 192.168.3
Also I am not sure where Apache on unix puts its default document root but it might be an idea to differentiate your 3 domain names to different directories like so
<VirtualHost *:80>
ServerName localhost
ServerAlias localhost
DocumentRoot /var/www/html
<Directory "/var/www/html">
AllowOverride All
Require local
Require ip 192.168.3
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName webserver
ServerAlias webserver
DocumentRoot /var/www/html/webserver
<Directory "/var/www/html/webserver">
AllowOverride All
Require local
Require ip 192.168.3
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName development
ServerAlias development
DocumentRoot /var/www/html/development
<Directory "/var/www/html/development">
AllowOverride All
Require local
Require ip 192.168.3
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName devserver
ServerAlias devserver
DocumentRoot /var/www/html/devserver
<Directory "/var/www/html/devserver">
AllowOverride All
Require local
Require ip 192.168.3
</Directory>
</VirtualHost>
Then put a simple html file in each directory saying 'Hello from Servername' and change servername in each file so you know you have got to the correct server.
RE: Update test1.php
Allow from all
Is not valid Apache 2.4 syntax either, unless you have loaded LoadModule access_compat_module modules/mod_access_compat.so
Even then it should be
Order Allow,Deny
Allow from all
So USE Apache 2.4 syntax
Require all granted
If you want to take the lazy route and allow access from the universe.
Be careful also with SELinux. The default configuration will prevent your virtual hosts directories from being accessed by httpd. You will need to set the appropriate context:
# chcon -R -u system_u -r object_r -t httpd_sys_content_t <DocumentRoot>
Another option is just to disable SELinux.

Categories