php5-fpm: bash script to check config before restart
I write a script to create new vhost on Nginx. That script creates Ningx vhost config file, vhost user and dirs, php-fpm pool file.
At the end of the script, I would like to check if config is ok before restart php-fpm. For Apache, I do apachectl graceful
, but is it possible to do something similar with php5-fpm -t
?
Solution 1:
From the manpage:
--test -t Test FPM configuration file and exit If called twice (-tt), the configuration is dumped before exiting.
php5-fpm -t
should exit with code 0 if the config is valid, and a non-zero exit code if not. Your script should do something like this then:
if ! php5-fpm -t; then
echo "php5-fpm configuration is invalid"
exit 1
fi
However, I made some changes to my configuration which weren't picked up as invalid, so YMMV.