I just installed multiple PHP versions on my server using FastCGI. Although I can only use them when the module PHP5 is disabled. When the latter is enabled, this configuration of my virtual host seems to be ignored :
<Directory /var/www>
AddHandler php-cgi .php
Action php-cgi /cgi-bin-php/php-cgi-5.5.17
</Directory>
Everything works fine when PHP5 is disabled but everything is executed using the module PHP5 when it is available. Would you have any idea?
Thank you
Ps: I am obviously on Apache (2.4) on Debian 7
After a moment of reflection, it makes sense that when the PHP module for Apache is available, Apache2 uses it, since it is part of it. My main issue was actually to prevent having to specify a handler for each website I have on the server, and if none is defined, use a default PHP version with FastCGI.
To get this working, I eventually added something like this in my fastcgi.conf:
<Directory /var/www>
AddHandler php-cgi .php
Action php-cgi /cgi-bin-php/php-cgi-5.5.17
</Directory>
With this I was sure to have at least PHP5.5 running for each site, without having to specify the handle in the virtual host. Problem was, what about Phpmyadmin that runs under /usr/share/phpmyadmin? Then I removed the <Directory> tag and it works.
I don't know if that is the best solution but please let me know if the above is correct or if there would be a better way to perform what I need.
Thank you
Related
I've got a server that is running Linux Debian and have apache2 and php5 installed but I have no control over its apache configuration. If I create a .htaccess file on the server to do for instance a basic authentication on a directory it works. However if I want to use any extension to be executable as PHP such as file.abc with AddType it makes it downloadable. Although PHP extensions such as php1, php2, php3, php4, php5 and phtml are perfectly executable as PHP on this server.
My Question is If Basic Auth is working but any.ext cannot be executable as PHP does that mean AllowOverride is set to None? Then how basic Auth is working? And am I able to make any.ext executable as PHP on this server?
I completed a php/mysql project for a client and yesterday went about to deploy it onto the client's box - and promptly failed. To be honest, it's my fault I didn't do enough checking before I started - but the project is fully self-contained and I didn't need anything currently on the client's server.
I developed the project using php 5.3 and PDO for mysql connection. When I got access to the client's server, turned out that they have VERY old installation that was last upgraded in 2008 (yes, seriously). They have Apache 2.0 and php 5.2, which is configured/compiled without PDO and with minimum everything.
I do have root access to the server, but I can't go and blindly start upgrading things. They've got a whole live site, with live shopping cart, etc. on that server and any general upgrade of php would require thorough testing. Therefore I'm looking at ways to run my new project using a separate install of php 5.3, which I compiled from sources with all required stuff included and installed into a separate directory (/opt/php53).
I am thinking along the lines of enabling fastcgi on the server and then using that to run php form my separate install. If I do this inside apache <Directory> where my project is install, it should only affect that one directory - and should leave everything else as is. Things are made more complicated because I don't have any kind of test server where I could play/test configurations - I have to work on the live server directly.
I'm wondering whether this fastcgi approach is valid or maybe there are some other options I should consider.
You can try to use different ports on fastcgi for the various PHP versions.
Another approach: http://linuxplayer.org/2011/05/intall-multiple-version-of-php-on-one-server
I've done some further digging/experimenting (taking advantage of the fact that I'm in UK and the client and its customers are in the USA - so it's still night there). The following setup seems to have worked - this utilises php-cgi without recourse to fastcgi - and I still get a good response time.
1) Leave pretty much everything intact in apache httpd.conf file - that includes existing libphp5.so that utilises existing 5.2 installation.
2) Install php 5.3 into a separate directory - in my case /opt/php53.
3) In httpd.conf, add the following (or ensure it's already there)
ScriptAlias /cgi-bin/ /var/www/mainsite/cgi-bin
AddHandler cgi-script .cgi
<Directory /var/www/mainsite/newapp>
Options -Indexes FollowSymLinks +ExecCGI
AllowOverride AuthConfig FileInfo
AddHandler php5-cgi .php
Action php5-cgi /cgi-bin/php.cgi
DirectoryIndex index.php index.html
Order allow,deny
Allow from all
</Directory>
4) In directory /var/www/mainsite/cgi-bin/ create file php.cgi with the following content:
#!/bin/bash
PHP_CGI=/opt/php53/bin/php-cgi
PHP_FCGI_CHILDREN=5
PHP_FCGI_MAX_REQUESTS=1000
### no editing below ###
export PHP_FCGI_CHILDREN
export PHP_FCGI_MAX_REQUESTS
exec $PHP_CGI
5) Restart apache: /etc/init.d/httpd restart
After this, I placed a file with <?php phpinfo(); ?> into the root of the web server and into my newapp directory. Executed from the root of the server it produced (among other things):
PHP Version 5.2.5
Build Date Dec 11 2008 19:04:47
Server API Apache 2.0 Handler
When executed from the newapp directory, it produced:
PHP Version 5.3.28
Build Date Feb 13 2014 17:00:43
Server API CGI/FastCGI
Which is exactly what I want.
There are Apache 2 + mod_wsgi + Python 2.6 on server.
I would like to run scripts from Python like PHP scripts. The idea may seem silly, but I'm so accustomed (at least at first learning Python).
Example:
PHP - http://example.com/script.php
Python - http://example.com/script.py
P.S. I know about mod_rewrite and other similar tricks that can do that. But it is only a disguise, and not a direct run.
UPD: My .htaccess file. index.py works, but other python scripts get 404 error.
<Files *.py>
SetHandler wsgi-script
Options ExecCGI FollowSymLinks
</Files>
DirectoryIndex index.py
That doesn't look as cool as having a wsgi app running, so I recommend that you use the flask framework which is as simple as can be a sane framework.
Here's a link describing the install procedure on mod_wsgi.
Later on, you might want to consider a cool framework like Django, Pyramid, Grok ...
If you really want to use mod_wsgi like mod_php check Graham Dumpleton's great answer.
Technically what you are doing should work, but see AddHandler method for configuring mod_wsgi in:
http://code.google.com/p/modwsgi/wiki/ConfigurationGuidelines#The_Apache_Alias_Directive
That way you don't have to fiddle with Files directive.
SetHandler does similar thing but all files in context are treated as WSGI script files even if they may be static HTML or PHP files. You got away with it because qualified with Files, but better to just use AddHandler.
Do note that code reloading will not work like you are used to with PHP. See:
http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode
I run Python scripts like PHP using mod_cgi
Here is a tutorial by Apache. And the cgi interface to use is here by Python.org
A second good tutorial that I used is here once your up and running.
I would add that there is a simiplier way to configure Apache.
Step 1: The first step is not mentioned in the guides above is to enable CGI processing in apache.
sudo a2enmod cgi
This will automatically enable mod_cgid if your server is configured with a multi-threaded MPM, which was the case for me.
Step 2: Edit your httpd.conf or whatever it is named in /etc/apache2/sites-enabled
in Linux Mint 19.2.
Enable a script for / with an index.py
<VirtualHost *:80>
DocumentRoot /your/www/html
DirectoryIndex index.py
</VirtualHost>
Step 3: Enable other python scripts so they can also run in the same folder or in subdirectories.
<Directory "/your/www/html/*">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
AddHandler cgi-script .py
AddHandler default-handler .jpg .png .gif .css .js .ico
</Directory>
ScriptAlias / /your/www/html/
There are two caveats that I have encountered that must be adhered to to run python scripts successfully.
When running in linux, make sure the line endings of each python file.py are
unix line endings. Otherwise the python script will not run. For example,
Notepad++ has Edit, EOL Conversion, Linux (LF) in its menu,tool bar.
Ensure that the permission of each python file.py has execute permissions.
In Linux Mint 19.2 I right click the file, go to Properties, go to Permissions,
then check the checkbox at Execute: Allow executing program as file. Or just
run the command:
chmod a+x python_script.py
Earlier today I tried installing the MyImouto image board software on my Apache server. I already have the full MediaWiki engine installed on port 80 (localhost/wiki/) and the MyImouto board installed in a virtual host on port 3000, running completely separate from the main web server.
After fiddling around a little, I made a mistake with a php-based upload on the main server and had to reinstall apache and php both, which I did, and upgraded to the latest versions (Apache 2.2.22 and PHP 5.4.0). I managed to get my setup up and running successfully, both with the port 3000 virtual host and without. And MediaWiki functions fine, except for one thing.
NOW when I type in http://localhost/wiki/index.php as I have always done in the past, something is redirecting it to http://localhost:3000/wiki/index.php/Main_Page and shifting it to the other virtual host, where there is no wiki at all. However http://localhost/wiki/index.php/Main_Page does work perfectly.
There's an .htaccess file in localhost:3000 which I renamed to something else, but that doesn't seem to do the trick. I also tried clearing the browser cache as well as running a session_destroy via php. It didn't fix it.
I even turned off the second virtual host in Apache's httpd.conf, but it still redirects me which tells me that it is something in the main webserver. I did not touch the MediaWiki configuration or code during this entire time.
I also attempted accessing http://localhost/phpMyAdmin and THAT redirected me to http://localhost:3000/phpMyAdmin/, as well as http://localhost/AdminTools which does the same type of thing. Httpd.conf now no longer has any references at all to the virtual host *:3000.
However, my main index (http://localhost/index.php) has the following header redirect, which successfully lets it work even when http://localhost is typed into the address bar.
header("Location: index.php?content=main");
I tried disabling expires_module and headers_module in Apache, thinking there might be some weird caching issue due to that now-renamed .htaccess file. That did not help either. In addition, I checked my hosts file and there is nothing odd in there, nor am I proxying through anything (this -is- localhost after all).
Would appreciate any help in figuring out what's causing this and how to fix it.
Windows XP SP3
Enabled Modules in Apache:
actions, alias, asis, auth_basic, authn_default, authn_file, authz_default, authz_groupfile, authz_host, authz_user, cgi, dir, env, expires, headers, include, isapi, log, mime, negotiation, rewrite, setenvif, php5
Enabled extensions in PHP:
curl, fileinfo, gd2, mbstring, exif, mysql, mysqli, openssl, pdo_mysql, sockets
I managed to figure it out. After fiddling a little bit with .htaccess and Rewrite Rules (none of which did anything), I took a look inside my httpd.conf file again and found that I had typo'd my port-80 Virtual Host:
<VirtualHost *:80>
ServerAdmin -myemail-#gmail.com
ServerName -blahblah-.no-ip.org:3000
DocumentRoot "C:/wwwroot/tfg"
<Directory "C:/wwwroot/tfg">
OptionsIndexes FollowSymLinks
AllowOverride All
Allow from all
Deny from 186
Deny from 187
</Directory>
</VirtualHost>
When in fact it should have been ServerName -blahblah-.no-ip.org:80.
Simple typos: always the ones that slip by the easiest.
There are some tutorials out there telling me how to override PHP configuration when it is running in CGI mode. But I'm still confused because lots of them assume that the server is running on Linux. While I need to do that also on Windows.
My hosting is indeed using Linux but my local development computer is using Windows XP with Xampp 1.7.3. So I need to do that in my local computer first, then I want to change the configuration on hosting server.
The PHP in my hosting server is already run as CGI while in my local computer still run as Apache module.
At this point, the processes that I understand are:
Change PHP to work in CGI mode. I did this by commenting these two line in "httpd-xampp.conf":
# LoadFile "C:/xampp/php/php5ts.dll"
# LoadModule php5_module modules/php5apache2_2.dll
My PHP is now running as CGI. I checked this with phpinfo(). It tells me that the Server API is now CGI/FastCGI. Now I want to override php configuration.
Create "cgi-bin" directory in DocumentRoot. My DocumentRoot is in "D:\www\" (I'm using apache with virtual host). So it is now "D:\www\cgi-bin".
Change the default "cgi-bin" directory settings from "C:/xampp/cgi-bin/" to "D:\www\cgi-bin":
ScriptAlias /cgi-bin/ "D:/www/cgi-bin/"
<Directory "D:\www\cgi-bin">
Options MultiViews Indexes SymLinksIfOwnerMatch Includes ExecCGI
AllowOverride All
Allow from All
</Directory>
Copy 'php.ini' file to "D:\www\cgi-bin" and modify upload_max_filesize setting from 128M to 10M.
Create 'php.cgi' file in "D:\www\cgi-bin" and put these code inside the file:
#!/bin/sh
/usr/local/cpanel/cgi-sys/php5 -c /home/user/public_html/cgi-bin/
That's it. I'm stuck at this point. All of tutorials tell me to create 'php.cgi' file and put shell code inside the file.
How to do the 6th step on Windows? I know the next step is to create handler in .htaccess file to load that 'php.cgi'.
And also, because I will also need to change PHP configuration on my hosting server (Linux), is the 6th step above right? Some tutorial tells to insert these lines instead of above:
#!/bin/sh
export PHPRC=/site/ini/1
exec /cgi-bin/php5.cgi
I'm sorry if my question is not clear. I'm a new member and this is my first question in this site.
Thank you.
If your server is already running PHP as cgi, and you do not need to run multiple PHP configurations, steps 5 and 6 are not necessary. Just change the default php.ini