Including several PHP versions in Apache, switchable via AddHandler directive - apache

A shared web host I'm using is offering several versions of PHP on the same server: 5.2, 5.3 and 5.4. They make it possible to switch between these versions by naming the file extensions .php54 and .php53 respectively, or via an .htaccess directive:
AddHandler php5.4-script .php
I have not been able to completely figure out how their Apache server is configured to support this though. Everything I found seemed to say that only one mod_php can be compiled into Apache at a time. Would this suggest that php5.4-script is some sort of custom wrapper module? Or are there obscure ways in which different PHP modules can be compiled under different handler names?

According to the resource I've found after researching on this topic, it is as you already thought a (Fast) CGI wrapper which allows you to change the PHP version used via e.g. .htaccess .
How to achieve this is explained thoroughly here: http://linuxplayer.org/2011/05/intall-multiple-version-of-php-on-one-server .
In case the site is not reachable, here I'm going to list the steps:
Install required dev packages
Compile and install
Create a fastcgi wrapper script
Build and install e.g. php-5.3 with fpm enabled
Configure php-fpm
Start fpm
Install and setup mod_fastcgi, mod_fcgid
Update the Apache config file
Restart Apache

Related

Laravel: how to specify the php version?

I have a Laravel (5.7.19) app running with apache2 on a redhat7 machine. There are php5.6, php7.1 and php7.4 installed on the machine and somehow apache uses php5.6 as the default and the app doesn't work with php5.6. Is there a way to specify a php version for a Laravel app, such as setting the php version in .env or some other config file of the app? I've googled around and couldn't find an answer. Right now the only way I could make the app to work is to disable php5.6 and then apache would use php7.1 as the default.
"Is there a way to specify a php version for a Laravel app, such as setting the php version in .env or some other config file of the app?"
No. The PHP interpetor isn't aware of itself. The application's dotenv file is read by the application itself, which means there's already an interpretor doing the job so if it's picked up by php5, there's no way for the interpretor to pass it along to a php7 interpreter.
If you're using Apache (and assuming a single Apache running), you can setup multiple PHP versions under the same Apache server by using the fastcgi module as described here: https://medium.com/#sivaschenko/apache-running-multiple-php-versions-simultaneously-570fc1541580 and then depending on application you can setup virtual hosts using different php versions
THe better way is with nginx + fpm, where you can have different php versions with different fpm instances running on different ports and you can setup server blocks where php requests are routed appropriately.

Howto run mod-mono and php on same apache webserver

I've successfully implemented mod-mono and apache webserver on a Centos 8 distro.
I've also installed PHP 7.2 on the server and the configuration looks ok on eye inspection.
However, the webserver is not executing the PHP files, but serving them for download.
If i go to http://example.com - it runs the website in MONO space
If I go to http://example.com/info.php - it gives me the PHP file for downloading. It makes me think that it tries to run the php file through mono and fails, so gives it to me for download instead forwarding it to PHP for execution.
Is it possible to run both PHP and MONO code on same apache webserver?
If yes, what could be the tricks to have it working ?
Many thanks.
Actually having a separate PHP website and also MONO websites in same apache server was working. However I though things were not working since I tried to run the PHP file from within the MONO-handled virtualhost ... so no need for clarifications.

Can I use yum to install an additional apache httpd server?

I'm using a plain apache server as a front-end and a mod-perl enabled apache server as a backend with mod_proxy.
I'm in the process of moving to a new hosting company so I'm installing software. In the past I've built both of these from source but it would be easier to use yum to install so that they are easily updated. Is it possible to install 2 separate httpd servers with yum? And if so how?
I'm thinking that the solution might be to move the front-end to lighttpd or similar but I'd still like to know whether it is possible.
I'm using Centos 7.
Seem to have it working now. Hope this might help someone else.
I now have one httpd with two different configuration files in /etc/httpd/conf/: httpd_docs.conf and httpd_perl.conf
Set the PidFile to two different files at the top of the config files.
Copied the /etc/httpd/conf.modules.d to /etc/httpd/conf.modules.perl and updated the 'Include' in the two config files to point to the different directories and then deleted unnecessary files in each directory so that the httpd_docs instance does not use mod_perl and the httpd_perl instance does.
Copied /etc/sysconfig/httpd to /etc/sysconfig/httpd_perl and edited each one to include an OPTIONS line
OPTIONS="-d /etc/httpd -f conf/httpd_docs.conf"
and
OPTIONS="-d /etc/httpd -f conf/httpd_perl.conf"
Copied /usr/lib/systemd/system/httpd.service to /usr/lib/systemd/system/httpd_perl.service and edited to point to correct EnvironmentFile.
Used this question to help answer my own question
https://serverfault.com/questions/31838/can-rhel-4-have-two-instances-of-apache-httpd-running-using-two-different-config

Trac on shared server

