“PHP” does not rely on the integrated environment. Use nginx to manually configure the ThinkPHP running environment


In today’s era, the Internet is very popular. All walks of life driven by the Internet are booming. It is precisely because of the development opportunities brought by the Internet that a large number of science and technology giants have been achieved. They use Internet technology to launch a large number of science and technology products. While these science and technology products bring people convenient and fast life, they are also slowly changing Changing the world.

In the context of the great prosperity of science and technology, there are countless technologies to provide support, and many scientific and technological talents are constantly developing and improving technologies. In the IT circle, there are all kinds of practitioners, who are constantly promoting various technologies with their own strength to improve them. Because of this, they are active in various technology communities and forums On the pit encountered, debating which language is the best development language.

So there’s this stem“If you want to start a big argument, goJavaCommunity discussionPHPIt’s the best language in the world”。 It’s no one else who caused this, it’s justphplanguage2001Official document of the year:

PHP is the best language for web programming, but what about other languages?
Because PHP is the best language ever, ever. It’s fast, very powerful, and free.

So, it has nothing to do with me, seriously.

What we’re going to share today is the same“The best language in the worldPHP”About: it’s aboutthinkphpYes, mentionedthinkphpThis word, many engaged in the development of small partners are not unfamiliar, especiallyphpLanguage developers;
This is a product developed by Chinese peoplephpIntegrated development environment, currently in ChinaphpThe language field has a lot of influence, and I have a lot of contacts. After a period of use, I feel pretty good. If you are interested in friends, you can go to the official website to download to try.

There are many excellent cases of such integrated development environment, such as:Laravel 、Yii、CodeIgniterIt’s worth trying.

The origin of the matter

So, as aJavaWhy do programmers come to sharePHPWhat about the content of the report? The reason is actually very simple. The company needs it. That’s enough. The project is not very big, and the function is relatively simple, so the early development and testing are relatively smooth; but when I finished the project development and deployment, I realized the problem, because the development and deployment are maturephpIntegrated environment, so I’m interested inPHPI don’t know the whole operation process of, and I always feel like I’m floating in the air. Therefore, I decided to set aside the integrated environment and manually deploy onethinkphpThe running environment of the system.

preparation in advance

Web server and web application

webIn development, it is often mentionedweb serverweb applictionThese two words are often ambiguous due to improper definition. Here is a brief introduction

  • Web Server NamelywebServer, usually referred to asApache、Nginx、IIS、Lighttpd、Tomcat、WildflyAnd other software;
  • Web ApplictionNamelywebApplication program usually refers to the project program developed by programming language;

Projects(web application)After the development is completed, it needs to be compiled and submitted to thewebThe server is running.

Selection of technical scheme

Before the environmental deployment starts, we need to make some preparations. As the saying goes, before taking advantage of the east wind, we must not have everything ready. usuallyphpThere are a variety of mature and stable schemes to choose from for the operation environment of the company

  • PHP + Apache: withISAPIOperation modePHPProjects,PHPVersion selected asTSThis method is more responsible for configuration, and the configuration process is easy to make mistakes due to human configuration, but the stability of this scheme is higher;
  • PHP + Nginx: withFAST-CGI/PHP-FPMOperation modePHPProjects,PHPVersion selected asNTS(i.e. thread unsafe version); this way is less configured, and has good performance for high concurrency and high load, but the stability is not as good as thatApache

Finalization of scheme details

We choose the latter one here, namely:PHP + NginxSophpYou have to choose the version ofntsThe following software is required:

  1. A computer that can work normally,windowsOperating system;
  2. nginx 1.13+; providephpProject operation environment support;
  3. thinkphp 5+phpProjects;
  4. php-nts-5.6phpLanguage support,phpAs an interpretive language, it needs to install an official language interpreter to interpret and executephpCode; the reason for choosingntsVersion, because of the choiceNginxAs a server;
  5. This is a very important one;

And then2、3、4In the software download, decompression, waiting to use.

PHP installation configuration

