cancel
Showing results for 
Search instead for 
Did you mean: 

How to run PHP as your own user, without safe mode, on the PAYH platform

Gabe
Community Veteran
Posts: 767
Registered: ‎29-10-2008

How to run PHP as your own user, without safe mode, on the PAYH platform

Done a bit more digging around on PAYH after Christmas and found that it is possible to run PHP scripts as your own user rather than Apache. There is a version of PHP 5.2.1 running as CGI. To use the CGI version rather than the Apache-module version, you will have to:
1. Add a shebang line (see below) to your script, as you would with Perl.
2. Replace the script's .php extension with a .cgi extension.
3. Load your script into the cgi-bin folder rather than the httpdocs folder.
4. Make it executable (755).
Here is a phpinfo script with the necessary shebang line. If you run this script, note the database-related swings and roundabouts.

#!/opt/php52/bin/php5-cgi
<?php
phpinfo();
?>

This doesn't really help with the Joomla/Gallery/etc. problems. It would take an awful lot of editing to convert things like Joomla or Gallery to work with this setup.
IMHO, Plusnet should do the right thing for their customers and keep the ccgi platform running until they update PAYH to Plesk 9.
Nevertheless, for scripters, the method above will allow PHP scripts to be run as your user (e.g. to create files owned by you rather than www-data) and without the safe-mode restrictions. If you decide to use this method to run shell scripts, it would be safest to use a password-protected method such as

http://phpshell.sourceforge.net/

suitably modified, and make your script non-executable when you've finished with it.
Gabe
1 REPLY 1
Gabe
Community Veteran
Posts: 767
Registered: ‎29-10-2008

Re: How to run PHP as your own user, without safe mode, on the PAYH platform

By the way, before I got all cookied out, I'd meant to add that the command-line version of PHP can also be run without safe mode on PAYH, for instance, by using the -n option. This might be useful when setting a PHP script as a cron task:
/usr/bin/php5 -n httpdocs/yourfolder/yourscript.php

If the script has to run from its own directory, then it should start:
chdir(dirname($_SERVER['argv'][0]));

Gabe