Proper procedure to edit php.ini

gareth.star

Member
May 9, 2013
20
2
3
cPanel Access Level
Root Administrator
Hi.

I've run into a problem with my server where suhosin is using its default settings, which unfortunately cause problems with a site I am maintaining. I've found that if I edit /usr/local/lib/php.ini, the problems are solved. I'm unable to do this via cPanel or WHM since you cannot edit suhosin specific settings there.

As I understand it, /usr/local/lib/php.ini will be overwritten and revert back when an update is performed.

What is the best way to edit php.ini, while maintaining my changes on every update?

Thanks!
 

quietFinn

Well-Known Member
Feb 4, 2006
1,222
87
178
Finland
cPanel Access Level
Root Administrator
In PHP5.3.x (and later) you can add your own settings in an .ini file in directory /usr/local/lib/php.ini.d
see:
php --ini
 

gareth.star

Member
May 9, 2013
20
2
3
cPanel Access Level
Root Administrator
In PHP5.3.x (and later) you can add your own settings in an .ini file in directory /usr/local/lib/php.ini.d
see:
Unfortunately that doesn't work, even though I am on PHP 5.3.x

Configuration File (php.ini) Path: /usr/local/lib
Loaded Configuration File: /usr/local/lib/php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)
Any other ideas? :)

Thanks for the response!
 

quietFinn

Well-Known Member
Feb 4, 2006
1,222
87
178
Finland
cPanel Access Level
Root Administrator
Unfortunately that doesn't work, even though I am on PHP 5.3.x



Any other ideas? :)

Thanks for the response!
It works if you have "Safe PHP CGI" selected in EasyApache-> Exhaustive Options List
 

gareth.star

Member
May 9, 2013
20
2
3
cPanel Access Level
Root Administrator
It works if you have "Safe PHP CGI" selected in EasyApache-> Exhaustive Options List
This worked perfectly! Thanks so much :D

For anyone stumbling onto this thread looking for a solution (for PHP 5.3.x and above):

In a console, type "php --ini" and you should hopefully see output similar to:

Code:
Configuration File (php.ini) Path: /usr/local/lib
Loaded Configuration File: /usr/local/lib/php.ini
Scan for additional .ini files in: /usr/local/lib/php.ini.d
Additional .ini files parsed: (none)
If the "Scan for additional .ini files" line says (none), you need to enable support for additional .ini files by logging into WHM, going to "EasyApache (Apache Update)" and stepping through until you reach the "Exhaustive Options List". There you will find the option "Safe PHP CGI (prevents users from overriding system php.ini)". Make sure that option is enabled, and continue to build your new environment.

Once complete, you can type "php --ini" again and you should hopefully have the additional .ini files line properly set.

Again in the console, navigate to /usr/local/lib and check to see if php.ini.d exists. If it does not (it didn't for me), create the directory.

Once done, you can place any .ini file in there (I named mine "test.ini") and PHP will read it. These .ini files do not have to be complete. The .ini file I made had the few settings that I needed. The rest were pulled directly from the main .ini file at /usr/local/lib/php.ini

If you are using PHP with Apache, don't forget to restart the Apache HTTPD service in order for the new ini files to be read.
 
  • Like
Reactions: Mads Nordholm