Talk:Advanced PHP configuration

Removed step 11
Sharing the same php.cgi accross users was proving problematic in my setup, so I don't recommend using the method that was in step 11 to share a single binary across users anymore. Theoretically it should have worked, but hey, whatever. The best advice I can give is to implement the php-update methd on all users who need it. -- Sambauers 08:09, 16 Feb 2007 (PST)

htaccess issue
For people encountering Internal Server Error 500 upon creating the .htaccess file, open your ~/logs/DOMAINNAME/http/error.log. If you see the error 'Illegal option AddHandler' you probably copied & pasted the contents for the htaccess file directly from the Wiki and there might be some invisible characters causing problems. Go through your .htaccess file and re-enter the hard line breaks between the lines, save, and re-test

By putting the symbolic link to php in your webroot, doesn't this make the php directory and all it's contents web accessible? This would seem to be a security risk.


 * No, the symbolic link makes it a heck of a lot easier to reference to your PHP directory. However, the .htaccess file you should have created in the PHP directory will forbid access. I updated the command for the symbolic link so that it doesn't screw things up. --Elmak 22:15, 21 October 2008 (UTC)

htaccess - Adding an extra extension
You can add an extra extension to be handled by a specific version of PHP by adding the following to your .htaccess file: AddHandler php5-cgi .htm Change php5 to just php to use PHP4 instead of 5.

Moved scripts inline, switched to BSD license
The external location for the files is being taken down, so I've moved the scripts here and switched them over to BSD licensing. This should make them easier for people to contribute to. Please do so carefully. Thanks Sambauers 10:26, 25 June 2008 (UTC)

Using Dreamhost's binary while using your own ini
This is a bit more secure than some setups and you don't have to worry about updating the binary. You can also point it to your own ini file.

PHP supports the -c parameter which allows you to instruct the php binary to use a different ini file other than the default.

The following shows my current php5-wrapper.fcgi file that I use for each domain that has FastCGI mode enabled. This file is in the root of the domain.

export PHP_FCGI_CHILDREN=2 export PHP_FCGI_MAX_REQUESTS=10000 exec /dh/cgi-system/php5.cgi -c /home/ /php/php.ini
 * 1) !/bin/sh

Note that this one is for php5. Change php5.cgi to php.cgi if you want to do this for php4 instead however I don't believe it supports fastcgi mode anyways.

Change to your login username. You may also really change the part following -c to any location and make sure you include the name of the ini file that you want to use.

Now then all you have to do is restart fastcgi so that it reads the new information. This is my script that I use to restart all processes.

restart_fcgi.sh: killall -9 php5.cgi
 * 1) !/bin/sh

This will force php to reload the php.ini file that they were assigned to. Note that this file must be placed outside the web accessable area and should only be run from the shell. If you can remember this command then you won't need this script. I did have another line there but I found that it wasn't ever really needed and it still did occasionally cause issues (php running but not accepting requests).

Last but not least adding more extensions if you wish. I changed my extension_dir to point to a location in my home folder. Once that is done download the php source corresponding to the current version installed. Right now it is 5.2.6. Once that is done extract the whole thing to your home folder. Inside the folder that is created is an ext folder. This folder contains all extensions that are included with php. All you have to do is change to the folder corresponding with the extension you want and issue the following commands.

For php5: /usr/local/php5/bin/phpize ./configure --with-php-config=/usr/local/php5/bin/php-config  make make check

For php4: /usr/local/bin/phpize ./configure --with-php-config=/usr/local/bin/php-config  make make check

Note: Do not run `make install`. This will attempt to have them install to the global dreamhost extension location which we do not want. Once all the steps have been completed you will find the compiled copy in the modules folder which you can copy to your own extension folder. Make sure to add a corresponding extension= .so entry into your ini file.

Now then all of the above only effectively works if you are using fastcgi but why shouldn't you be?

I found that if Dreamhost updates and your extensions are not compatible it will cause php to get stuck. Just a forewarning as it happened recently when Dreamhost updated from 5.2.6 to 5.2.9. Just go back and recompile your extensions for the current dreamhost version and you should be ok. The easiest way to determine what version they are running is to run '/dh/cgi-system/php5.cgi -v' at the terminal.

--Shinji 01:28, 7 July 2008 (UTC) // Last Edited: Shinji 12:18, 5 August 2009 (UTC)

Text file busy
When I run the update script I get the following error:

Warning: copy(/home/richardson/php5/php5.cgi): failed to open stream: Text file busy in /home/.donald/richardson/php5/php-update.php on line 112

Any ideas on how to fix this? It looks like it's not actually updating the php.cgi file... Samuel 04:48, 14 July 2008 (UTC)

Script Errors
Corrected a few script errors: --Elmak 22:20, 21 October 2008 (UTC)
 * The if statements in php-update.sh were done incorrectly and would error out.
 * The symbolic links were created unnamed unremovable links
 * Symbolic links were written as if the PHP folder was one directory level up, corrected for PHP directory to be in your home directory.

Still getting errors when trying to run this script:

 * command not foundne 51:
 * command not foundne 53:

/php-update.phpinput file:.
 * command not foundne 55:

./php-update.sh: line 56: syntax error in conditional expression '/php-update.sh: line 56: syntax error near `]] '/php-update.sh: line 56: `if -e "$UPDATEDIR/php.cgi"

--Chris.mccreery 18:18, 20 September 2010 (UTC)

Thanks
Just a quick note to thank all the people who've worked on this article - very useful, thanks! Sampablokuper 04:00, 15 March 2009 (UTC)

crontab permissions?
In step 7, "crontab -e" gave me this error:

crontabs/tmp.3zDYIF: Permission denied no crontab for - using an empty one

Not sure what would cause that, but perhaps it should be mentioned on the wiki page.

Undesired consequences of PHP_FCGI_CHILDREN in fcgi wrapper script
According to http://wherethebitsroam.com/blogs/jeffw/apache-php-fastcgi-and-phpfcgichildren and http://www.mail-archive.com/mod-fcgid-users@lists.sourceforge.net/msg00288.html, using PHP_FCGI_CHILDREN=X might not be desirable in all setups. It will spawn X additional processes that are not used, and clog up your process count. Personally, this has resulted in lots of 500 Internal Server Error messages (due to php5.cgi processes being killed automatically by procwatch) and almost always my interactive processes on the server are killed right out (like doing small edits using 'nano', but even 'top' and 'more' will get killed). The suggestion of these references seems to be simply remove the 'PHP_FCGI_CHILDREN=X' environment variable from the fcgi wrapper. Might help to make a note of this, especially for shared hosting users, where process count is very limited? --Jstesta 23:07, 26 February 2011 (PST)