Install Nginx + PHP-fpm on Ubuntu

Install Nginx + PHP-fpm on Ubuntu

2d22f67b436458034f238a0f0dd00b40.png
Update apt-get
apt-get update -y && apt-get upgrade -y
Install php-fpm
add-apt-repository ppa:ondrej/nginx-mainline
apt install -y software-properties-common
apt -y update


apt install -y php7.4 php7.4-fpm php7.4-cgi php7.4-mysql php7.4-common php7.4-mbstring php7.4-xml php7.4-curl
Setup Nginx
vi /etc/nginx/sites-available/example.com
 
server {
        listen 80;
        root /var/www/html;
        index index.php index.html index.htm index.nginx-debian.html;
        server_name example.com;

        location / {
                try_files $uri $uri/ =404;
        }

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        }

        location ~ /\.ht {
                deny all;
        }
}
 
 ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
 
remove the default configuration
unlink /etc/nginx/sites-enabled/default
Setup folder permission
cd /var/www
chown -R www-data. *
轉換 .htaccess
如果需要轉換的話,可以透過這邊的工具