php:buildphpapachenginxfromsource
Differences
This shows you the differences between two versions of the page.
php:buildphpapachenginxfromsource [2017/03/24 05:49] – [Basic Config] admin | php:buildphpapachenginxfromsource [2022/10/29 16:15] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 5: | Line 5: | ||
yum install gcc-c++ | yum install gcc-c++ | ||
yum install automake | yum install automake | ||
+ | yum install make | ||
</ | </ | ||
===== Build and config PHP and Nginx ===== | ===== Build and config PHP and Nginx ===== | ||
Line 240: | Line 241: | ||
restart(){ | restart(){ | ||
- | | + | |
- | sleep 2 | + | sleep 2 |
- | start | + | start |
} | } | ||
rh_status(){ | rh_status(){ | ||
- | | + | |
} | } | ||
Line 278: | Line 279: | ||
yum install libxml2-devel | yum install libxml2-devel | ||
yum install libxslt-devel | yum install libxslt-devel | ||
+ | yum install bison bison-devel | ||
</ | </ | ||
* step2: Build libmcrypt: libmcrypt-2.5.8.tar.gz | * step2: Build libmcrypt: libmcrypt-2.5.8.tar.gz | ||
Line 286: | Line 288: | ||
</ | </ | ||
| | ||
- | * step4: Build php-fpm (add option **--enable-fpm**)< | + | * Step4:If you don't find file configure, run script below< |
+ | ./buildconf --force | ||
+ | </ | ||
+ | * step5: Build php-fpm (add option **--enable-fpm**)< | ||
tar zxvf php-5.3.28.tar.gz | tar zxvf php-5.3.28.tar.gz | ||
cd php-5.3.28 | cd php-5.3.28 | ||
Line 292: | Line 297: | ||
make & make install | make & make install | ||
cp php.ini-production / | cp php.ini-production / | ||
+ | </ | ||
+ | === Build PHP7.4 with php-fpm === | ||
+ | <code bash> | ||
+ | ./configure --prefix=/ | ||
+ | </ | ||
+ | configure: error: Package requirements (oniguruma) were not met | ||
</ | </ | ||
=== Script start php-fpm === | === Script start php-fpm === | ||
Line 563: | Line 574: | ||
===== Memcache ===== | ===== Memcache ===== | ||
==== Build and Install Memcache server ==== | ==== Build and Install Memcache server ==== | ||
- | - step1: Install | + | - step1: Install |
yum install libevent-devel | yum install libevent-devel | ||
</ | </ | ||
- | - step2: | + | - step2: |
wget http:// | wget http:// | ||
</ | </ | ||
- | - step3: | + | - step3: |
tar xvf memcached-1.4.22.tar.gz | tar xvf memcached-1.4.22.tar.gz | ||
cd memcached-1.4.22 | cd memcached-1.4.22 | ||
Line 602: | Line 613: | ||
mkdir -p / | mkdir -p / | ||
mkdir -p / | mkdir -p / | ||
+ | chown -R nobody.root / | ||
+ | chown -R nobody.root / | ||
</ | </ | ||
- step2: create script stop, start memcache< | - step2: create script stop, start memcache< | ||
Line 694: | Line 707: | ||
exit $RETVAL | exit $RETVAL | ||
+ | </ | ||
+ | ==== Memcache Admin ==== | ||
+ | PHP memcache admin: https:// | ||
+ | |||
+ | Below are steps to install and configure Memcache Admin: | ||
+ | - Step1: download Memcache Admin source to **/ | ||
+ | git clone https:// | ||
+ | </ | ||
+ | - Step2: Install composer in source directory:< | ||
+ | cd / | ||
+ | curl -sS https:// | ||
+ | </ | ||
+ | - Step3: download and install depedency packages< | ||
+ | / | ||
+ | </ | ||
+ | - Step4: Go to directory app and copy .config.dist to .config:< | ||
+ | cd app | ||
+ | cp .config.dist .config | ||
+ | </ | ||
+ | - Step5: Change admin password in .config< | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | ] | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | } | ||
+ | </ | ||
+ | - Step6: config nginx with php-fpm for run this website:< | ||
+ | server { | ||
+ | listen | ||
+ | server_name | ||
+ | root / | ||
+ | |||
+ | index index.html index.htm index.php; | ||
+ | fastcgi_index | ||
+ | |||
+ | access_log / | ||
+ | error_log / | ||
+ | |||
+ | error_page | ||
+ | error_page 500 502 503 504 /50x.html; | ||
+ | |||
+ | location ~* " | ||
+ | access_log | ||
+ | expires | ||
+ | } | ||
+ | |||
+ | location / { | ||
+ | index index.html index.php; ## Allow a static html file to be shown first | ||
+ | try_files $uri $uri/ @handler; ## If missing pass the URI to zend framework' | ||
+ | expires 30d; ## Assume all files are cachable | ||
+ | } | ||
+ | location @handler { ## zend framework uses a common front handler | ||
+ | rewrite / /index.php; | ||
+ | } | ||
+ | location ~ .php/ { ## Forward paths like / | ||
+ | rewrite ^(.*.php)/ $1 last; | ||
+ | } | ||
+ | location ~ \.php$ { | ||
+ | if (!-e $request_filename) { rewrite / /index.php last; } | ||
+ | fastcgi_pass | ||
+ | fastcgi_param | ||
+ | include | ||
+ | } | ||
+ | } | ||
</ | </ | ||
===== Varnish Cache ===== | ===== Varnish Cache ===== | ||
Line 985: | Line 1083: | ||
Loaded Configuration File / | Loaded Configuration File / | ||
</ | </ | ||
- | ===== PHP-FPM Config and Optimize ===== | ||
- | **global** config for all pools:< | ||
- | [global] | ||
- | ; Error log file | ||
- | ; If it's set to " | ||
- | ; in a local file. | ||
- | ; Note: the default prefix is / | ||
- | ; Default Value: log/ | ||
- | ;error_log = log/ | ||
- | |||
- | ; Log level | ||
- | ; Possible Values: alert, error, warning, notice, debug | ||
- | ; Default Value: notice | ||
- | ;log_level = notice | ||
- | |||
- | ; The maximum number of processes FPM will fork. This has been design to control | ||
- | ; the global number of processes when using dynamic PM within a lot of pools. | ||
- | ; Use it with caution. | ||
- | ; Note: A value of 0 indicates no limit | ||
- | ; Default Value: 0 | ||
- | ; process.max = 128 | ||
- | </ | ||
- | **pool** www config:< | ||
- | ; Choose how the process manager will control the number of child processes. | ||
- | ; Possible Values: | ||
- | ; | ||
- | ; | ||
- | ; | ||
- | ; | ||
- | ; | ||
- | ; be alive at the same time. | ||
- | ; | ||
- | ; | ||
- | ; state (waiting to process). If the number | ||
- | ; of ' | ||
- | ; number then some children will be created. | ||
- | ; | ||
- | ; state (waiting to process). If the number | ||
- | ; of ' | ||
- | ; number then some children will be killed. | ||
- | ; ondemand - no children are created at startup. Children will be forked when | ||
- | ; new requests will connect. The following parameter are used: | ||
- | ; | ||
- | ; can be alive at the same time. | ||
- | ; | ||
- | ; an idle process will be killed. | ||
- | </ | ||
- | ==== PHP-FPM Global Configuration Tweaks ==== | ||
- | Set up **emergency_restart_threshold, | ||
- | emergency_restart_threshold 10 | ||
- | emergency_restart_interval 1m | ||
- | process_control_timeout 10s | ||
- | </ | ||
- | What this mean? So if **10 PHP-FPM child** processes exit with SIGSEGV or SIGBUS within 1 minute*then **PHP-FPM restart automatically**. This configuration also **sets 10 seconds time limit for child processes to wait for a reaction** on signals from master. | ||
- | (In some case, the php-fpm child processes full memory and can't process the request, these configurations will automatically restart the php-fpm child processes) | ||
- | ==== PHP-FPM Pools Configuration ==== | ||
- | refer: http:// | ||
- | === Basic Config === | ||
- | Default php-fpm will use pool **[www]** to configuration for all site. In advance, it’s possible to use **different pools** for different sites and **allocate resources very accurately** and even use **different users and groups for every pool**. Following is just example configuration files structure for PHP-FPM pools for three different sites (or actually three different part of same site):< | ||
- | / | ||
- | / | ||
- | / | ||
- | </ | ||
- | Just example configurations for every pool: | ||
- | * / | ||
- | [site] | ||
- | listen = 127.0.0.1: | ||
- | user = site | ||
- | group = site | ||
- | request_slowlog_timeout = 5s | ||
- | slowlog = / | ||
- | listen.allowed_clients = 127.0.0.1 | ||
- | pm = dynamic | ||
- | pm.max_children = 5 | ||
- | pm.start_servers = 3 | ||
- | pm.min_spare_servers = 2 | ||
- | pm.max_spare_servers = 4 | ||
- | pm.max_requests = 200 | ||
- | listen.backlog = -1 | ||
- | pm.status_path = /status | ||
- | request_terminate_timeout = 120s | ||
- | rlimit_files = 131072 | ||
- | rlimit_core = unlimited | ||
- | catch_workers_output = yes | ||
- | env[HOSTNAME] = $HOSTNAME | ||
- | env[TMP] = /tmp | ||
- | env[TMPDIR] = /tmp | ||
- | env[TEMP] = /tmp | ||
- | </ | ||
- | * / | ||
- | [blog] | ||
- | listen = 127.0.0.1: | ||
- | user = blog | ||
- | group = blog | ||
- | request_slowlog_timeout = 5s | ||
- | slowlog = / | ||
- | listen.allowed_clients = 127.0.0.1 | ||
- | pm = dynamic | ||
- | pm.max_children = 4 | ||
- | pm.start_servers = 2 | ||
- | pm.min_spare_servers = 1 | ||
- | pm.max_spare_servers = 3 | ||
- | pm.max_requests = 200 | ||
- | listen.backlog = -1 | ||
- | pm.status_path = /status | ||
- | request_terminate_timeout = 120s | ||
- | rlimit_files = 131072 | ||
- | rlimit_core = unlimited | ||
- | catch_workers_output = yes | ||
- | env[HOSTNAME] = $HOSTNAME | ||
- | env[TMP] = /tmp | ||
- | env[TMPDIR] = /tmp | ||
- | env[TEMP] = /tmp | ||
- | </ | ||
- | * / | ||
- | [forums] | ||
- | listen = 127.0.0.1: | ||
- | user = forums | ||
- | group = forums | ||
- | request_slowlog_timeout = 5s | ||
- | slowlog = / | ||
- | listen.allowed_clients = 127.0.0.1 | ||
- | pm = dynamic | ||
- | pm.max_children = 10 | ||
- | pm.start_servers = 3 | ||
- | pm.min_spare_servers = 2 | ||
- | pm.max_spare_servers = 4 | ||
- | pm.max_requests = 400 | ||
- | listen.backlog = -1 | ||
- | pm.status_path = /status | ||
- | request_terminate_timeout = 120s | ||
- | rlimit_files = 131072 | ||
- | rlimit_core = unlimited | ||
- | catch_workers_output = yes | ||
- | env[HOSTNAME] = $HOSTNAME | ||
- | env[TMP] = /tmp | ||
- | env[TMPDIR] = /tmp | ||
- | env[TEMP] = /tmp | ||
- | </ | ||
- | So this is just example howto configure multiple different size pools. | ||
- | === Optimize config === | ||
- | Example Config:< | ||
- | process.max = 15 | ||
- | pm.max_children = 100 | ||
- | pm.start_servers = 10 | ||
- | pm.min_spare_servers = 5 | ||
- | pm.max_spare_servers = 15 | ||
- | pm.max_requests = 1000 | ||
- | </ | ||
- | **process.max**: | ||
- | |||
- | The configuration variable **pm.max_children** controls the maximum amount of FPM processes that can ever run at the same time. This value can be calculate like this :< | ||
- | pm.max_children = total RAM - (500MB) / average process memory | ||
- | </ | ||
- | * To find the average process memory:< | ||
- | ps -ylC php-fpm --sort:rss | awk ' | ||
- | </ | ||
- | ps -ylC php-fpm --sort:rss | grep php-fpm | wc -l | ||
- | </ | ||
- | Avg Memory = Total Memory/ | ||
- | </ | ||
- | * Why **500MB** ? Depends **of what is running on your system**, but you want to keep memory for nginx (about 20MB), MySql and others services. | ||
- | Other configs: | ||
- | * **pm.start_servers**: | ||
- | pm.start_servers = (pm.max_spare_servers + pm.min_spare_servers)/ | ||
- | </ | ||
- | * **pm.max_requests**: | ||
Line 1163: | Line 1094: | ||
session.name = PHPSESSID | session.name = PHPSESSID | ||
session.save_path = "/ | session.save_path = "/ | ||
+ | upload_max_filesize = 20M | ||
+ | post_max_size = 8M | ||
</ | </ | ||
==== PHP check ==== | ==== PHP check ==== |
php/buildphpapachenginxfromsource.txt · Last modified: 2022/10/29 16:15 by 127.0.0.1