I'm facing an odd problem with Trac's authentication. I have it installed in other servers and never had problem to install it, but now I'm trying to install it on a shared linux server where:
don't have access to httpd.conf;
only available scripts are php and python (wsgi);
no dev tools at all (so no chance to use gcc to compile something);
.htaccess is okay.
Well, trac is installed and working in anonymous mode and I can not find a way to make it private. It looks like it only relies on Apache basic authentication but I can not do this without httpd.conf access.
On my other instalations I use <Location> inside httpd.conf, but I can't use this tag inside .htaccess. I know that I can simply put <Location>'s content inside a .htaccess file and put this file in any www subdirectory to protect it. But since this is a wsgi script in another directory outside www I have no place to put that .htaccess.
I'm looking for a way to solve this by:
still using apache auth with any other .htaccess configuration that I've missed;
any other way Trac could be used in privative besides relying on apache;
any other issue/project tracking similar to trac is an option too.
I'm using AccountManagerPlugin on a shared Linux server machine of mine without issues.

Apache doesn't load PHP MySQL extension but IIS does

I have a really irritating problem with PHP on Windows Server 2008 R2. IIS and Apache are running on the same machine (Apache is embedded with another product and it being there is not my choice).
IIS is configured to be able to use multiple versions of PHP, and none of the PHP versions on there were installed with the Windows installer (so php.exe does not exist in the path).
Apache uses one particular version of PHP (5.2.5 Thread-safe - again I can't change this as a 3rd-party application has PHP extensions compiled against this version).
If I check phpinfo() in my Apache site it doesn't have an entry for MySQL, even though php_mysql.dll is enabled in php.ini and it exists in the \ext directory. If I (temporarily) add this version of PHP (same directory, same php.ini) to IIS and set up a test site with phpinfo() it correctly lists MySQL. I know this is not just some strange issue with phpinfo because I have a MySQL-based PHP site running in Apache and it fails with Call to undefined function mysql_connect()
It was suggested that I copy libmysql.dll from the PHP directory to C:\Windows\System32 but this made no difference. As there are multiple versions of PHP on the server I suppose it's possible that the wrong version of libmysql.dll is being loaded, but the PATH doesn't include any directories containing libmysql.dll.
IIS and Apache are looking at exactly the same PHP installation, php.ini, and ext directory, but only IIS can load the MySQL extension. Apache is on the default System account as it looks like System has access to all the DLLs.
The Apache logs say nothing about any DLLs failing to load. I'm logging PHP errors in the event log but nothing is reported about those extensions.
After Googling around the issue I found other suddenly-occurring issues in PHP on Windows server but the usual resolutions - rebuilding php.ini, restarting IIS, restarting the server - haven't helped.
Any suggestions on where to look next are much appreciated!
I know this might not ultimately answer your question but, did you try configuring Apache to execute PHP through FastCGI (mod_fcgid) and use the same binary as IIS does ?
I know you are using mod_php, but calling it via FastCGI will abstract PHP from the webserver process. If extensions are loading fine under PHP called via FastCGI, there is no reason it won't work on a different web server.
Also, I personally beleive that it is a better idea this way since PHP is only called when a *.php file is requested. This way, Apache will not load PHP in memory for every request, which will give you better performance for serving static files, for example.
Update
To do this, you need to download mod_fcgid from http://httpd.apache.org/mod_fcgid/, load the module in your Apache configuration this way,
LoadModule fcgid_module modules/mod_fcgid.so
And then, just specify what binary you want to call when PHP pages are requested:
AddHandler fcgid-script .php
FcgidWrapper "c:/php/php-cgi.exe" .php
Then, files with a .php extension will now be executed by the PHP FastCGI wrapper. Just be sure to specify the same php-cgi.exe binary as IIS is using.
All extensions that were previously available in IIS should now be available in Apache since the PHP installation behind is the same in both environment.
Keep me updated.
1.- check php.ini path in phpinfo.
2.- add php folder to the windows path
http://www.computerhope.com/issues/ch000549.htm
3.- add directive PHPINIDir to apache conf
http://php.net/manual/en/install.windows.apache2.php
4.- uncomment mysql extension in respective php.ini
5.- reload apache
6.- check mysql extension in phpinfo
and please don't copy any files to system32
You will generally need different library dlls for the different versions of PHP you are running. It's best to keep these in their own directories.
There's a few different things that could cause a module not to load, including the PHP version whether you're running a thread-safe or not-thread-safe version and also if the binaries were compiled as VC6 or VC9 †. Usually the easiest way to debug if you're getting any module loading errors is running php.exe from the command line as it will spit out any startup errors (also ensure these are enabled in your php.ini and you're loading the correct php.ini file when you do so).
† IIRC VC6/VC9 is to do with which version of Visual Studio PHP was compiled with.
Ultimately this issue came down to a missing PATH reference. Although IIS doesn't seem to require PHP or PHP modules to exist in the path it seems that Apache (or perhaps my version of PHP?) does. I am lucky in that I only need to run one version of PHP outside IIS, as I have no idea what would happen if I had multiple Apache instances referencing different versions of PHP and multiple PHP directories in the path - presumably one would always fail.
So far it looks like adding Apache's version of PHP to the path hasn't affected the IIS versions of PHP, but I will swear loudly if it suddenly does.