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, go
PHPIt’s the best language in the world”。 It’s no one else who caused this, it’s just
2001Official 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 world
PHP”About: it’s about
thinkphpThis word, many engaged in the development of small partners are not unfamiliar, especially
This is a product developed by Chinese people
phpIntegrated development environment, currently in China
phpThe 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 a
JavaWhy do programmers come to share
PHPWhat 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 mature
phpIntegrated environment, so I’m interested in
PHPI 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 one
thinkphpThe running environment of the system.
preparation in advance
Web server and web application
webIn 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
Apache、Nginx、IIS、Lighttpd、Tomcat、WildflyAnd other software;
webApplication program usually refers to the project program developed by programming language;
web application）After the development is completed, it needs to be compiled and submitted to the
webThe 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. usually
phpThere are a variety of mature and stable schemes to choose from for the operation environment of the company
PHP + Apache: with
PHPVersion selected as
TSThis 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: with
PHPVersion selected as
NTS(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 that
Finalization of scheme details
We choose the latter one here, namely:
PHP + NginxSo
phpYou have to choose the version of
ntsThe following software is required:
- A computer that can work normally,
nginx 1.13+; provide
phpProject operation environment support;
phpAs an interpretive language, it needs to install an official language interpreter to interpret and execute
phpCode; the reason for choosing
ntsVersion, because of the choice
NginxAs a server;
- This is a very important one;
2、3、4In the software download, decompression, waiting to use.
PHP installation configuration
The version we choose here is
php 5.6, Download
phpYou will find that there are different versions to choose from, as shown in the figure below:
tsThe 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 than
ntsThe 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; but
ntsVersion has better performance, which is suitable for scenarios that don’t pay much attention to data security and need better performance.
PHPThen extract the package to get the following directory:
PHPThe execution tool can be used in the
CMDCommand execution command
php.exe xxx.phpTo run
php-cgi.exe: PHP interpreter for
CGIThe implementation tools provided in
webProjects are always used.
php-win.exe: can also be executed
PHPThe 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.
phpDevelopment of debugging tools.
phpConfiguration files, including
sessionPath, file size and many other configurations, if you need to modify
phpOpen the file to modify.
Run PHP CGI
Next, there will be
php-cgiTo be used later:
phpOpen in the root directory
- Input command:
php-cgi.exe -b 127.0.0.1:9000 -c "php.ini"；
Running problems of PHP CGI
If it’s running
php-cgiCommand when the following problems, the system is missing
Visual C++ Redistributable Package, need to download and install;
The solution of the problem
Visual C++ Redistributable Package
(download link: Download Visual C + + redistributable package);
64Bit installation package;
3. After downloading, click Install;
4. Back to
php-cgiThe problem has been solved;
In the overall structure of the website,
Web ServerSoftware (e.g
nginx、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.
Web 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 programming
CGIWe need your support.
CGIIs a communication protocol that converts data submitted by a user into a
CGIIt is not responsible for the transmission of data, data transmission depends on the
socketIt’s done. Every time the user sends
CGIWhen you ask,
Web ServerSoftware will generate a new one
CGIInterpreter process (such as
CGIAfter the script processes the request,
CGIThe interpreter process is executed
Web ServerRelease; this process is called release
fork-and-executepatternIn the high concurrency scenario, it will be created and destroyed repeatedly
CGIIt 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.
Web ApplicationA protocol for data exchange between computers
CGIThe extended version of is more efficient than
CGIIt’s much higher.
FastCGIIt’s like a resident（
CGI, it can be executed all the time, as long as it is activated, it will not take time every time
FastCGIIt is also language independent and scalable
CGIThe main reason for low performance is
CGIThe interpreter is loaded repeatedly, and
FastCGIThe main action is to
CGIThe interpreter process remains in memory and is run by the
FastCGIProcess manager to schedule, so as to improve the running performance.
FastCGIManager, but he’s just a manager
CGIThe program itself can only parse the request and return the result without managing the process.
FastCGIHe is responsible for managing a process pool to deal with the data from the
WebServer requests, not only that,
PHP-FPMIt is also used for scheduling management
php-cgiManagement procedures of the project.
PHP5.3After the release,
PHP-FPMIs built into
PHPKernel, do not need to download separately.
php.iniModification of documents,
php-cgiThere is no way to restart the process smoothly
php.iniThey all need to be restarted
php-cgiProgress; but there is
php-fpmAfter that, for
php.iniYou can achieve a smooth restart by modifying. but
windowsIf you want to experience it, you can choose
NginxIt’s a lightweight one
WebServer, 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-developed
2004Open source and open source.
nginxIn the configuration file, you can
nginxDo 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 finish
eventsBlock between a part of the content, mainly set some impact
nginxThe configuration instructions that the server runs as a whole, so the scope of these instructions is the entire server
nginxServer global. These configuration instructions include: user (Group)
pidPath, log path, etc.
2. Events block
eventsThe setting instructions involved in the block include whether or not to turn on many to many
worker processUnder the network connectionserialize, is simultaneous reception 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 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 documents
mime-typeDefinition, log customization, use or not
sendfileTransfer file, connection timeout, single connection request limit, etc.
4. Server block
serverA block is a bound virtual host, which is a set of services (or websites). One
httpThere can be more than one in
serverBlocks can contain multiple
The domain name and port of each binding website are configured in the
serverThe 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. each
serverBlocks can contain multiple
serverBlock, based on
nginxThe request string received by the server (for example:
url_string）, in addition to the virtual host name (or
url_stirngMatching, processing specific requests. Address orientation, data cache, and response control are all implemented in this part.
The configuration here is mostly application related.
nginxExecute the operation command;
NginxVersion number of:
- Configuration check:
- Configuration file modification reload command:
nginx -s reload
- Quick stop or shutdown
nginx -s stop
- Normal stop or shutdown
nginx -s quit
PHP running configuration
fastcgiTherefore, it needs to be supported in the
fastcgiBecause the project is using
thinkphpSo you need to position to the
publicTherefore, 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 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.