diff --git a/conf/nginx.conf b/conf/nginx.conf index 336e2ae..71a8be1 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -15,11 +15,11 @@ location {LOCATION} { index index.php; location ~ ^(.+\.php)(.*)$ { - fastcgi_split_path_info ^(.+\.php)(.*)$; - fastcgi_pass unix:/var/run/php5-fpm.sock; include fastcgi_params; + fastcgi_split_path_info ^(.+\.php)(.*)$; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $request_filename; + fastcgi_pass unix:/var/run/php5-fpm-{POOLNAME}.sock; } location ~ ^{PATH}/(\.|Core|Specific) { diff --git a/conf/php-fpm.conf b/conf/php-fpm.conf new file mode 100644 index 0000000..e249310 --- /dev/null +++ b/conf/php-fpm.conf @@ -0,0 +1,68 @@ +[{POOLNAME}] +; The address on which to accept FastCGI requests. +listen = /var/run/php5-fpm-{POOLNAME}.sock + +; Set permissions for unix socket, if one is used. +listen.owner = www-data +listen.group = www-data +listen.mode = 0600 + +; Unix user/group of processes. +user = www-data +group = www-data + +; Choose how the process manager will control the number of child processes. +pm = dynamic + +; The number of child processes to be created when pm is set to 'static' and the +; maximum number of child processes to be created when pm is set to 'dynamic'. +pm.max_children = 6 + +; The number of child processes created on startup. +pm.start_servers = 3 + +; The desired minimum number of idle server processes. +pm.min_spare_servers = 3 + +; The desired maximum number of idle server processes. +pm.max_spare_servers = 5 + +; The number of requests each child process should execute before respawning. +pm.max_requests = 500 + +; The URI to view the FPM status page. If this value is not set, no URI will be +; recognized as a status page. +pm.status_path = /fpm-status + +; The ping URI to call the monitoring page of FPM. If this value is not set, no +; URI will be recognized as a ping page. +ping.path = /ping + +; The timeout for serving a single request after which the worker process will +; be killed. +request_terminate_timeout = 1d + +; The timeout for serving a single request after which a PHP backtrace will be +; dumped to the 'slowlog' file. A value of '0s' means 'off'. +request_slowlog_timeout = 5s + +; The log file for slow requests. +slowlog = /var/log/nginx/{POOLNAME}.slow.log + +; Set open file descriptor rlimit. +rlimit_files = 4096 + +; Set max core size rlimit. +rlimit_core = 0 + +; Chdir to this directory at the start. +chdir = {DESTDIR} + +; Redirect worker stdout and stderr into main error log. +catch_workers_output = yes + +; Do not clear environment in FPM workers. +clear_env = no + +; Additional php.ini defines, specific to this pool of workers. +; ... diff --git a/scripts/backup b/scripts/backup index d0fb5e7..e88426f 100644 --- a/scripts/backup +++ b/scripts/backup @@ -22,6 +22,7 @@ ynh_backup "$DESTDIR" "sources" # Copy the conf files ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" "nginx.conf" +ynh_backup "/etc/php5/fpm/pool.d/${app}.conf" "php-fpm.conf" # Dump the database mysqldump -u "$dbuser" -p"$dbpass" --no-create-db "$dbname" > ./dump.sql diff --git a/scripts/install b/scripts/install index fad3fcf..a91bbd6 100644 --- a/scripts/install +++ b/scripts/install @@ -67,8 +67,15 @@ nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf" sed -i "s@{PATH}@${path}@g" ../conf/nginx.conf sed -i "s@{LOCATION}@${path:-/}@g" ../conf/nginx.conf sed -i "s@{DESTDIR}@${DESTDIR}@g" ../conf/nginx.conf +sed -i "s@{POOLNAME}@${app}@g" ../conf/nginx.conf sudo cp ../conf/nginx.conf "$nginx_conf" +# Copy and set php-fpm configuration +phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf" +sed -i "s@{POOLNAME}@${app}@g" ../conf/php-fpm.conf +sed -i "s@{DESTDIR}@${DESTDIR}/@g" ../conf/php-fpm.conf +sudo cp ../conf/php-fpm.conf "$phpfpm_conf" + # Save app settings ynh_app_setting_set "$app" password "$password" ynh_app_setting_set "$app" encrypt_key "$deskey" @@ -79,4 +86,5 @@ ynh_app_setting_set "$app" skipped_uris "/" ynh_app_setting_set "$app" protected_uris "/admin/" # Reload services +sudo service php5-fpm restart || true sudo service nginx reload || true diff --git a/scripts/remove b/scripts/remove index 19f22e6..0b0af86 100644 --- a/scripts/remove +++ b/scripts/remove @@ -19,7 +19,9 @@ domain=$(ynh_app_setting_get $app domain) # Delete app directory and configurations sudo rm -rf "/var/www/${app}" +sudo rm -f "/etc/php5/fpm/pool.d/${app}.conf" [[ -n $domain ]] && sudo rm -f "/etc/nginx/conf.d/${domain}.d/${app}.conf" # Reload services +sudo service php5-fpm restart || true sudo service nginx reload || true diff --git a/scripts/restore b/scripts/restore index 4e6184f..bb43be9 100644 --- a/scripts/restore +++ b/scripts/restore @@ -31,6 +31,10 @@ nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf" [[ -f $nginx_conf ]] && ynh_die \ "The NGINX configuration already exists at '${nginx_conf}'. You should safely delete it before restoring this app." +phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf" +[[ -f $phpfpm_conf ]] && ynh_die \ +"The PHP FPM configuration already exists at '${phpfpm_conf}'. + You should safely delete it before restoring this app." # Restore the app files and set permissions sudo cp -a ./sources "$DESTDIR" @@ -42,6 +46,8 @@ ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ./dump.sql # Restore configuration files sudo cp -a ./nginx.conf "$nginx_conf" +sudo cp -a ./php-fpm.conf "$phpfpm_conf" # Reload services +sudo service php5-fpm restart || true sudo service nginx reload || true diff --git a/scripts/upgrade b/scripts/upgrade index 06e5bd1..2897a13 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -48,11 +48,19 @@ nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf" sed -i "s@{PATH}@${path}@g" ../conf/nginx.conf sed -i "s@{LOCATION}@${path:-/}@g" ../conf/nginx.conf sed -i "s@{DESTDIR}@${DESTDIR}@g" ../conf/nginx.conf +sed -i "s@{POOLNAME}@${app}@g" ../conf/nginx.conf sudo cp ../conf/nginx.conf "$nginx_conf" +# Copy and set php-fpm configuration +phpfpm_conf="/etc/php5/fpm/pool.d/${app}.conf" +sed -i "s@{POOLNAME}@${app}@g" ../conf/php-fpm.conf +sed -i "s@{DESTDIR}@${DESTDIR}/@g" ../conf/php-fpm.conf +sudo cp ../conf/php-fpm.conf "$phpfpm_conf" + # Set SSOwat rules ynh_app_setting_set "$app" skipped_uris "/" ynh_app_setting_set "$app" protected_uris "/admin/" # Reload services +sudo service php5-fpm restart || true sudo service nginx reload || true