PHP.ini configuration

Marks

Verified User
Joined
Jul 13, 2019
Messages
121
Hello, I would like to know if there is a faster way to change PHP settings like memory_limit = 256M

If there is any command in SSH it accesses the desired PHP configuration file and sets this value without having to open and change the files one by one manually.
 
How are you interfacing PHP with your web server?

Do you mean per user or system-wide?

If you have PHP 7.1 installed

sed -i "s/^memory_limit.*/memory_limit = 256M/g" /usr/local/php71/lib/php.ini

Will change the server-wide setting for PHP 7.1

PHP 7.2's php.ini is at /usr/local/php72/lib/php.ini

PHP 7.3 - /usr/local/php73/lib/php.ini

If you are running PHP as php-fpm then you will need to reload the respective PHP master pool

service php71-php-fpm reload

If you are talking about user specific, then this will depend on how you are interfacing PHP with your web server.
 
What are the recommended settings for php-fpm?
For shared hosting, which parameters should I treat?
 
I'm not really sure what you are asking.

Recommended settings are in the eye of the beholder.
 
I definitely think that the recommended settings for memory limits are "at least the defaults". Not less then them. The more, the better... but usually it is useless. Never go below the defaults because some developers rely on them.
 
I think you would actually be surprised as just how little memory most people need for PHP scripts.

Sure, there are some that require more memory and need so legitimately. But if you set your default too high, then you can have poorly coded scripts runaway and hide with all kinds of memory.

I'm more a fan of least privileges necessary, which also means least amount of resources needed. Why give a script 512MB of memory if it only needs 128MB or 64MB?
 
Here are the reasons why:

1. Badly written scripts exist. You can't fix them - they are customers property;
2. 99% of the customers don't care about the technical details - they want their website to... work...

Now, given the above conditions, imagine a customer who call you and say "my site is not working". You explain to them "it's because it uses more than 64MB of RAM" (plus "your script is poorly written" which your customer understand as "bla bla bla"). Then he clearly say:

- But it worked fine with my previous host. And my developer said that you suck because your setting is too low. Fix it or I quit.

Yes, people usually prefer to change their hosting (something they can do relatively easy and it's cheap) than to rewrite their websites (expensive and out of their competency).

That's why going below the defaults on any setting is usually bad idea. Developers do test the websites with stock production settings. Most hosting companies cover them. So all websites should work with them.
 
Back
Top