-
-
Save radist2s/c781b34aa7301ed8dbc0 to your computer and use it in GitHub Desktop.
Create php-fmp server and nginx virtual host.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
NGINX_USERNAME="www-data" | |
USER=$1 | |
DIR=`readlink -f $2` | |
NAME=$3 | |
HOSTS_LIST=$4 | |
HELP_TEXT="Usage example: $0 fpm_server_username ~/www/base_site_dir site_pool_name \"sitename.com www.sitename.com\" " | |
if [ -z "$USER" ]; then | |
echo "Username is empty" | |
echo $HELP_TEXT | |
exit | |
fi | |
USERNAME_EXISTS=`grep -e "^$USER:" -o /etc/passwd` | |
if [ -z "$USERNAME_EXISTS" ]; then | |
echo "Username $USER not exists" | |
echo $HELP_TEXT | |
exit | |
fi | |
if [ ! -d "$DIR" ]; then | |
echo "Directory $DIR not exists" | |
echo $HELP_TEXT | |
exit | |
fi | |
if [ -z $NAME ]; then | |
echo "Pool name is empty" | |
echo $HELP_TEXT | |
exit | |
fi | |
if [ -z "$HOSTS_LIST" ]; then | |
echo "Hosts list is empty" | |
echo $HELP_TEXT | |
exit | |
fi | |
SITEDIR="$DIR/$NAME" | |
SITEDIT_ESC=`echo "$SITEDIR" | sed "s/\//\\\\\\\\\//g"` | |
SUDOUSER="root" | |
sudo -u $USER mkdir -p "$SITEDIR/"{tmp,public_html,sessions,logs} | |
NGINX_SITES_AVAILABLE_DIR="/etc/nginx/sites-available" | |
NGINX_SITES_ENABLED_DIR="/etc/nginx/sites-enabled" | |
sudo -u $SUDOUSER cp ./nginx-vhost.bone "$NGINX_SITES_AVAILABLE_DIR/$NAME" | |
sudo -u $SUDOUSER sed -i "s/%POOLNAME%/$NAME/g" "$NGINX_SITES_AVAILABLE_DIR/$NAME" | |
sudo -u $SUDOUSER sed -i "s/%SITEDIR%/$SITEDIT_ESC/g" "$NGINX_SITES_AVAILABLE_DIR/$NAME" | |
sudo -u $SUDOUSER sed -i "s/%HOSTNAME%/$HOSTS_LIST/g" "$NGINX_SITES_AVAILABLE_DIR/$NAME" | |
sudo -u $SUDOUSER ln -s "$NGINX_SITES_AVAILABLE_DIR/$NAME" "$NGINX_SITES_ENABLED_DIR/$NAME" | |
PHPFPM_POOL_DIR="/etc/php5/fpm/pool.d" | |
sudo -u $SUDOUSER cp ./phpfpm-pool.bone "$PHPFPM_POOL_DIR/$NAME" | |
sudo -u $SUDOUSER sed -i "s/%POOLNAME%/$NAME/g" "$PHPFPM_POOL_DIR/$NAME" | |
sudo -u $SUDOUSER sed -i "s/%SITEDIR%/$SITEDIT_ESC/g" "$PHPFPM_POOL_DIR/$NAME" | |
sudo -u $SUDOUSER sed -i "s/%USERNAME%/$USER/g" "$PHPFPM_POOL_DIR/$NAME" | |
usermod -G $USER -a $NGINX_USERNAME |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
upstream backend-%POOLNAME% {server unix:/var/run/php5-%POOLNAME%.sock;} | |
#upstream backend-%POOLNAME% {server 127.0.0.1:9001;} | |
server { | |
listen 80; | |
server_name %HOSTNAME%; | |
root %SITEDIR%/public_html; | |
error_log %SITEDIR%/logs/nginx-error.log; | |
index index.php index.html; | |
charset utf8; | |
location / { | |
#auth_basic "Restricted"; | |
#auth_basic_user_file htpasswd; | |
index index.php index.html index.htm; | |
} | |
location ~* \.(jpg|jpeg|gif|png|ico|css|less|bmp|swf|js|flv|avi|zip|rar|doc|mp4|txt)$ { | |
expires max; | |
add_header Cache-Control public; | |
} | |
if (!-e $request_filename) | |
{ | |
rewrite ^(.+)$ /index.php?q=$1 last; | |
} | |
location ~ \.php$ { | |
include fastcgi_params; | |
fastcgi_buffer_size 128k; | |
fastcgi_buffers 4 256k; | |
fastcgi_busy_buffers_size 256k; | |
client_max_body_size 1m; | |
fastcgi_index index.php; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
fastcgi_pass backend-%POOLNAME%; | |
} | |
location ~ /\.(ht|git) { | |
deny all; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[%POOLNAME%] | |
listen = /var/run/php5-%POOLNAME%.sock | |
#listen = 127.0.0.1:9001 | |
listen.mode = 0666 | |
user=%USERNAME% | |
group=%USERNAME% | |
chdir=%SITEDIR%/public_html | |
#catch_workers_output = yes | |
php_admin_flag[log_errors] = On | |
php_admin_flag[display_errors] = Off | |
php_admin_value[error_reporting] = E_ALL | |
php_admin_value[error_log] = %SITEDIR%/logs/php-error.log | |
php_admin_value[upload_tmp_dir] = %SITEDIR%/tmp | |
php_admin_value[soap.wsdl_cache_dir] = %SITEDIR%/tmp | |
php_admin_value[date.timezone] = Europe/Moscow | |
php_admin_value[session.save_path] = %SITEDIR%/sessions | |
php_admin_value[memory_limit] = 15M | |
pm = dynamic | |
pm.max_children = 5 | |
pm.start_servers = 1 | |
pm.min_spare_servers = 1 | |
pm.max_spare_servers = 1 | |
pm.max_requests = 500 | |
pm.status_path = /status | |
ping.path = /ping | |
php_value[max_file_uploads] = 2 | |
php_value[upload_max_filesize] = "8M" | |
php_value[max_execution_time] = 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment