Updating php settings in Plesk 10+ from command line / CLI

I’ve tested this on Plesk 10.4.4 and Plesk 11.0.9 and it has worked the same on both.  If you have bulk updates to the php settings that you need to run against every site on a server, such as changing safe mode, the session save directory, include paths, etc. it is a real pain in the ass to do via the horrible Plesk 10+ web interface.  Hell, it would probably take at least 15 clicks per site to make such a change if you’re running web hosting mode interface with new window pop-up enabled for hosting settings.

To do it via the command line, you’ll use two commands:

/usr/local/psa/bin/domain --show-php-settings domain.com

/usr/local/psa/bin/domain --update-php-settings domain.com -settings settings.txt

The first command will show you the current settings for a given domain.  They’ll look like this:

General settings:
safe_mode = off
open_basedir = /
Performance settings:
Additional directivies:

Place the new setting you want to apply in a file named settings.txt and then run the second command.  Fortunately, if you only put the setting to be added/changed, any other custom settings already set on the given domain will be preserved, so you don’t have to worry about wiping config out when applying just one new value.

Next up, if you’re sure you want to go ahead and apply the settings to every domain on the server, here’s a sequence of commands to do that:

/usr/bin/mysql -u admin --password=`cat /etc/psa/.psa.shadow` -e "select name from domains INTO OUTFILE '/tmp/domains.dat' LINES TERMINATED BY '\n'" psa
cat /tmp/domains.dat | xargs -n 1 -i /usr/local/psa/bin/domain --update-php-settings {} -settings settings.txt

The first part of that is a SQL command that will write out a list of all of your domains to /tmp/domains.dat. You should test that command by itself first as your MySQL may not have permissions to write to /tmp if you’ve changed it from the defaults Plesk installs with.  The second line outputs the extracted list of domains and runs the php settings update command against each one of them, one at a time.

Leave a Reply

Your email address will not be published. Required fields are marked *