Apache PHP-FPM Centos AH01071 - php

I have a CentOS server and I am trying to configure apache with php-fpm. I have a virtualhost in a conf file. When checking the status of http and php-fpm all is fine but when trying to access the website in the browser,
I have errors based on the filesmatch part of my conf file :
<FilesMatch \.php$>
SetHandler "proxy:unix:/var/run/php-fpm.sock|fcgi://localhost/path/to/docroot"
</FilesMatch>
=> [proxy_fcgi:error] AH01071: Got error 'Primary script unknown'
In the browser : File not found
<FilesMatch \.php$>
SetHandler "proxy:unix:/var/run/php-fpm.sock|fcgi://localhost/"
</FilesMatch>
=> [proxy_fcgi:error] AH01071: Got error 'Unable to open primary script:
//path/to/docroot/index.php (No such file or directory)'
In the browser: No input file specified
The /path/to/docroot also has apache permission, what could be the issue? any help is appreciated.
Thanks

The problem was the open_basedir and docroot settings in the php.ini. I modified the www.conf file inside php-fpm.d folder to add the two settings :
php_admin_value['open_basedir'] = /path/to/base_dir
php_admin_value['doc_root'] = /path/to/doc_root
and then everything worked.
Thanks!

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

SetHandler directive failing in VirtualHost but OK in main config

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.

Netbeans lamp php interpereter not working

I am following this netbean guide https://netbeans.org/kb/docs/php/configure-php-environment-ubuntu.html#createDocumentRootLocation
But I am stuck at creating the virtual host. I try to do as in the tutorial but there is no <Directory> tags in the "000-default.conf" file. I kept going and ignored that.
I did as in the tutorial and put it in my /home/user/public_html. but now when I run it the php code is not interpreted
If I a2ensite the default I can access virtual host set at /var/www/html and that php is interpreted
There are no errors the php is just not being interpreted, what am I doing wrong here.
Im using:
Ubuntu 18.10 LTS
PHP 7.2.10-0ubuntu1 (cli)
Apache/2.4.34
Edit:
My "TestPhp.conf" file:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /home/jelly/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Edit 2 and answer:
Turned out to be some lines in my "php7.2.conf" file that had to be commented out as the out-commented lines in that file explains. as running PHP scripts in user directories is disabled by default.
what is your test script like? if you start with <? try <?php instead.
Also check php.ini for expose_php = false (may hide php form the headers)
If the error persists, include your config and test script, along with any errors in http.log
You need to find a config file which enables php
I only have a Ubuntu, and the files in my installation may vary compared to yours:
Enable PHP engine [php.load]
This is the part that loads the PHP interpreter, and allows you to use php scripts
LoadModule php5_module /usr/lib/apache2/modules/libphp5.so
Enable .php file directed to php [php5.conf]
This is the part tells apache to send *.php (and in this case some other extensions like *.phtml) to the php interpreter
<FilesMatch ".+\.ph(p[345]?|t|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch ".+\.phps$">
SetHandler application/x-httpd-php-source
# Deny access to raw php sources by default
# To re-enable it's recommended to enable access to the files
# only in specific virtual host or directory
Require all denied
</FilesMatch>
# Deny access to files without filename (e.g. '.php')
<FilesMatch "^\.ph(p[345]?|t|tml|ps)$">
Require all denied
</FilesMatch>
EDIT I noticed that you were on UBUNTU as well
use sudo a2enmod and select php in the list
EDIT 2
Note that if you are following a general Guide and not a UBUNTU specific one, you may encounter several issues since the UBUNTU apache config is spread out in several files, as opposed to one big file, which is what you may encounter in other distros

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

Failed Opening required error. required once

I am getting the following error from my website in the error logs:
[Wed Jul 02 07:13:58 2014] [error] [client **.**.**.**]
PHP Fatal error: require_once(): Failed opening required '/var/zpanel/hostdata/
zadmin/core/public_html/loader.php' (include_path='.:/usr/share/pear:/usr/share/php')
in /var/zpanel/hostdata/zadmin/public_html/cmcatering_co_uk/index.php on line 3
In index.php I have the following:
<?php
$code_base = "/var/zpanel/hostdata/zadmin/core";
require_once($code_base . "/public_html/loader.php");
?>
The loader.php file is in the correct place and so I am a bit confused as to why this is happening. I tried putting the core folder in /usr/share/php but this did not fix the problem. Any suggestions?
edit:
I have also just seen this error:
[Wed Jul 02 07:36:58 2014] [error] [client 94.10.110.115] PHP Warning: require_once(/usr/share/php/core/public_html/loader.php): failed to open stream: Operation not permitted in /var/zpanel/hostdata/zadmin/public_html/cmcatering_co_uk/index.php on line 3
httpd.conf:
# ZPanel Apache Include file for CentOS Linux
# Written by Bobby Allen, 15/05/2011
# Set the Zpanel Alias (used for development, sable will eventually use a VHOST)
Alias /zpanel /etc/zpanel/panel
# Setup the directory settings and PHP security flags for the Zpanel application directory.
<Directory /etc/zpanel/panel>
Options FollowSymLinks
AllowOverride All
DirectoryIndex index.php
<IfModule mod_php5.c>
AddType application/x-httpd-php .php
php_flag magic_quotes_gpc Off
php_flag track_vars On
php_flag register_globals Off
php_admin_value upload_tmp_dir /etc/zpanel/temp
</IfModule>
</Directory>
# Disallow web access to directories that don't need it/that we don't want people looking in!
<Directory /etc/zpanel/panel/cnf>
Order Deny,Allow
Deny from All
</Directory>
# Set server tokens (security??)
ServerTokens Maj
# Now we include the generic VHOST configuration file that holds all the ZPanel user hosted vhost data
Include /etc/zpanel/configs/apache/httpd-vhosts.conf
if you read the error message then you well see:
Operation not permitted
Your webserver process has no permissions to access
/usr/share/php/core/public_html/
In many cases webservers are bound to their root.
/var/zpanel/hostdata/
It looks as though this is a permissions issue due to the operation not permitted error. Look at whether your server is giving php access to the given folder in its configuration. Also just for a sanity check, echo out the filename as it is passed to your require_once.
Would be helpful if you posted your apache site config.
<?php
$code_base = "/var/zpanel/hostdata/zadmin/core";
require_once("<?php echo $code_base; ?>/public_html/loader.php");
?>

Categories