simultaneously use of php5 and php7 on Fedora 27 - php

I am trying to configure everything in order to run simultaneously php5 and php7 on Fedora 27. I am using Remi's guides from here and here, I am able to switch versions in the command line with module load/unload php71/php56
but on the page where I output phpinfo(); I get php version of 7.1. I have also
running php56-php-fpm.service and php71-php-fpm.service running.
What should I check or where to search? Thank you.
php.conf file:
# Redirect to local php-fpm if mod_php (5 or 7) is not available
<IfModule !mod_php5.c>
<IfModule !mod_php7.c>
# Enable http authorization headers
SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1
<FilesMatch \.php$>
SetHandler "proxy:unix:/run/php-fpm/www.sock|fcgi://localhost"
</FilesMatch>
</IfModule>
</IfModule>
also there are php56-php.conf and php71-php.conf files. As I understand mod_php is serving files instead of php-fpm, is there any method to disable it?

Check all SetHandler Directives in /etc/httpd/conf.d/*conf
Each package comes with its configuration file (php##-php.conf), you may have to disable them to be able to set the proper version per vhost / project / directory, or ensure your configuration files are loaded after provided ones.

Related

Using heroku-fcgi to handle files without a .php extension (Apache)

Overview
I'm trying to host a few legacy PHP apps on Heroku with Apache. They all relied on the following deprecated syntax to parse any unknown file types (without the .php extension) as PHP.
DefaultType application/x-httpd-php
This has been replaced by AddType in Apache 2.4 (Heroku currently uses v2.4.37). Heroku also uses mod_proxy_fcgi to process PHP files via fcgi://heroku-fcgi.
Issue
I have a file foo.test and I want to have it handled by PHP FPM. Taking cues from the docs and the default Apache config provided by Heroku, here's what I've tried:
# .htaccess
<FilesMatch \.test$>
<If "-f %{REQUEST_FILENAME}">
SetHandler proxy:fcgi://heroku-fcgi
</If>
</FilesMatch>
# apache_app.conf (properly loaded via Procfile)
ProxyPassMatch "^/(.*\.test(/.*)?)$" "fcgi://heroku-fcgi/app/$1"
With both of these I get a plain-text 403 Access denied. response from PHP FPM. I'm sure both configs are properly loading and pointing to the FCGI handler because changing the endpoint results in other errors.
My Apache skills are long since rusty and I can't seem to find any good pointers online. The Apache error log is also clean. Any ideas (without the obvious "change all extensions to PHP, you dumbass") would be appreciated!
Fairly obvious solution. PHP FPM has its own configuration with a security.limit_extensions flag. It defaults to .php.
The solution was to unset that value: security.limit_extensions =. This naturally can pose some security threats, but these apps are only going up for static demo.
I was using heroku/heroku-buildpack-php but forked that to update this file. The htaccess FilesMatch should work now but I just ended up placing it into the Apache config file to avoid repetition across the sites I'll be serving.
security.limit_extensions can be customized with a configuration file passed as a Procfile argument.
https://devcenter.heroku.com/articles/custom-php-settings#php-fpm-settings
PHP-FPM settings:
In addition to php_value and php_flag for php.ini specific settings, any pool specific PHP-FPM configuration directives are valid in that configuration file, so you can use it to fine tune PHP-FPM’s behavior.
So you can set up it like the following
Procfile
web: vendor/bin/heroku-php-apache2 -C apache.conf -F fpm_custom.conf web/
apache.conf
<FilesMatch \.test$>
<If "-f %{REQUEST_FILENAME}"> # make sure the file exists so that if not, Apache will show its 404 page and not FPM
SetHandler proxy:fcgi://heroku-fcgi
</If>
</FilesMatch>
fpm_custom.conf
security.limit_extensions = .php .test

How to execute php code in html files (php-fpm and apache 2.4) on centos 7

As we have upgrade OS from centos 6.9 to Centos 7 on server. We have installed "Apache/2.4.6" and "PHP 5.6.36 (fpm-fcgi)" on this server. But we are facing problem to execute "PHP Code" in ".html" files. PHP code working fine in ".php file" but not in ".html files". I have ready many blogs but no where mentioned exact solution.
Can you please guide us how we can execute PHP code in .html files.
Note : We are using Apache 2.4, PHP-FPM and MPM_worker on centos 7.
After change below in files "/etc/php-fpm.d/www.conf" and "/etc/httpd/conf.d/php.conf" :
"security.limit_extensions = .php .php3 .php4 .php5 .htm" // in www.conf
and
SetHandler "proxy:fcgi://127.0.0.1:9000" // in php.conf
PHP code working in htm files but due to to these changes every html files renders as php. We want only php code render as php not html code render by php.
Your help would be appreciated.
This is how I configure Apache / PHP-FPM for a virtual host. It's not a public server so I'm only using HTTPS. This is from /etc/httpd/conf.d/ssl.conf:
<VirtualHost _default_:443>
DocumentRoot "/home/myvhost/public_html"
ServerName myvirtualhost.com:443
<Directory "/home/myvhost/public_html">
allow from all
Options FollowSymLinks SymLinksIfOwnerMatch
Require all granted
php_admin_value open_basedir /home/myvhost/public_html
</Directory>
SuexecUserGroup myvhost myvhost
ProxyPassMatch ^(/.*\.php)$ fcgi://127.0.0.1:9000/home/myvhost/public_html/$1
<FilesMatch \.php$>
# SetHandler application/x-httpd-php
SetHandler "proxy:fcgi://127.0.0.1:9000"
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
</FilesMatch>
</VirtualHost>
And this is from /etc/php-fpm.d/myvhost.conf (copied from the default PHP-FPM configuration file):
[myvirtualhost.com]
user = myvhost
group = apache
listen = 127.0.0.1:9000
security.limit_extensions = .php
So basically you could just copy the "ProxyPassMatch" line and change php to html and do the same thing with "FilesMatch". You can also modify the regex but I'm not really good at that.

FastCGI/FPM on PHP7.0 + Apache2 on Ubuntu 16.04 server (AWS)

So all the answers already available on Google, here on SO and even on DigitalOcean only discuss either about PHP5.6 or less OR Apache2 v2.3 or less OR only v.14.04 or less of Ubuntu which are all outdated solutions that won't work/give errors on a latest PHP7.0 + Apache2 v. 2.4.18 on Ubuntu 16.04 server setup that has wordpress with redis, memcache and varnish setup for DB+Object caching, backend speed enhancement and reverse proxy respectively.Just a clear picture of my setup so you don't have to keep on figuring out vague ideas or answers and get the right solutions for people with the latest/almost same setup as mine! :)
Since I use a micro AWS instance that's super slow - sever response time 1.5s to 5.4s on the minimalist pages! I found out that fastcgi is a real gold here that can speed up servers up to 20x to 50x! But I'm unable to get the right setup solutions as they're outdated and PHP after v7.0 has changed pretty much everything about folders and files where we need to store our data and configurations.
So, I followed this Stack Overflow issue https://askubuntu.com/questions/378734/how-to-configure-apache-to-run-php-as-fastcgi-on-ubuntu-12-04-via-terminal and followed the solution provided by Evan Mattson and Nazq (3rd last and last answers), replacing everything with php7.0 and removing php5.6 but as Evan mentions in his answer:
Now create the following PHP file in the document root /var/www/html:
sudo nano /var/www/html/info.php
Add:
<?php phpinfo(); ?>
save & exit.
Now we call that file in a browser (e.g.
http://your-server-ip/info.php)
Under Server API at the top you should see FPM/FastCGI.
Success!
I don't see it! I get the usual default Apache 2.0 Handler in the Server API block of my info.php file which means something is wrong here.
The suggestions ask to:
edit /etc/apache2/conf-available/php5-fpm.conf with
<IfModule mod_fastcgi.c>
AddHandler php5-fcgi .php
Action php5-fcgi /php5-fcgi
Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi
FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -socket /var/run/php5-fpm.sock -pass-header Authorization -idle-timeout 3600
<Directory /usr/lib/cgi-bin>
Require all granted
</Directory>
</IfModule>
And then executing:
#sudo a2enconf php5-fpm
#sudo apache2 restart
Replacing them for PHP7.0 Here's my version of these steps:
I edited /etc/apache2/conf-enabled/php7.0-fpm.conf and
/etc/apache2/conf-available/php7.0-fpm.conf BOTH with:
<IfModule mod_fastcgi.c>
AddHandler php7.0-fcgi .php
Action php7.0-fcgi /php7.0-fcgi
Alias /php7.0-fcgi /usr/lib/cgi-bin/php7.0-fcgi
FastCgiExternalServer /usr/lib/cgi-bin/php7.0-fcgi -socket /var/run/php7.0-fpm.sock -pass-header Authorization -idle-timeout 3600
<Directory /usr/lib/cgi-bin>
Require all granted
</Directory>
</IfModule>
So now, these 2 files look exactly (same) like this:
# Redirect to local php-fpm if mod_php is not available
<IfModule !mod_php7.c>
<IfModule proxy_fcgi_module>
# Enable http authorization headers
<IfModule setenvif_module>
SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1
</IfModule>
<FilesMatch ".+\.ph(p[3457]?|t|tml)$">
SetHandler "proxy:unix:/run/php/php7.0-fpm.sock|fcgi://localhost"
</FilesMatch>
<FilesMatch ".+\.phps$">
# 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[3457]?|t|tml|ps)$">
Require all denied
</FilesMatch>
</IfModule>
</IfModule>
<IfModule mod_fastcgi.c>
AddHandler php7.0-fcgi .php
Action php7.0-fcgi /php7.0-fcgi
Alias /php7.0-fcgi /usr/lib/cgi-bin/php7.0-fcgi
FastCgiExternalServer /usr/lib/cgi-bin/php7.0-fcgi -socket /var/run/php7.0-fpm.sock -pass-header Authorization -idle-timeout 3600
<Directory /usr/lib/cgi-bin>
Require all granted
</Directory>
</IfModule>
Then I execute #sudo a2enconf php7.0-fpm (--> replaced) and
#sudo service apache2 restart
#sudo systemctl restart apache2
And I call the file in a browser (e.g. http://your-server-ip/info.php)
Under Server API at the top you should see FPM/FastCGI.
But I still see: The usual default Apache 2.0 Handler in the Server API block of my info.php file which means something is wrong here.
Please help! I'm stuck on this for so long!
P.S.: Please give solutions that you have found correct/working as this is for my production site, experimentation may cause something to break, suggestions are welcome but please don't go for something that is irreversible/disaster! Thanks!

Apache suddenly not parsing php

So my server suddenly stopped parsing PHP (sends raw php to the client). I'm not really sure when it happened, but I just noticed it today. I was messing with some mod_rewrite stuff, but I put it back and it didn't change. Other than that I haven't changed anything (to the best of my knowledge). Ideas? It's an Ubuntu 11.10 server, BTW.
Few things to try...
First:
apachectl -t -D DUMP_MODULES | grep php
You should get something like:
php5_module (shared)
at the very least.
Secondly... how are you restarting apache? Are you sure it is getting killed? I have used an apache init.d script before that would actually run an apachectl configtest to make sure it was error free before stopping and restarting. So, perhaps you need to stop, ensure it is stopped, then start again.
Also, in your config, make sure you have something like:
<IfModule php5_module>
AddType application/x-httpd-php .php
</IfModule>
You don't necessarily need the <IfModule> directive, but doesn't hurt.
And what version of apache are you running?
check:
that PHP files have their executable bit set
that "index.php" is set as one of default index files in your web
root
that php module is loaded by apache (see apache config file, perhaps
near by enabling mod_rewrite module)
Remove the Rewrite setting might be you have return wrong.
And restart the Apache server. Hope that will resolve the issue.
Can refer to
http://www.matthewwittering.co.uk/blog/ubuntu-tips/apache-not-running-php-files.htm
https://askubuntu.com/questions/59272/php-not-working-in-apache2-after-system-upgrade
<IfModule mod_php5.c>
<FilesMatch "\.ph(p3?|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>
# To re-enable php in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
<IfModule mod_userdir.c>
<Directory /home/*/public_html>
php_admin_value engine Off
</Directory>
</IfModule>
</IfModule>

