Advertisement
Dimazzan

nginx php-fpm

May 25th, 2022 (edited)
965
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. apt update
  3. yes | apt install curl gnupg2 ca-certificates lsb-release debian-archive-keyring
  4. #
  5. curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor \
  6.     | tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
  7. #
  8. echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
  9. http://nginx.org/packages/debian `lsb_release -cs` nginx" \
  10.     | tee /etc/apt/sources.list.d/nginx.list
  11. #
  12. echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" \
  13.     | tee /etc/apt/preferences.d/99nginx
  14. #
  15. apt update
  16. apt install nginx
  17. mkdir /var/www
  18. #
  19. #
  20. #
  21. (cat<<-EOF
  22. server {
  23.     listen 80 default_server;
  24.     listen [::]:80 default_server;
  25.     server_name  _;
  26.     index index.php;
  27.     root /var/www;
  28.  
  29.     location / {
  30.         root /var/www;
  31.         index  index.php;
  32.     }
  33.  
  34.     error_page  404              /404.php;
  35.  
  36.     error_page   500 502 503 504  /50x.html;
  37.     location = /50x.html {
  38.         root   /usr/share/nginx/html;
  39.     }
  40.  
  41.     location ~ \.php\$ {
  42.  
  43.         fastcgi_split_path_info ^(.+\.php)(/.+)\$;
  44.         try_files \$fastcgi_script_name = 404;
  45.         set \$path_info \$fastcgi_path_info;
  46.  
  47.         fastcgi_param PATH_INFO          \$path_info;
  48.         fastcgi_param SCRIPT_FILENAME    \$document_root\$fastcgi_script_name;
  49.         fastcgi_param QUERY_STRING       \$query_string;
  50.         fastcgi_param REQUEST_METHOD     \$request_method;
  51.         fastcgi_param CONTENT_TYPE       \$content_type;
  52.         fastcgi_param CONTENT_LENGTH     \$content_length;
  53.  
  54.         fastcgi_param SCRIPT_NAME        \$fastcgi_script_name;
  55.         fastcgi_param REQUEST_URI        \$request_uri;
  56.         fastcgi_param DOCUMENT_URI       \$document_uri;
  57.         fastcgi_param DOCUMENT_ROOT      \$document_root;
  58.         fastcgi_param SERVER_PROTOCOL    \$server_protocol;
  59.         fastcgi_param REQUEST_SCHEME     \$scheme;
  60.         fastcgi_param HTTPS              \$https if_not_empty;
  61.  
  62.         fastcgi_param GATEWAY_INTERFACE  CGI/1.1;
  63.         fastcgi_param SERVER_SOFTWARE    nginx/\$nginx_version;
  64.  
  65.         fastcgi_param REMOTE_ADDR        \$remote_addr;
  66.         fastcgi_param REMOTE_PORT        \$remote_port;
  67.         fastcgi_param SERVER_ADDR        \$server_addr;
  68.         fastcgi_param SERVER_PORT        \$server_port;
  69.         fastcgi_param SERVER_NAME        \$server_name;
  70.         fastcgi_param REDIRECT_STATUS    200;
  71.  
  72.         fastcgi_pass unix:/run/php/php8.1-fpm.sock;
  73.         fastcgi_index index.php;
  74.         fastcgi_buffers 8 16k;
  75.         fastcgi_buffer_size 32k;
  76.     }
  77. }
  78. EOF
  79. )>/etc/nginx/conf.d/default.conf
  80. #
  81. #
  82. #
  83. (cat<<-EOF
  84. user  www-data;
  85. worker_processes  auto;
  86.  
  87. pid        /var/run/nginx.pid;
  88.  
  89. events {
  90.     worker_connections  1024;
  91. }
  92.  
  93. http {
  94.     include       /etc/nginx/mime.types;
  95.     default_type  application/octet-stream;
  96.     access_log  off;
  97.     sendfile        on;
  98.     keepalive_timeout  65;
  99.     include /etc/nginx/conf.d/*.conf;
  100. }
  101. EOF
  102. )>/etc/nginx/nginx.conf
  103. #
  104. #
  105. #
  106. apt install -y lsb-release ca-certificates apt-transport-https software-properties-common gnupg2
  107. echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/sury-php.list
  108. curl https://packages.sury.org/php/apt.gpg | apt-key add -
  109. apt update
  110. yes | apt install php8.1-{fpm,bz2,curl,intl,xml,cli,mbstring,sqlite3,opcache}
  111. systemctl enable php8.1-fpm
  112. service nginx restart
Advertisement
RAW Paste Data Copied
Advertisement