The version we choose here isphp 5.6, DownloadphpYou will find that there are different versions to choose from, as shown in the figure below:

PHPProvidedntsEdition andtsThe two versions are thread safe version and thread safe version

  • TS version: thread safe version, which adopts locking mechanism in multi thread access, can ensure that the same data or operation at the same time point can only be accessed and operated by one thread, so as to avoid the dirty data problem caused by multi thread operation of a data at the same time; but its performance is better thanntsThe version is poor, which is suitable for the scenarios with high data security requirements.
  • ntsedition: that is, the thread unsafe version does not provide data access protection in multithreading access, which may result in multiple threads operating the same data one after another or at the same time, which may cause data confusion; butntsVersion has better performance, which is suitable for scenarios that don’t pay much attention to data security and need better performance.

Article selectionntsedition, clickZipdownloadPHPThen extract the package to get the following directory:

php.exePHPThe execution tool can be used in theCMDCommand execution commandphp.exe xxx.phpTo runPHPDocuments.

php-cgi.exe: PHP interpreter forCGIThe implementation tools provided inwebProjects are always used.

php-win.exe: can also be executedPHPThe difference is that the console will be opened, but the output will not be displayed. It can be used to write programs such as file processing, network service, etc. without displaying interface.

phpdbg.exephpDevelopment of debugging tools.

php.iniphpConfiguration files, includingphpExtended installationsessionPath, file size and many other configurations, if you need to modifyphpOpen the file to modify.


Next, there will bephp-cgiTo be used later:

  1. stayphpOpen in the root directorycmdOrders;
  2. Input command:php-cgi.exe -b -c "php.ini"
  3. php-cgiSo127.0.0.1:9000It’s running;

Running problems of PHP CGI

If it’s runningphp-cgiCommand when the following problems, the system is missingVisual C++ Redistributable Package, need to download and install;

The solution of the problem

1.downloadVisual C++ Redistributable Package
(download link: Download Visual C + + redistributable package);

2. Selection64Bit installation package;

3. After downloading, click Install;

4. Back tocmdRun inphp-cgiThe problem has been solved;


