当前位置:网站首页>Analysis of PHP environment configuration

Analysis of PHP environment configuration

2022-06-24 05:06:00 User 7426861

PHP As an open source server-side scripting language , stay web It's widely used . If you want to download some open source applications ,github On php Open source software choices are often better than Java even more than . lately , Studied linux Next php Installation , The main experience is as follows .

PHP-INI

php.ini File is php And can only be named as php.ini, It's right php Application global settings file , There are a lot of options , contain php Page usage memory size limit , Upload and download file size limit , Floating point precision, etc .

FPM-PHP

fpm-php(FastCGI ProcessManager) It was originally php Third party package for , stay php5.3.3 It became php Core members of , No need to download and install separately .FastCGI Before the birth of ,web The end forwards a php After the request , Need to reload php.ini, adopt fpm-php establish master process , Received more than one php request , Create child processes to share master Process loaded php.ini Information . install fpm-php after , start-up php In fact, by starting fpm-php.service To achieve .fpm-php and web Communication can be achieved in two ways ,socket and tcp The way , adopt /etc/php-fpm.d/www.conf To configure . The main difference between the two methods is listen The configuration of is different . One is php-fpm.sock, One is the server ip:9000.

socket The way is long connection , Apply to php On the same server as other services

[www]
user = nginx
group = nginx
listen = /run/php-fpm.sock

tcp The way is http Request mode , It is suitable for multi server cluster with high concurrency

[www]
user = nginx
group = nginx
listen = 127.0.0.1:9000

Let's talk about how processes are allocated , In terms of the following configuration ,start_servers=10 explain php The service starts 10 individual worker The child process has been waiting ,min_spare_servers=5 Is the smallest active process .php On at start up 8 A process , If not received web request ,fpm-php It will release some , Finally achieve 5 A process . But not more than max_spare_servers = 35. as for max_children=50, That's static configuration , constant , It's a waste of resources , Always on 50 Processes are waiting there , It's the same even if no one visits the site .

pm.max_children = 50
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 35

Expansion pack,

Install only php Often can not meet the needs of the application software , There are a lot of other extension packages to support php application . for example ,【odbc,common,ima,mongodb,xml etc. 】, However, it should be noted that the following packages are based on pecl Of 【apcu,imagick,goeip,mcrypt,redis,zip,memcache】. especially ,zip Packages need to be specified in particular pecl, Otherwise, the expansion pack installation will not succeed , other pecl Bags can be made from remi Automatically find the response package in the source .

yum install php-common
yum install php-apcu
yum install php-pecl-zip

web Server related configuration

php and web The server nginx,apache We also need to do some association configuration , Add the following to their profile :

nginx:
location ~ .*\.php$
{
    fastcgi_pass  unix:/run/php-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include fastcgi_params;
    try_files $uri = 404;
}
​
apache:
<FilesMatch \.php$>
  SetHandler "proxy:unix:/run/php-fpm.sock|fcgi://localhost"
</FilesMatch>

however ,ubuntu Under the system PHP Application and use apache In the case of servers , Need configuration , Otherwise, vice versa apache The server reported an error and could not be started . That's right php To understand the configuration of , In the future, with the deepening of its research , And write about php Something new .

原网站

版权声明
本文为[User 7426861]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/08/20210824190016533o.html