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, goJava
Community discussionPHP
It’s the best language in the world”。 It’s no one else who caused this, it’s justphp
language2001
Official 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 aboutthinkphp
Yes, mentionedthinkphp
This word, many engaged in the development of small partners are not unfamiliar, especiallyphp
Language developers;
This is a product developed by Chinese peoplephp
Integrated development environment, currently in Chinaphp
The 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、CodeIgniter
It’s worth trying.
The origin of the matter
So, as aJava
Why do programmers come to sharePHP
What 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 maturephp
Integrated environment, so I’m interested inPHP
I 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 onethinkphp
The running environment of the system.
preparation in advance
Web server and web application
web
In development, it is often mentionedweb server
、web appliction
These two words are often ambiguous due to improper definition. Here is a brief introduction
-
Web Server
:Namelyweb
Server, usually referred to asApache、Nginx、IIS、Lighttpd、Tomcat、Wildfly
And other software; -
Web Appliction
:Namelyweb
Application 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 theweb
The 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. usuallyphp
There are a variety of mature and stable schemes to choose from for the operation environment of the company
-
PHP + Apache
: withISAPI
Operation modePHP
Projects,PHP
Version selected asTS
This 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-FPM
Operation modePHP
Projects,PHP
Version 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 + Nginx
Sophp
You have to choose the version ofnts
The following software is required:
- A computer that can work normally,
windows
Operating system; -
nginx 1.13+
; providephp
Project operation environment support; -
thinkphp 5+
;php
Projects; -
php-nts-5.6
;php
Language support,php
As an interpretive language, it needs to install an official language interpreter to interpret and executephp
Code; the reason for choosingnts
Version, because of the choiceNginx
As a server; - This is a very important one;
And then2、3、4
In the software download, decompression, waiting to use.
PHP installation configuration
The version we choose here isphp 5.6
, Downloadphp
You will find that there are different versions to choose from, as shown in the figure below:
PHP
Providednts
Edition andts
The 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 thannts
The version is poor, which is suitable for the scenarios with high data security requirements. -
nts
edition: 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; butnts
Version has better performance, which is suitable for scenarios that don’t pay much attention to data security and need better performance.
Article selectionnts
edition, clickZip
downloadPHP
Then extract the package to get the following directory:
php.exe
:PHP
The execution tool can be used in theCMD
Command execution commandphp.exe xxx.php
To runPHP
Documents.
php-cgi.exe
: PHP interpreter forCGI
The implementation tools provided inweb
Projects are always used.
php-win.exe
: can also be executedPHP
The 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.exe
:php
Development of debugging tools.
php.ini
:php
Configuration files, includingphp
Extended installationsession
Path, file size and many other configurations, if you need to modifyphp
Open the file to modify.
Run PHP CGI
Next, there will bephp-cgi
To be used later:
- stay
php
Open in the root directorycmd
Orders; - Input command:
php-cgi.exe -b 127.0.0.1:9000 -c "php.ini"
; -
php-cgi
So127.0.0.1:9000
It’s running;
Running problems of PHP CGI
If it’s runningphp-cgi
Command 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. Selection64
Bit installation package;
3. After downloading, click Install;
4. Back tocmd
Run inphp-cgi
The problem has been solved;
FastCGI
In the overall structure of the website,Web Server
Software (e.gnginx、apache、httpd
It 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.
CGI
CGI
yesWeb Server
AndWeb Application
Data 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.CGI
It’s not a programming language, and it doesn’t belong to any language, but most of them provide support for programmingCGI
We need your support.
CGI
Is a communication protocol that converts data submitted by a user into ak-v
My dictionary.CGI
It is not responsible for the transmission of data, data transmission depends on thesocket
It’s done. Every time the user sendsCGI
When you ask,Web Server
Software will generate a new oneCGI
Interpreter process (such asphp-cgi.exe
), whenCGI
After the script processes the request,CGI
The interpreter process is executedWeb Server
Release; this process is called releasefork-and-execute
pattern.
fork-and-execute
patternIn the high concurrency scenario, it will be created and destroyed repeatedlyCGI
It costs a lot of server resources to explain the process, which makes the performance of the server low. To solve this problem,FastCGI
emerge as the times require.
FastCGI
FastCGI
YesWeb Server
AndWeb Application
A protocol for data exchange between computersCGI
The extended version of is more efficient thanCGI
It’s much higher.FastCGI
It’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 timefork
once.
FastCGI
It is also language independent and scalableCGI
Open expansion,CGI
The main reason for low performance isCGI
The interpreter is loaded repeatedly, andFastCGI
The main action is toCGI
The interpreter process remains in memory and is run by theFastCGI
Process manager to schedule, so as to improve the running performance.
PHP-CGI
PHP-CGI
yesPHP
Officially realizedFastCGI
Manager, but he’s just a managerCGI
The program itself can only parse the request and return the result without managing the process.
PHP-FPM
PHP-FPM
YesPHP
Language forFastCGI
He is responsible for managing a process pool to deal with the data from theWeb
Server requests, not only that,PHP-FPM
It is also used for scheduling managementPHP
Parserphp-cgi
Management procedures of the project.PHP5.3
After the release,PHP-FPM
Is built intoPHP
Kernel, do not need to download separately.
aboutphp.ini
Modification of documents,php-cgi
There is no way to restart the process smoothlyphp.ini
They all need to be restartedphp-cgi
Progress; but there isphp-fpm
After that, forphp.ini
You can achieve a smooth restart by modifying. butphp-fpm
staywindows
If you want to experience it, you can chooseLinux
Environmental Science.
Nginx configuration
Nginx
It’s a lightweight oneWeb
Server, 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-developed2004
Open source and open source.
Catalogue introduction
Module introduction
fileconf/nginx.conf
yesnginx
In the configuration file, you cannginx
Do 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 finishevents
Block between a part of the content, mainly set some impactnginx
The configuration instructions that the server runs as a whole, so the scope of these instructions is the entire servernginx
Server global. These configuration instructions include: user (Group)worker process
Numberpid
Path, log path, etc.
2. Events block
events
The setting instructions involved in the block include whether or not to turn on many to manyworker process
Under the network connectionserialize, is simultaneous reception allowedMultiple network connections, which oneEvent driven modelProcessing connection requests, eachworker process
Can be supported at the same timeMaximum number of connections.
3. HTTP block
http
Block innginx
Configuration 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-type
Definition, log customization, use or notsendfile
Transfer file, connection timeout, single connection request limit, etc.
4. Server block
Eachserver
A block is a bound virtual host, which is a set of services (or websites). Onehttp
There can be more than one inserver
. eachserver
Blocks can contain multiplelocation
Block.
The domain name and port of each binding website are configured in theserver
The 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. eachserver
Blocks can contain multiplelocation
Block,location
yesserver
Block, based onnginx
The request string received by the server (for example:server_name
orurl_string
), in addition to the virtual host name (orip
)For exampleurl_stirng
Matching, 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
staycmd
Open innginx
Root directorynginx
Execute the operation command;
- see
Nginx
Version number of:nginx -V
- Configuration check:
nginx -t
- start-up
nginx
:start nginx
- Configuration file modification reload command:
nginx -s reload
- Quick stop or shutdown
Nginx
:nginx -s stop
- Normal stop or shutdown
Nginx
:nginx -s quit
PHP running configuration
nginx
functionphp
Project needsfastcgi
Therefore, it needs to be supported in thenginx
Introduced infastcgi
Because the project is usingthinkphp
So you need to position to thepublic
Therefore, the complete configuration is as follows:
1. Inhttp
In the module,server
Add the following configuration before the block:
2.server
The complete configuration of the block is as follows:
3.nginx
After the configuration is completed, you can access the project through the configured domain name and port; so far, the configuration is complete.
Summary
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.