Are you trying to set custom php.ini in FastCGI?
This guide will help you.
When using FastCGI (FCGI) as the loader for PHP, traditional phpvalues in the .htaccess file as well as custom php.ini files in the publichtml directory no longer work.
Most of the domains move to PHP nowadays. In a shared server, all of us want to set the PHP parameter according to the feasibility of domains.
In such a case, custom PHP plays an important role.
Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform FastCGI queries.
In this context, we shall look into how to set custom php.ini in FastCGI.
With custom PHP, according to our requirements, we can set features like 'maximum upload file size, maximum execution time' and so on.
Among the PHP handlers, in a shared server, due to a lack of resources, FastCGI is the best to manage resources for a high traffic site.
Moving ahead, our Support Experts show how to set custom PHP in 'FastCGI' as a PHP handler.
To set a custom "php.ini" for the "FastCGI" PHP handler a few settings are to be done in the server.
Initially, we check the current PHP handler for the server:
# /usr/local/cpanel/bin/rebuild_phpconf –current Available handlers
If it is "FastCGI", we proceed with the below-given steps to enable custom "php.ini":
1. Open the ".htaccess" file for the domain and add the below codes:
AddHandler php5-fastcgi .php
Action php5-fastcgi /cgi-bin/php5.fcgi
2. Then, move the php.ini file to the cgi-bin folder of the account and also change the permission of the file to "755".
3. Add the below-given code to the "cgi-bin" directory which is present inside the "public_html" file of the domain:
#!/bin/sh
export PHP_FCGI_CHILDREN=1
export PHP_FCGI_MAX_REQUESTS=10
exec /usr/local/cpan el/cgi-sys/php5
4. Eventually, save and quit the file.
5. Then change the permission of the file "/home/user/public_html/cgi-bin/php5.fcgi" to 755.
Now, we have a custom PHP for our domain. Once this is done, we can set different PHP parameters.
For example, if want to install Drupal, we need to set the PHP parameter "Memory Limit" as 64MB which helps seamless installation of Drupal in our domain.
Though there is a never-ending stream of things to do, if we take care of the steps above, we can perform the task easily.
This article covers how to set custom php.ini in FastCGI. Basically, FastCGI is the best to manage resources for a high traffic site in shared servers.
To create Custom php.ini with PHP5 under FastCGI:
1. First open .htaccess for the account in question and add the following lines to the bottom of the file:
AddHandler php5-fastcgi .php
Action php5-fastcgi /cgi-bin/php5.fcgi
2. Next, you'll need to source your main server php.ini which is located in /usr/local/lib/. Also note that it needs to have the correct ownership so we'll take care of that too:
cd /home/user/public_html/cgi-bin/
cp -a /usr/local/lib/php.ini .
chown user:user php.ini
3. Next we need to create the wrapper script. Create a file in your current directory (cgi-bin) called php5.fcgi as defined above and add the following:
#!/bin/sh
export PHP_FCGI_CHILDREN=1
export PHP_FCGI_MAX_REQUESTS=10
exec /usr/local/cpanel/cgi-sys/php5
4. Finally, make sure the ownership and permissions are correct on this file:
chown user:user php5.fcgi && chmod 0755 php5.fcgi