17

I installed Windows Subsystem Ubuntu shell recently and shifted all of my development from XAMPP to nginx and php7.0-fpm installed through ubuntu windows subsystem.

The problem i am facing is that php files load extremly slower. For a test I simply put

<?php phpinfo(); ?>

in a file and executed it. It literally took the system two minutes to return the reply. I have debugged a lot but could not find any solution.

I am running nginx through nginx server blocks and have setup my local domains.

I am sure that php is slower by observing that if i load a static file i.e a txt or html files, it loads blazingly fast.

Below are my sites enabled files and nginx conf file ..

Sites Enabled

server {
    listen 80 ;
    listen [::]:80;

    root /mnt/c/xampp/htdocs/doit/;
    index index.html index.php;

    server_name doit.dev www.doit.dev;
    error_log /var/log/nginx/error.log;
    location / {
        try_files $uri $uri/ =404;
    }
    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_read_timeout 120;
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    location ~ /\.ht {
        deny all;
    }   
}

Nginx Conf File:

user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}


#mail {
#   # See sample authentication script at:
#   # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
# 
#   # auth_http localhost/auth.php;
#   # pop3_capabilities "TOP" "USER";
#   # imap_capabilities "IMAP4rev1" "UIDPLUS";
# 
#   server {
#       listen     localhost:110;
#       protocol   pop3;
#       proxy      on;
#   }
# 
#   server {
#       listen     localhost:143;
#       protocol   imap;
#       proxy      on;
#   }
#}

Error logs for both nginx and php-fpm working, nothing being logged against errors.

1
  • Note: starting June 2019, WSL 2 is coming, and brings considerable performance improvements.
    – VonC
    May 6, 2019 at 20:50

2 Answers 2

48

Using windows 10 v1803, and nginx & php7 fpm via WSL.

Changing listen to 127.0.0.1:9000 doesn't work for me.

After spending hours of googling, I found: https://github.com/Microsoft/WSL/issues/2100

i.e. Add

fastcgi_buffering off;

to nginx.conf, and save my day.

4
  • 3
    This saved my bacon! Thank you! Jun 19, 2018 at 7:55
  • 2
    Thank you so much. I was starting to pull my hair. Sep 18, 2018 at 14:37
  • I put this parameter along side my other php fastcgi params. Works great! Thank you so much!
    – JustinP
    Sep 20, 2018 at 13:25
  • 1
    Saved my bacon also! Jan 15, 2019 at 22:16
23
+100

Sorted this out, pasting for any other enthusiast working with ubuntu on windows subsystem.

The default Nginx and php setups are going to use a unix:socket, but that’s not going to work for WSL. Also, WSL uses a lightweight init system and services are not going to start automatically for Nginx, PHP, MySQL, etc.


Edit /etc/nginx/sites-available/example.com.conf

comment out fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;

and add fastcgi_pass 127.0.0.1:9000;


Edit /etc/php/7.0/fpm/pool.d/www.conf

comment out listen = /var/run/php/php7.0-fpm.sock;

and add listen = 127.0.0.1:9000;


It will fix all of your issues.

4
  • 1
    After restarting nginx and php-fpm7.0 it all worked out well, thank you - saved my day! Feb 9, 2018 at 13:47
  • 1
    This would be the correct approach, but a missing feature is currently preventing this setup from working whatsoever. My php7.2-fpm.log file is full of ERROR: failed to retrieve TCP_INFO for socket: Protocol not available (92) and no pages are loading. I thought it was working initially because I forgot to restart nginx and it was still using the Unix socket. The answer is correct, but the WSL team needs to fix the issue before it will work properly.
    – SeinopSys
    Mar 11, 2018 at 18:04
  • 1
    Thank you very much that worked straight away! Amazing!
    – Piotr Kula
    Apr 4, 2018 at 15:28
  • ERROR: unable to bind listening socket for address '127.0.0.1:9000': Permission denied (13) even when using sudo on php-fpm7.2. nmap localhost also fails which may be related
    – Jonathan
    Apr 23, 2019 at 1:09

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.