“PHP” takes nginx and PHP CGI as examples, and installs nginx and PHP CGI as windows system services


In the above, we usednginx + php-cgi To configurethinkphpRunning environment, the project has been successfully run, can be very happy developmentphpProject.

However, it is not easy to rest assured. At this time, the project environment has the following several aspectsproblem

  1. Every time you turn on the computer, you have to run all the software environment again, because the running of the software stops after the shutdown. When you restart, you do not restart with the start of the operating system;
  2. It is too cumbersome to run these software again every time. If it is developed locally, it can be tolerated, but it can be tolerated when it is deployed on the server? Obviously not.
  3. Once an exception occurs during project operation, it will causephp-cgiStop running, which is an obstacle to both developing and online projects, and must be overcome;
  4. aboutphp.iniModification cannot be restarted smoothly. Every time you modifyphpConfiguration, you have to restartphp-cgi


If thenginxandphp-cgiregister aswindowsSystem services, set boot up; thisnginxandphp-cgiAs a system service, it can run continuously, and it can be started with the system when it is turned on; then, it can be used as a system service to run continuouslywindowsIn the task managernginxServices andphp-cgiService management.

holdnginxandphp-cgiregister aswindowsSystem service needsWinSWandxxfpmSo, wefirstTo download these two programs, the download address is as follows:

Download winsw and xxfpm

downloadSelect the corresponding installation package according to your own operating systemxxfpm, download it directly, because onlywindowsEdition;

aboutWinSWFor different.netVersion, provides different installation packages, here choose.NET4The version is good;

then, decompress the downloaded file for use in the next step.


WinSWIs a can be used for packaging and management as wellWindowsService Custom process tools can be used forwindowsIt is essentially an executable binary file running in thewindowsUnder the system.

WinSWThe management function of system service is the same as that in Windows Task Manager2.xstartWinSWEntrusted togithubPlatform; after downloading and decompressing, theExecutable operation commandAs follows:

  • installInstall services toWindowsIn the service controller;
  • uninstallFrom installedWindowsService unloading in service controller;
  • startStart the installed Service;
  • stopStop the service that has been started;
  • restartRestart the service; if the service is not currently running, this command will start the service;
  • statusCheck the current status of the service;

The running format of the command

The command needs to be inWinSW.exeCan be executed in the directory becauseWinSWThe initial name isWinSW.exeSo you should add the process name before the command. For example, the complete command to install the service is:winsw install; (suffix.exeCan be omitted)

Name modification is supported

WinSW.exeSupport modifying names, such asnginxIts name can be changed to:nginx-service.exe;stayphpThe name can be changed tophp-cgi-service.exe;

XML configuration file

WinSWThe configuration function of service management needs XML file to complete, and the name of XML file of each process needsWinSWThe name of the process is the same; ifWinSW.exeChanged tonginx-service.exe, corresponding toxmlThe file name is to be modified tonginx-service.xml

WinSWProvides the initialxmlFile example, yesminiVersion and full version, respectivelysample-minimal.xmlandsample-allOptions.xmlWinSW xmlSample files for are as follows:

XML configuration entry

  • idFor identificationWindowsInternal serviceIDThis value must be unique among all services installed in the system and should consist entirely of alphanumeric characters.
  • nameThe display name of the service can contain spaces and other characters, but the name should not be too long.
  • descriptionDescription of the service, which will be displayed inWindowsService manager.
  • executableSpecify the executable to start, the file path can be absolute, or you can only specify the executable name and search from itPATH
  • startmodeThis element specifiesWindowsThe startup mode of the service. The default value isAutomatic, which can be one of the following values:Boot,System,AutomaticorManual
  • delayedAutoStartIfAutomaticIf the boot mode is defined, this Boolean option enables delayed start mode. Note that this startup mode will not apply to earlier thanWindows 7andWindows Server 2008OldWindowsedition.
  • dependOf other services that this service depends onIDYou can use multiple elements to specify multiple dependencies. For example:<depend>Eventlog</depend><depend>W32Time</depend>
  • loggingThis option is optional and can be used to set the log path, for example:< logpath > log path
  • argumentSpecifies the parameters to pass to the executable,WinSWEach quotation mark is enclosed in quotation marks if necessary<argument>Do not use quotation marks in quotation marks to avoid double quotation marks.
  • stopargument/stopexecutableUse to specify the stop parameters and the action to perform when stopping.

Register nginx service

RightWinSWWith enough understanding, you can start to startnginxregister asWindowsService. Here are the detailed steps:

1. Download theWinSW.exeCopy to nginx root and rename tonginx-service.exe

2. In the same level directory, create a new onexmlFile namednginx-service.xml, innginx-service.xmlEnter the following contents in the file and save them;

3. Innginx-service.exeRun incmd, enter the command:

  • nginx-service.exe install
  • net start nginx-service.exe

So far,nginx-service.exeIt not only successfully registered, but also ran successfully.

Register PHP CGI service

registerphp-cgiServices not only needWinSW.exeWe need more supportxxfpmSupport. Therefore, previously downloadedxxfpmUsed here; registerphp-cgiThe detailed steps of the service are as follows:

1. Download thexxfpmOfbinDirectory, there are three files, respectivelypthreadGC2.dll、xxfpmandxxfpm.exeWhat is needed ispthreadGC2.dll、xxfpm.exe

2. handlepthreadGC2.dll、xxfpm.exeCopy tophpLinguisticroot directoryBelow, andphp-cgi.exe The same level;

3. DownloadWinSW.exeCopy toNginxUnder the root directory and rename tophp-cgi-service.exe

4. In the same level directory, create a new onexmlFile, namedphp-cgi-service.xml, inphp-cgi-service.xmlInput the following contents into the file and save it;

3. inphp-cgi-service.exeRun incmd, enter the command in turn:

  • php-cgi-service.exe install
  • net start php-cgi-service.exe

So far,php-cgi-service.exeIt not only successfully registered, but also ran successfully. aboutnginxYou can also do similar operations to install the system service to realize the boot up.

It’s over. I’m not serious, but I’m talented! Get more technology, I pay attention to it.