Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP and nginx is not working #393

Closed
heyanlong opened this issue May 19, 2016 · 35 comments
Closed

PHP and nginx is not working #393

heyanlong opened this issue May 19, 2016 · 35 comments
Labels

Comments

@heyanlong
Copy link

php-fpm

ERROR: unable to bind listening socket for address 127.0.0.1:9000 Invalid argument

Nginx

bind() to 0.0.0.0:81 failed (22: Invalid argument)

by windows 10 preview 14332.rs1_release.160422

@sunilmut
Copy link
Member

This is related to #68. I took a deeper look at 'Nginx'. It first binds to an IPv4 address and then to an IPv6 address (to the same port by default) using the IPV6_V6ONLY option. Unfortunately, we are not able to support the scenario immediately and we have a bug tracking this.
As an alternative, there are couple of options as workarounds:
Edit the default configuration of Nginx to start at different ports on IPv4 and IPv6. Or, use either IPv4 or IPv6. The port configuration for Nginx is stored in '/etc/nginx/sites-enabled/default'. I was able to verify that both these workarounds work and the Nginx server starts successfully on build 14342. We know its not ideal, but at least gets your one step further.
Meanwhile, we have an understanding of the bug on our side, but unfortunately, it might take some time to fix it because of dependencies outside of WSL.

@heyanlong
Copy link
Author

Nginx server starts successfully on build 14342.
But the process will not start work

error.log

2016/05/20 03:18:24 [alert] 98#0: ioctl(FIOASYNC) failed while spawning "worker process" (22: Invalid argument)
2016/05/20 03:18:24 [alert] 98#0: ioctl(FIOASYNC) failed while spawning "worker process" (22: Invalid argument)
2016/05/20 03:18:24 [alert] 98#0: ioctl(FIOASYNC) failed while spawning "worker process" (22: Invalid argument)
2016/05/20 03:18:24 [alert] 98#0: ioctl(FIOASYNC) failed while spawning "worker process" (22: Invalid argument)

@cjgreen
Copy link

cjgreen commented Jun 29, 2016

As mentioned in the following blog post here:

Add the following line to /etc/nginx/nginx.conf:
master_process off;

Then restart nginx:
sudo service nginx restart;

Edit:
This appears to only get nginx working for html files. When trying to load php files through php-fpm I receive the following error:
2016/06/30 15:28:14 [alert] 458#0: *1 connect() failed (22: Invalid argument) while connecting to upstream, client: 127.0.0.1, server: REMOVED, request: "GET /REMOVED HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "REMOVED", referrer: "REMOVED"

@williamn
Copy link

I follow the steps taken as the blog post describe and it works. My nginx is now working.
But I have not successful on FPM

I got this when try to start the PHP FPM

ERROR: failed to retrieve TCP_INFO for socket: Invalid argument

Any idea why?

@sunilmut
Copy link
Member

sunilmut commented Jul 5, 2016

TCP_INFO socket option is currently not supported in WSL, and something we will look into adding. Thanks for the feedback and trying out WSL!

@PeterDraex
Copy link

How can I prevent FPM from using TCP_INFO socket option? Thanks. @sunilmut @williamn

@loutian
Copy link

loutian commented Aug 5, 2016

@cjgreen I got the same error, did you solved it ?

@spagu
Copy link

spagu commented Nov 22, 2016

any solution so far?

@heyanlong
Copy link
Author

@spagu i'm not retry

@stehufntdev
Copy link
Collaborator

After adding signal driven IO support for unix stream sockets, I was able to run nginx locally and load the default site. Also confirmed that the errors were gone from the nginx error log. The fix should be out in insider builds soon.

Can you please confirm if the issues with php are resolved?

@chrisboylan
Copy link

Just updated to 15019 and the PHP problem still persists. Do you have a rough idea of when/which build it will be in?

@stehufntdev
Copy link
Collaborator

Thanks for checking back. The fix didn't make it into the last insider build, but it should be in soon. When that happens we'll include it in the release notes and mark this thread as fixedinsider.

@chrisboylan
Copy link

Semi-success! Upgraded to 15025 and can get php7.0 and nginx to run. phpinfo(); works, but Im having a tough time getting any apps to run. Getting a lot of session writing errors:

FastCGI sent in stderr: "PHP message: PHP Warning: session_write_close(): Failed to write session data (user). Please verify that the current setting of session.save_path is correct (/var/lib/php/sessions)

Tried changing permissions on /var/lib/php/sessions to no avail. Going to try and point it elsewhere.

@stehufntdev
Copy link
Collaborator

Thanks for the update, can you please provide a strace of the failure and repro steps of what you tried?

@chrisboylan
Copy link

Funny thing is that I was checking phpinfo() for details, and it's getting cut off with a really fast timeout that I can't figure out.

The error.log line from nginx is

2017/02/03 01:33:31 [error] 1158#1158: *1 upstream timed out (110: Connection timed out) while reading upstream, client: 127.0.0.1, server: xxxxxx.com, request: "GET /phpinfo.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.0-fpm.sock:", host: "xxxxxx.loc"

The nginx.conf line for PHP on this site is:

location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; fastcgi_read_timeout 120; #shot in dark to end timeout problems (didn't work) }

It's entirely possible its just a bad config on my side somehow. Think I might nuke the WSL install and try again.

@stehufntdev
Copy link
Collaborator

Thanks, please let us know if you hit any other issues. If you do, a strace and repro steps will help us to narrow down the cause.

