Blog

PHP-fcgi : Local php.ini fails to load

Tags: fastcgilocal php.iniphp

Published on: August 24, 2014 by Vipin R.N

PHP-fcgi : Local php.ini fails to load

Scenario:

The php parameters in a FastCGI environment can be changed  by creating a php.ini file in users document root /home/username/public_html/php.ini . But sometimes the custom php.ini not loading as expected, as shown in the image below.

Here I am making an attempt to verify the a custom php.ini  configuration and resolutions in FastCGI environment

1) Create a PHP Info page

2) Check the loaded configuration file :

phpinfo_basic

3) Login to your server via SSH

4) Make a backup copy of your cPanel PHP wrapper script with the following command :

cp -frp /usr/local/cpanel/cgi-sys/php5 /usr/local/cpanel/cgi-sys/php5-BACKUP

5) Now edit the cPanel PHP wrapper script with your favourite text editor :

vi /usr/local/cpanel/cgi-sys/php5

 By default this script should look like :

#!/bin/sh # If you customize the contents of this wrapper script, place

# a copy at /var/cpanel/conf/apache/wrappers/php5

# so that it will be reinstalled when Apache is updated or the

# PHP handler configuration is changed

exec /usr/bin/php

6) Above the line exec /usr/bin/php add the following code :

[[ -f ~/public_html/php.ini ]] && exec /usr/bin/php -c ~/public_html/php.ini

Now the cPanel PHP wrapper script should look like :

    #!/bin/sh

    # If you customize the contents of this wrapper script, place
    # a copy at /var/cpanel/conf/apache/wrappers/php5
    # so that it will be reinstalled when Apache is updated or the
    # PHP handler configuration is changed

    [[ -f ~/public_html/php.ini ]] && exec /usr/bin/php -c ~/public_html/php.ini
    exec /usr/bin/php

What this does is uses the Bash syntax for seeing if a file exists [[ -f ]] and in this case we’re looking for the file ~/public_html/php.ini. The ~ symbol would represent the current user calling the script, so this would be the same as entering in either /home/user1/public_html/php.ini or/home/user2/public_html/php.ini as the full path.

 The rest of the code simply executes the PHP binary at /usr/bin/php with the -c flag which sets the location where you’d like to load a php.ini from from. In this case we are telling the server we’d like to use the php.ini file inside the user’s /public_html/ directory if one exists, instead of/usr/local/lib/php.ini which would be the server’s default.

7) Now you’ll want to copy the cPanel PHP wrapper script to a more permanent location, so that your settings are saved if you ever recompile Apache down the road. This can be done using the following command:

mkdir -p /var/cpanel/conf/apache/wrappers

cp -frp /usr/local/cpanel/cgi-sys/php5 /var/cpanel/conf/apache/wrappers/php5

8) Now restart Apache for the settings to become active:

service httpd restart

 

9) Reload the info page which you have created earlier now you can see the loaded configuration path as the below :

phpinfo_final

If you check the “Loaded configuration File” you can see that the loaded configuration file is present in the users home directory.

Category : cPanel, Howtos, Linux, Troubleshooting

Vipin R.N

Vipin R.N

Vipin is a no-nonsense, disciplined guy who ensures that everything is carried out with the highest level of perfection. Apart from his great coding skills, he is quite interested in advanced server administration, issue analysis, documentation and training. In-depth knowledge in international politics, ammunition and automobiles makes this hard core Manchester United fan, one of the most referenced personalities in the entire team.

You may also read:

Comments

Add new commentSIGN IN

Let's Connect

Categories

Your Cart

Cart is empty.

Subtotal
₹0.00
APPLY
0
Send this to a friend