In the overall structure of the website,Web ServerSoftware (e.gnginx、apache、httpdIt is the distributor of the content that responds to the request of the client. aboutStatic resource request, they will search under the set path, and then return. If not, they will return an error messageDynamic request, they will pass the data to the corresponding program for processing, and then return the processing results of the program.


CGIyesWeb ServerAndWeb ApplicationData exchange between a protocol, the full name is the public gateway interface(Common Gateway Interface,CGI)It can realize the data interaction between browser and server.CGIIt’s not a programming language, and it doesn’t belong to any language, but most of them provide support for programmingCGIWe need your support.

CGIIs a communication protocol that converts data submitted by a user into ak-vMy dictionary.CGIIt is not responsible for the transmission of data, data transmission depends on thesocketIt’s done. Every time the user sendsCGIWhen you ask,Web ServerSoftware will generate a new oneCGIInterpreter process (such asphp-cgi.exe), whenCGIAfter the script processes the request,CGIThe interpreter process is executedWeb ServerRelease; this process is called releasefork-and-executepattern.

fork-and-executepatternIn the high concurrency scenario, it will be created and destroyed repeatedlyCGIIt costs a lot of server resources to explain the process, which makes the performance of the server low. To solve this problem,FastCGIemerge as the times require.


FastCGIYesWeb ServerAndWeb ApplicationA protocol for data exchange between computersCGIThe extended version of is more efficient thanCGIIt’s much higher.FastCGIIt’s like a resident(long-live)TypeCGI, it can be executed all the time, as long as it is activated, it will not take time every timeforkonce.

FastCGIIt is also language independent and scalableCGIOpen expansion,CGIThe main reason for low performance isCGIThe interpreter is loaded repeatedly, andFastCGIThe main action is toCGIThe interpreter process remains in memory and is run by theFastCGIProcess manager to schedule, so as to improve the running performance.


PHP-CGIyesPHPOfficially realizedFastCGIManager, but he’s just a managerCGIThe program itself can only parse the request and return the result without managing the process.


PHP-FPMYesPHPLanguage forFastCGIHe is responsible for managing a process pool to deal with the data from theWebServer requests, not only that,PHP-FPMIt is also used for scheduling managementPHPParserphp-cgiManagement procedures of the project.PHP5.3After the release,PHP-FPMIs built intoPHPKernel, do not need to download separately.

aboutphp.iniModification of documents,php-cgiThere is no way to restart the process smoothlyphp.iniThey all need to be restartedphp-cgiProgress; but there isphp-fpmAfter that, forphp.iniYou can achieve a smooth restart by modifying. butphp-fpmstaywindowsIf you want to experience it, you can chooseLinuxEnvironmental Science.

Nginx configuration

NginxIt’s a lightweight oneWebServer, reverse proxy server, e-mail(IMAP/POP3/SMTP)Proxy server, with less memory and strong concurrency, was developed by Russian programmer Igor sassoyev and self-developed2004Open source and open source.

Catalogue introduction

Module introduction

fileconf/nginx.confyesnginxIn the configuration file, you cannginxDo network infrastructure configuration, virtual host binding, reverse proxy, load balancing and many other flexible and powerful configuration, the following are some of the main modules:

1. Global block

Global blocks are configuration files from start to finisheventsBlock between a part of the content, mainly set some impactnginxThe configuration instructions that the server runs as a whole, so the scope of these instructions is the entire servernginxServer global. These configuration instructions include: user (Group)worker processNumberpidPath, log path, etc.

2. Events block

eventsThe setting instructions involved in the block include whether or not to turn on many to manyworker processUnder the network connectionserialize, is simultaneous reception allowedMultiple network connections, which oneEvent driven modelProcessing connection requests, eachworker processCan be supported at the same timeMaximum number of connections.

3. HTTP block

 httpBlock innginxConfiguration is particularly important. Most of the functions such as proxy, cache, log definition, file type, network infrastructure configuration and the configuration of third-party modules can be placed in this module. Including the introduction of documentsmime-typeDefinition, log customization, use or notsendfileTransfer file, connection timeout, single connection request limit, etc.

4. Server block

EachserverA block is a bound virtual host, which is a set of services (or websites). OnehttpThere can be more than one inserver. eachserverBlocks can contain multiplelocationBlock.

The domain name and port of each binding website are configured in theserverThe others in the block also include all the data needed for routing configuration, access device judgment, etc.

5. Location block

It is used to configure the routing of requests and the processing of various pages. eachserverBlocks can contain multiplelocationBlock,locationyesserverBlock, based onnginxThe request string received by the server (for example:server_nameorurl_string), in addition to the virtual host name (orip)For exampleurl_stirngMatching, processing specific requests. Address orientation, data cache, and response control are all implemented in this part.

The configuration here is mostly application related.

Run command

staycmdOpen innginxRoot directorynginxExecute the operation command;

  • seeNginxVersion number of:nginx -V
  • Configuration check:nginx -t
  • start-upnginxstart nginx
  • Configuration file modification reload command:nginx -s reload
  • Quick stop or shutdownNginxnginx -s stop
  • Normal stop or shutdownNginxnginx -s quit

PHP running configuration

nginxfunctionphpProject needsfastcgiTherefore, it needs to be supported in thenginxIntroduced infastcgiBecause the project is usingthinkphpSo you need to position to thepublicTherefore, the complete configuration is as follows:

1. InhttpIn the module,serverAdd the following configuration before the block:

2.serverThe complete configuration of the block is as follows:

3.nginxAfter the configuration is completed, you can access the project through the configured domain name and port; so far, the configuration is complete.


It’s not language that chooses people, it’s people who choose language. Persistence in learning is king. If there is a small partner who needs the above complete configuration, you can get it by private letter.

In the end, I’m not serious, but I’m talented! Pay attention to me and get more knowledge of programming technology.