In today’s era, the Internet is popular. All walks of life driven by the Internet are booming. It is precisely because of the timely grasp of the development opportunities brought by the Internet that a large number of science and technology giants have achieved. They have launched a large number of science and technology products by using Internet technology. While these science and technology products bring convenient and fast life to people, Also slowly changing the world.
Under the background of the great prosperity of science and technology, countless technologies are providing support, and many scientific and technological talents are constantly developing and improving technology; In the IT circle, there are all kinds of practitioners who are constantly promoting and improving various technologies with their own strength. Because of this, they are active in various technology communities and forums, constantly discussing the pits they encounter and debating which language is the best development language.
So there is such a stem“If you want to start a big argument, go
PHPIs the best language in the world”。 It was no one else who caused the stem
2001Official documents for:
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 absolutely nothing to do with me, seriously.
What you want to share today is also the same as“The best language in the world
thinkphpThis word is familiar to many small partners engaged in development, especially
phpDevelopers in the language field;
This is a product developed by Chinese people
phpIntegrated development environment, currently in China
phpThe language field has a great influence. I also have a lot of contacts. After using it for a period of time, I feel pretty good. If you are interested, you can go to the official website to download to try.
There are many excellent cases of integrated development environments like this, such as:
Laravel 、Yii、CodeIgniterWait, it’s all worth trying.
The origin of things
So, as a
JavaProgrammers, why share
PHPWhat about the content? The reason is actually very simple. The company needs it. This reason is 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 mature
phpIntegrated environment, so I
PHPI don’t understand the whole operation process of, and I always have a feeling of floating in the air; So I decided to put aside the integrated environment and deploy one manually
preparation in advance
Web server and web application
webDuring development, it is often mentioned
web applictionThese two words are often ambiguous due to improper definition. Here is a brief introduction:
webServer, usually referred to as
webApplication program, usually refers to the project program developed in programming language;
web application）After development, it needs to be compiled and handed over to
webThe server is running.
Selection of technical scheme
Before the formal deployment of the environment, we need to make some preparations. Just before the so-called east wind, everything must be ready first. usually
phpThere are a variety of mature and stable schemes to choose from for the operation environment of the, and the following are the more mature ones:
PHP + Apache: to
PHPVersion selection is
TS(i.e. thread safe version); this configuration method is more responsible, and the configuration process is easy to make mistakes due to human configuration, but this scheme is more stable;
PHP + Nginx: to
PHPVersion selection is
NTS(i.e. thread unsafe version); this method has less configuration, and has good performance for high concurrency and high load, but its stability is not as good as that
Finalization of scheme details
We choose the latter one here, namely:
PHP + Nginx, so
phpYou have to choose the version of
ntsVersion, the following software is required:
- A computer that works normally,
nginx 1.13+； provide
phpProject operation environment support;
phpAs an interpretative language, it is necessary to install an official language interpreter before it can be interpreted and executed
phpcode; Why choose
ntsVersion, because I chose
NginxAs a server;
- A serious programmer, this is particularly important;
2、3、4Download and decompress the software in and wait for use.
PHP installation configuration
The version we choose here is
php 5.6, downloading
phpYou will find that there are different versions to choose from, as shown in the following figure:
tsThe two versions are the thread safe version and the thread safe version. The two versions are very different:
TS version: thread safe version, which uses a locking mechanism when accessing multiple threads, can ensure that the same data or operation can only be accessed and operated by one thread at the same time point, so as to avoid the problem of dirty data caused by multiple threads operating one data at the same time; But its performance is better than
ntsThe version is poor, which is applicable to scenes with high requirements for data security.
ntsedition: that is, the thread unsafe version does not provide data access protection during multi-threaded access, and multiple threads may operate the same data successively or at the same time, which may cause data disorder; but
ntsThe version has better performance, which is suitable for scenarios that do not pay much attention to data security and need better performance.
PHPPackage, and then unzip it to get the following directory:
PHPThe execution tool can be
CMDCommand execution command
php.exe xxx.phpTo run
php-cgi.exe: PHP interpreter for
CGIImplementation tools provided in
webProjects are always used.
php-win.exe: can also be executed
PHPFile, the difference is that the console opens, but the output is not displayed. It can be used to write programs such as file processing and network services without display interface.
phpDeveloped debugging tools.
phpConfiguration files, including
sessionPath, file size and many other configurations, which need to be modified
phpOpen the file and modify it.
Run PHP CGI
The next step is to
php-cgiRun for later use:
phpOpen under root directory
- Enter command:
php-cgi.exe -b 127.0.0.1:9000 -c "php.ini"；
PHP CGI running problem
php-cgiIf the following problems occur during the command, the system is missing
Visual C++ Redistributable Package, need to download and install;
Visual C++ Redistributable Package
(download link:Download Visual C + + redistributable package）；
64Bit installation package;
3. After downloading, click Install;
4. Return to
php-cgi, the problem has been solved;
In the overall structure of the website,
Web ServerSoftware (e.g
nginx、apache、httpdIt executes the distributor of the content and responds to the request of the client. aboutStatic resource request, they will search under the set path, and then return. If they are not found, they will return an error message; aboutDynamic request, they will pass the data to the corresponding program for processing, and then return the processing result of the program.
Web ApplicationA protocol for data exchange between. Its full name is the common gateway interface（
Common Gateway Interface，CGI）, it can realize the data interaction between browser and server.
CGIIt is not a programming language, nor does it belong to any language, but most languages provide
CGIIs a communication protocol that converts data submitted by users into a
CGIIt is not responsible for data transmission itself. Data transmission depends on
socketCompleted. Every time the user sends
Web ServerThe software will generate a new
CGIInterpreter process (e.g
CGIAfter the script processes the request,
CGIThe interpreter process will be
Web ServerRelease; This process is called
fork-and-executepatternIn high concurrency scenarios, it will be created and destroyed repeatedly
CGIInterpreting the process consumes a lot of server resources, which makes the running performance of the server low. To solve this problem,
FastCGIemerge as the times require.
Web ApplicationA protocol for data exchange between
CGIThe extended version of is more efficient than
FastCGIIt’s like a resident（
CGI, it can be executed all the time. As long as it is activated, it won’t take time to execute every time
FastCGIIt is also language independent and scalable
CGIThe main reason for low performance is
CGIRepeated loading of the interpreter, and
FastCGIThe main behavior is to
CGIThe interpreter process is held in memory and controlled by the
FastCGIThe process manager schedules, so as to improve the running performance.
FastCGIManager, but he’s just a
CGIThe program itself can only parse the request, return the result, and will not manage the process.
FastCGIFor the specific implementation of the protocol, he is responsible for managing a process pool to process data from
WebServer requests, not only that,
PHP-FPMIt is also used for dispatching management
PHP5.3After the version,
PHP-FPMIs built into
PHPThe kernel does not need to be downloaded separately.
php.iniModification of documents,
php-cgiThe process cannot be restarted smoothly. Every time it is modified
php.iniAll need to be restarted
php-cgiProcess; But yes
php-fpmAfter that, for
php.iniA smooth restart can be achieved by modifying. but
windowsIf you want to experience it, you can choose
NginxIt’s a lightweight
WebServer, reverse proxy server, e-mail（
IMAP/POP3/SMTP）The proxy server occupies less memory and has strong concurrency; It was developed by Igor sesoyev, a Russian programmer
2004Open source in.
nginxService configuration file, in which you can
nginxDo many flexible and powerful configurations such as network basic configuration, virtual host binding, reverse proxy and load balancing. The following are some main modules:
1. Global block
The global block is the configuration file from start to finish
eventsPart of the content between blocks, mainly setting some effects
nginxThe configuration instructions run by the server as a whole, so the scope of these instructions is the whole
nginxServer global. These configuration instructions include: user (Group)
pidPath, log path, etc.
2. Events block
eventsThe setting instructions involved in the block include whether to turn on to many
worker processNetwork connection underserialize, whether simultaneous reception is allowedMultiple network connections, which oneEvent driven modelProcessing connection requests, each
worker processCan be supported at the same timeMaximum number of connections.
3. HTTP block
nginxConfiguration is particularly important. Most functions such as agent, cache, log definition, file type, network basic configuration and the configuration of third-party modules can be placed in this module. Including document introduction
mime-typeDefinition, log customization, whether to use
sendfileTransfer files, connection timeout, upper limit of single connection requests, etc.
4. Server block
serverA block is a bound virtual host, which is a group of services (or websites). One
httpThere can be more than one
serverA block can contain multiple
The domain name and port of each bound website are configured in
serverThe other in the block also includes all the data required 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. each
serverA block can contain multiple
serverBlock, based on
nginxThe request string received by the server (for example:
url_string）, except for the virtual host name (or
ip）Strings other than
url_stirngMatch and process specific requests. Address orientation, data caching, and response control are all implemented in this part.
The configuration here is mostly application related.
nginxRoot directory, you can
nginxExecute the operation command;
NginxVersion number of:
- Configuration check:
- Configuration file modification and reload command:
nginx -s reload
- Quick stop or close
nginx -s stop
- Normal stop or shutdown
nginx -s quit
PHP run configuration
fastcgiSupport is therefore needed in
fastcgiConfiguration of; Because the project is used
thinkphpTherefore, it needs to be located in the project
publicDirectory; Therefore, the complete configuration is as follows:
httpIn the module,
serverAdd the following configuration before the block:
serverThe complete configuration of the block is as follows:
nginxAfter configuration, you can access the project through the configured domain name and port; This completes the configuration.
It is not language that chooses people, but people choose language. Learning is the king. If there is a small partner who needs the above complete configuration, you can get it by private mail.
After all, I’m not serious, but I’m talented! Follow me and get more programming technology knowledge.