简体   繁体   中英

Why is my PHP not autostarting with NginX on Windows 10?

I'm running a new install of Windows 10 . I need to create a local testing environment for PHP. I've set up and run NginX/PHP servers on Ubuntu Linux before, but never on Windows. I've installed the NginX and PHP binaries for Windows.

After I've booted up and logged in, if I cd to C:\\nginx and run nginx.exe , the Nginx server starts up and runs fine, and I get the "Welcome to NginX" screen at http://127.0.0.1 .

Then, if I cd to C:\\nginx\\php and run php-cgi.exe -b 127.0.0.1:9000 -cc:/nginx/php/php.ini , the PHP server runs, and I can access http://127.0.0.1/php.info and get the output of php_info(); . So it seems everything is installed okay.

My goal now, is to to have the PHP server autostart when I boot the machine. I downloaded the Non-Sucking Service Manager , and opened a command prompt in Administraror mode, and ran nssm edit nginx . I filled out the screens as follows:

nssm nginx应用程序

nssm nginx详细信息

Then I did the same for PHP:

nssm php应用程序

nssm php详细信息

However, while NginX seems to be starting at boot, PHP does not. After a boot, without manually starting anything at the command line, I get the NginX welcome screen. However, if I try to view the PHP info page, I get the following message:

Unable to connect

Firefox can't establish a connection to the server at 127.0.0.1.

How do I get PHP to autostart on boot?

This is my nginx.conf file:

worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include             mime.types;
    default_type        text/html;
    sendfile            on;
    keepalive_timeout   65;

    server {

        #Uncomment and edit the line below if you want to use a custom domainname
        #server_name    your.domain.com;

        listen          80;
        root            c:/nginx/html;

    location ~ .php$ {
        root html;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME c:/nginx/html/$fastcgi_script_name;
        include fastcgi_params;
    }
    }
}

Your nginx.conf seems OK.

... However, while NginX seems to be starting at boot ...

I wouldn't trust NGINX welcome page, it most likely comes from cache. I also don't trust a service status Running unless there are nginx processes started by nssm.

In my tests both nginx and php services were not started properly.

I needed to set AppNoConsole=1 for both services to make them work.

According to the author(s) this is a known issue with Windows 10 Creators Update.

2017-04-26: Users of Windows 10 Creators Update should use prelease build 2.2.4-101 to avoid an issue with services failing to start. If for some reason you cannot use that build you can also set AppNoConsole=1 in the registry, noting that applications which expect a console window may behave unexpectedly.

You can change this setting via NSSM Service Editor GUI > Process > Console window . Just clear the checkbox and click Edit service. It's done.

The same operation can be done with commands too.

net stop php
net stop nginx

nssm set php AppNoConsole 1
nssm set nginx AppNoConsole 1

net start nginx
net start php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM