#! / bin / sh
#
# Author: Till Klampaeckel <till@php.net>
# Credits
# * original script: http://unix.derkeiler.com/Mailing-Lists/FreeBSD/questions/2007-09/msg00468.html
# * improved: http://till.klampaeckel.de/blog/archives/30-PHP-performance-III-Running-nginx.html
# linux start script all inspired by CouchDB's start script (by Noah Slater)
SCRIPT_OK = 0
SCRIPT_ERROR = 1
DESCRIPTION = "php-fcgi super-duper-control thing"
NAME = php-fgcid
SCRIPT_NAME = $ (basename $ 0)
WWW_GROUP = www-data
PHP_CGI = / usr / bin / php-cgi
phpfcgid_users = "user1 user2"
phpfcgid_children = "2"
phpfcgid_tmpdir = "/ tmp"
phpfcgid_requests = "100"
log_daemon_msg () {
echo $ @
}
log_end_msg () {
# Dummy function to be replaced by LSB library.
if test "$ 1"! = "0"; then
echo "Error with $ DESCRIPTION: $ NAME"
fi
return $ 1
}
phpfcgid_start () {
echo "Starting $ NAME with $ phpfcgid_children children (req: $ phpfcgid_requests)."
export PHP_FCGI_CHILDREN = $ phpfcgid_children
export PHP_FCGI_MAX_REQUESTS = $ phpfcgid_requests
for user in $ {phpfcgid_users}; do
socketdir = "$ {phpfcgid_tmpdir} /. fastcgi. $ {user}"
mkdir -p $ {socketdir}
chown $ {user}: $ {WWW_GROUP} $ {socketdir}
chmod 0750 $ {socketdir}
su -m $ {user} -c "$ {PHP_CGI} -b $ {socketdir} / socket &"
done
}
phpfcgid_stop () {
echo "Stopping $ NAME."
pids = `pgrep php-cgi`
pkill php-cgi
}
phpfcgid_status () {
log_daemon_msg "To be implemented: status"
log_end_msg $ SCRIPT_ERROR
}
parse_script_option_list () {
case "$ 1" in
start)
log_daemon_msg "Starting $ DESCRIPTION" $ NAME
if phpfcgid_start; then
log_end_msg $ SCRIPT_OK
else
log_end_msg $ SCRIPT_ERROR
fi
;;
stop)
log_daemon_msg "Stopping $ DESCRIPTION" $ NAME
if phpfcgid_stop; then
log_end_msg $ SCRIPT_OK
else
log_end_msg $ SCRIPT_ERROR
fi
;;
restart | force-reload)
log_daemon_msg "Restarting $ DESCRIPTION" $ NAME
if phpfcgid_stop; then
if phpfcgid_start; then
log_end_msg $ SCRIPT_OK
else
log_end_msg $ SCRIPT_ERROR
fi
else
log_end_msg $ SCRIPT_ERROR
fi
;;
status)
phpfcgid_status
;;
*)
cat << EOF> & 2
Usage: $ SCRIPT_NAME {start | stop | restart | force-reload | status}
EOF
exit $ SCRIPT_ERROR
;;
esac
}
parse_script_option_list $ @
server {
listen 80;
server_name myhost.com;
access_log /var/log/nginx/myhost.com.access.log;
location / {
autoindex on;
root /var/www/myhost.com;
index index.php index.html index.htm;
}
location ~ .php {
include fastcgi_params;
fastcgi_pass unix: /tmp/.fastcgi.www-data/socket;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/myhost.com/$fastcgi_script_name;
}
}
Source: https://habr.com/ru/post/84587/
All Articles