@lucas-sandery
Copy link

If, like me, you're not on the insider builds but don't want your logs filling up with this:

ERROR: failed to retrieve TCP_INFO for socket: Invalid argument (22)

You can set log_level = alert in /etc/php5/fpm/php-fpm.conf. Obviously not ideal but better than thrashing your SSD.

@dvaknheo
Copy link

I take the same problem as
chrisboylan commented on 3 Feb
and have no solution;

@cute-angelia
Copy link

I take the same problem

but the port 9000 is on ~

@dvaknheo
Copy link

dvaknheo commented Jan 4, 2018

solute it , do not run nginx/php7.0-fpm by manual in command line.
just
sudo service php-7.0-fpm start
sudo service nginx start

@dvaknheo
Copy link

dvaknheo commented Jan 4, 2018

err , i am wrong ,
you must use port than unix file socket , otherwise you php must be run slowlest

@WSLUser
Copy link

WSLUser commented Jan 4, 2018

@dvaknheo when you say port rather than unix file socket, are you referring to SOCK_STREAM that was brought to Windows in build 17063? or the native file socket in WSL? Per this blog, support to WSL should be coming based on this "And, if you are wondering, there is already support for unix socket within Windows Subsystem for Linux (WSL), how does that work with the Windows unix socket implementation? Well, currently, it doesn’t, but stay tuned! " I would imagine that should speed things up a bit once that piece of the pie has been eaten.

@sunilmut
Copy link
Member

sunilmut commented Jan 4, 2018

@DarthSpock - What is the problem that you are facing? Can you please post the repro steps and the output of the following command from the bash prompt cmd.exe /c ver?

The AF_UNIX blog post you are referring to should not have anything to do with the functioning of PHP or nginx within WSL.

@WSLUser
Copy link

WSLUser commented Jan 4, 2018

@sunilmut I wasn't providing an issue. I'm just curious if @dvaknheo has tested performance with the latest Insider build as I'm not able to install Insider builds. I don't normally work with nginx but do play slightly with php. I brought the article up as a case of eventually having a possible performance boost for utilizing Unix sockets vice tcp ports which is currently done in some situations such as using nginx

@sunilmut
Copy link
Member

sunilmut commented Jan 4, 2018

@DarthSpock - Got it, thanks! A forward looking statement, but theoretically speaking (without any measurements), the way things are currently implemented and layered, I would not expect a difference in performance between WSL<->Win32 between TCP loopback and AF_UNIX sockets. Note that this is just in theory.

@CMYK99
Copy link

CMYK99 commented Jan 20, 2018

In nginx error log there is such an error message.
2018/01/21 00:29:22 [emerg] 35#35: io_setup() failed (38: Function not implemented)

@therealkenc
Copy link
Collaborator

therealkenc commented Jan 20, 2018

2018/01/21 00:29:22 [emerg] 35#35: io_setup() failed (38: Function not implemented)

Open a new one for that following CONTRIBUTING.md. Cant tell you if it is a dupe or not because not enough information provided. This issue (bind() to 0.0.0.0:81 failed (22: Invalid argument) was closed a long time ago along with #68.

@sunilmut
Copy link
Member

@YouHeng1 - Yes, please open a new issue for this and also note any functionality issue that you might be observing with nginx.

@dvaknheo
Copy link

yesterday night I upgrade unbuntu (for i want a php7.1 - swoole project). and then my php(both php7.0 and another download php7.2) is broken :(

ERROR: failed to retrieve TCP_INFO for socket: Protocol not available (92)
ERROR: pid 1031, fpm_socket_get_listening_queue(), line 420: failed to retrieve TCP_INFO for socket: Protocol not available (92)

again! ,thought ,i set socket bind to 127.0.0.1:8999 .

maybe ,my win10 need to upgrade 1803ver

////
some month last i install Tencent WeGame and broken my WSL thought I re-install wsl can not solute. then I uninstall WeGame soluted .

but this days my php is not broken , just after upgrade unbuntu .

@heyanlong
Copy link
Author

@dvaknheo
多写代码,少玩游戏
Write more code, play less games

@hparadiz
Copy link

This configuration works in Ubuntu WSL.
Please note that fastcgi_buffering is off.
Without this nginx will wait on PHP forever and never complete.

location ~ \.php$ {
        proxy_set_header X-Forwarded-Proto $scheme;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_buffering off; # This must be here for WSL as of 11/28/2018
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PHP_VALUE "upload_max_filesize = 20M \n post_max_size=21M";
        include /etc/nginx/fastcgi.conf;
}

@Babaktrad
Copy link

This configuration works in Ubuntu WSL.
Please note that fastcgi_buffering is off.
Without this nginx will wait on PHP forever and never complete.

location ~ \.php$ {
        proxy_set_header X-Forwarded-Proto $scheme;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_buffering off; # This must be here for WSL as of 11/28/2018
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
```>         fastcgi_param PHP_VALUE "upload_max_filesize = 20M \n post_max_size=21M";
        include /etc/nginx/fastcgi.conf;

It works for me. It was nearly two weeks that I was involved with this issue! Thanks a lot.

@PhillR
Copy link

PhillR commented Dec 7, 2018

@hparadiz Hero answer, solved a long, outstanding problem for me. Thank you!

@phpcat100
Copy link

thank you.

@tawhidulIKhan
Copy link

It works! thanks @hparadiz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests