addvhost.sh 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. read -p "Write the host name, eg. google:" HOST;
  2. read -p "Write the 1st level domain name without starting dot (.), eg. com.au:" DOMAIN;
  3. mkdir -p /var/www/vhosts/$HOST.$DOMAIN/web
  4. mkdir -p /var/www/vhosts/$HOST.$DOMAIN/logs
  5. mkdir -p /var/www/vhosts/$HOST.$DOMAIN/ssl
  6. groupadd $HOST
  7. useradd -g $HOST -d /var/www/vhosts/$HOST.$DOMAIN $HOST
  8. passwd $HOST
  9. usermod -s /bin/bash $HOST
  10. chown -R $HOST:$HOST /var/www/vhosts/$HOST.$DOMAIN
  11. chmod -R 0775 /var/www/vhosts/$HOST.$DOMAIN
  12. touch /etc/php/7.4/fpm/pool.d/$HOST.$DOMAIN.conf
  13. echo "[$HOST]
  14. user = $HOST
  15. group = $HOST
  16. listen = /run/php/php7.4-fpm-$HOST.sock
  17. listen.owner = www-data
  18. listen.group = www-data
  19. php_admin_value[disable_functions] = exec,passthru,shell_exec,system
  20. php_admin_flag[allow_url_fopen] = off
  21. pm = dynamic
  22. pm.max_children = 5
  23. pm.start_servers = 2
  24. pm.min_spare_servers = 1
  25. pm.max_spare_servers = 3
  26. chdir = /" >> /etc/php/7.4/fpm/pool.d/$HOST.$DOMAIN.conf
  27. service php7.4-fpm restart
  28. ps aux | grep $HOST
  29. touch /etc/nginx/sites-available/$HOST.$DOMAIN
  30. echo "server {
  31. listen 80;
  32. server_name $HOST.$DOMAIN;
  33. location ~ ^/\.well-known/(.*) {}
  34. location / {
  35. return 302 http://www.$HOST.$DOMAIN$request_uri;
  36. }
  37. }
  38. server {
  39. listen 80;
  40. root /var/www/vhosts/$HOST.$DOMAIN/web;
  41. index index.php index.html index.htm;
  42. server_name www.$HOST.$DOMAIN;
  43. include /etc/nginx/conf.d/server/1-common.conf;
  44. access_log /var/www/vhosts/$HOST.$DOMAIN/logs/access.log;
  45. error_log /var/www/vhosts/$HOST.$DOMAIN/logs/error.log warn;
  46. location ~ \.php$ {
  47. try_files \$uri \$uri/ /index.php?$args;
  48. fastcgi_split_path_info ^(.+\.php)(/.+)$;
  49. fastcgi_pass unix:/var/run/php/php7.4-fpm-$HOST.sock;
  50. fastcgi_index index.php;
  51. fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
  52. include fastcgi_params;
  53. }
  54. }" >> /etc/nginx/sites-available/$HOST.$DOMAIN
  55. ln -s /etc/nginx/sites-available/$HOST.$DOMAIN /etc/nginx/sites-enabled/$HOST.$DOMAIN
  56. service nginx restart ; systemctl status nginx.service