$ sudo apt-get update -y
$ sudo apt-get install nginx mariadb-server -y
$ sudo service nginx start
$ sudo service mariadb start
$ sudo apt-get install software-properties-common -y
$ sudo add-apt-repository ppa:ondrej/php
$ sudo apt-get update -y
$ sudo apt-get install php7.1 php7.1-fpm php7.4 php7.4-fpm zip unzip -y
$ sudo service php7.1-fpm start && sudo service php7.4-fpm start
$ sudo mkdir /var/www/html/php71
$ sudo mkdir /var/www/html/php74
$ sudo nano /var/www/html/php71/index.php
<?php phpinfo(); ?>
$ sudo cp /var/www/html/php71/index.php /var/www/html/php74/index.php
$ sudo chown -R www-data:www-data /var/www/html/php71
$ sudo chown -R www-data:www-data /var/www/html/php74
$ sudo nano /etc/nginx/sites-available/php71.conf
server {
listen 8071;
root /var/www/html/php71/;
index index.php;
server_name _;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
$ sudo nano /etc/nginx/sites-available/php74.conf
server {
listen 8074;
root /var/www/html/php74/;
index index.php;
server_name _;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
$ sudo ln -s /etc/nginx/sites-available/php71.conf /etc/nginx/sites-enabled/
$ sudo ln -s /etc/nginx/sites-available/php74.conf /etc/nginx/sites-enabled/
$ sudo service nginx restart && sudo service php7.1-fpm restart && sudo service php7.4-fpm restart
$ sudo nano /etc/nginx/sites-available/default
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
#--------------------------------------------------------------------------------------
# The application which only supports php version 7.1
#--------------------------------------------------------------------------------------
# might as well move this: include /var/www/sites.conf
#
location /old {
alias /var/www/old;
try_files $uri $uri/ /index.php$is_args$args;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
}
}
#--------------------------------------------------------------------------------------
# Default PHP
#--------------------------------------------------------------------------------------
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
Nginx config file
server {
listen 9000;
listen [::]:9000;
server_name dev.test;
...
}
Edit %windir%\system32\drivers\etc\hosts
and append:
127.0.0.1 test.dev
Should be accessable at http://test.dev:9000
How to install Nginx + php + MySQL on WSL Windows 10 Nginx running in WSL2 (Ubuntu 20.04) does not serve HTML page to Windows 10 host on another port than port 80