PHP Files won't open in browser - only download. What do I need to change to make it work properly?

I have tried reinstalling PHP. PHP is working, and Apache2 is running. I don't know why it's not opening in a browser and displaying normally.
Just so you know - my httpd.conf is empty - and instead I have everything in apache2.conf. This is because I'm using Ubuntu.
Can you help me? I know it's something simple, but I can't seem to find the answer.
Have you virtual host on this project?
Are you open php file with http://localhost/file.php or directly like file://...../file.php ?
In your apache conf:
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
Don't forget to restart apache afterwards. Let me know how it goes.
In my case there was a modification of the /etc/apache2/mods-enabled/php5.conf by module userdir
<IfModule mod_php5.c>
<FilesMatch "\.ph(p3?|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>
# To re-enable php in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
<IfModule mod_userdir.c>
<Directory /home/*/public_html>
php_admin_value engine Off
</Directory>
</IfModule>
</IfModule>
The solution is inside the config file, just comment the lines from <IfModule mod_userdir> to </IfModule>.
Try
sudo a2enmod php5
in terminal.
Assuming you are using php 5 :)
If you are using php5 the complete solution would be
sudo apt-get install libapache2-mod-php5
Then
sudo a2enmod php5
I recently had this problem, but only when accessing my site's root (e.g. http://example.com) - it worked as expected when accessing index.php explicitly (e.g. http://example.com/index.php).
The issue was that before creating index.php, I had an index.html file in the web root, but then I renamed it to index.html.bak to 'move it out of the way'. Unfortunately, that doesn't move it out of the way. For whatever reason, Apache will serve that file up with a MIME type of application/x-trash.
(As the /etc/mime.types file contains a line reading "application/x-trash ~ % bak old sik")
Maybe that will help someone else who is scratching their head as I was.
Also, when moving a site and you encounter this, make sure your .htaccess file doesn't specify a different method handler for php. We ran into this moving a wordpress site for a client.
Had same problem - and it was in the .htaccess file I had accidentally downloaded from the live server. Once you've deleted the .htaccess file, you will need to clear your cache to be able to load the .php file in your browser via http://

Categories