0 votes
asked by (6k points)

1 Answer

0 votes

For using custom php.ini file per user in FastCGI (fcgid) with SuExec to load php pages. What we will be doing, is telling our php interpreter (fastcgi) to use a different configuration for a specific user. We are going to do this through the use of .htaccess files, and a new action script. I am going to assume that you already have everything installed and working correctly.

We'll test with user “webhost” to use its own php.ini file. All documents are served out of the /home/webhost/public_html folder, so we are going to start by creating/editing our .htaccess file that is there, you can use your own editor of choice.

root@server [~] # pico /home/webhost/public_html/.htaccess

Now, place the following code at the top of the file:

AddHandler php-fastcgi .php
Action php-fastcgi /cgi-bin/php.fcgi


What this does, is tell the web server to use the php5-fastcgi script to execute .php files. The next step, is to create that file, and place our configuration within it. We place this file within the cgi-bin folder of the users home directory.

root@server [~] # echo '#!/bin/sh' >> /home/webhost/public_html/cgi-bin/php.fcgi
root@server [~] # echo 'exec /usr/local/cpanel/cgi-sys/php5' >> /home/webhost/public_html/cgi-bin/php.fcgi


This places the correct statement within the file. Because the file is being loaded from the /home/webhost/public_html/cgi-bin/ folder, this is where it will look for a php.ini file. So, you would now want to place your customized php.ini file in the /home/webhost/public_html/cgi-bin/ folder. A simple way to do this on a cPanel server, is to copy to existing one being used, then modify it after to your liking. To do this, run the following:

root@server [~] # cp /usr/local/lib/php.ini /home/webhost/public_html/cgi-bin

Ok, permissions. Because we have done all of this as root, permissions for a couple of files may need modifying. The first one, is the script call itself. This is because this server is running SuExec, which executes scripts with the owners permissions. Because the file currently has root as the owner, it will flag up a 500 error. To fix this, we give it the owner and group of the user, as well as execute permissions:

root@server [~] # chown webhost:webhost /home/webhost/public_html/cgi-bin/php.fcgi
root@server [~] # chmod 700 /home/webhost/public_html/cgi-bin/php.fcgi


We might as well check the owner of that .htaccess file we created too:

root@server [~] # chown webhost:webhost /home/webhost/public_html/.htaccess

Now, everything should be ready to go. How do we see if it worked? Easiest way, is to use phpinfo. Make sure of course, that this is not disabled in you php.ini file. Create a new file within your public_html folder of your website. Lets call it phpinfo.php. Within that file, place the following:

Once that is done, navigate your browser to the page you just created, and check the under the “Loaded Configuration File” section. It should state something along the lines of “/home/webhost/public_html/cgi-bin/php.ini”. If so, your all set!
 

answered by (6k points)
...