User Tools

Site Tools


php:buildphpapachenginxfromsource

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

php:buildphpapachenginxfromsource [2017/03/24 05:49] – [Basic Config] adminphp: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
 </code> </code>
 ===== Build and config PHP and Nginx ===== ===== Build and config PHP and Nginx =====
Line 240: Line 241:
  
 restart(){ restart(){
-        stop +    stop 
-        sleep 2 +    sleep 2 
-        start+    start
 } }
  
 rh_status(){ rh_status(){
-        status -p ${pidfile} $prog+    status -p ${pidfile} $prog
 } }
  
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
 </code> </code>
   * step2: Build libmcrypt: libmcrypt-2.5.8.tar.gz   * step2: Build libmcrypt: libmcrypt-2.5.8.tar.gz
Line 286: Line 288:
 </code> </code>
      
-  * step4: Build php-fpm (add option **--enable-fpm**)<code bash>+  * Step4:If you don't find file configure, run script below<code bash> 
 +./buildconf --force 
 +</code>  
 +  * step5: Build php-fpm (add option **--enable-fpm**)<code bash>
 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 /usr/local/php/etc/php.ini cp php.ini-production /usr/local/php/etc/php.ini
 +</code>
 +=== Build PHP7.4 with php-fpm ===
 +<code bash>
 +./configure --prefix=/onec/php7 --with-config-file-path=/onec/php7/etc --with-libdir=lib64 --enable-fpm --disable-rpath --disable-ipv6 --disable-safe-mode --enable-opcache --enable-calendar --enable-bcmath --enable-ftp --enable-soap --enable-shared --enable-mbstring --disable-mbregex --enable-magic-quotes --enable-sockets --with-openssl --with-zlib --with-gd --with-jpeg-dir=/usr --with-png-dir=/usr --with-freetype-dir=/usr --with-zlib-dir=/usr --with-mysql --with-mysqli --without-sqlite3 --without-pdo-sqlite --with-pdo-mysql --with-pear --with-curl --with-curlwrappers --with-mcrypt=/usr/local
 +</code> option **--disable-mbregex** fix error:<code>
 +configure: error: Package requirements (oniguruma) were not met
 </code> </code>
 === 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 missinge package<code>+  - step1: Install missing package<code>
 yum install libevent-devel yum install libevent-devel
 </code> </code>
-  - step2: download memcache<code>+  - step2: Download memcache<code>
 wget http://memcached.org/files/memcached-1.4.22.tar.gz wget http://memcached.org/files/memcached-1.4.22.tar.gz
 </code> </code>
-  - step3: buld and install<code bash>+  - step3: Build and install<code bash>
 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 /var/run/memcached/ mkdir -p /var/run/memcached/
 mkdir -p /var/lock/subsys/ mkdir -p /var/lock/subsys/
 +chown -R nobody.root /var/run/memcached/
 +chown -R nobody.root /var/lock/subsys/
 </code> </code>
   - step2: create script stop, start memcache<code bash>   - step2: create script stop, start memcache<code bash>
Line 694: Line 707:
  
 exit $RETVAL exit $RETVAL
 +</code>
 +==== Memcache Admin ====
 +PHP memcache admin: https://github.com/clickalicious/phpmemadmin
 +
 +Below are steps to install and configure Memcache Admin:
 +  - Step1: download Memcache Admin source to **/onec/www/monitor/**:<code bash>
 +git clone https://github.com/clickalicious/phpmemadmin.git
 +</code> => source will be downloaded to /onec/www/monitor/phpmemadmin
 +  - Step2: Install composer in source directory:<code bash>
 +cd /onec/www/monitor/phpmemadmin
 +curl -sS https://getcomposer.org/installer | /onec/php/bin/php
 +</code>
 +  - Step3: download and install depedency packages<code bash>
 +/onec/php/bin/php composer.phar install
 +</code>
 +  - Step4: Go to directory app and copy .config.dist to .config:<code bash>
 +cd app
 +cp .config.dist .config
 +</code>
 +  - Step5: Change admin password in .config<code json>
 +{
 +  "username": "admin",
 +  "password": "pass",
 +  "timeout": -1,
 +  "cluster": {
 +    "name": "Cluster",
 +    "thresholds": {
 +        "notice": 50,
 +        "warning": 75,
 +        "error": 95
 +    },
 +    "hosts": [
 +      {
 +        "host": "127.0.0.1",
 +        "port": 11211
 +      }
 +    ]
 +  },
 +  "render": {
 +    "auto": true
 +  },
 +  "format": {
 +    "date": "Y-m-dTH:i:s"
 +  },
 +  "updatecheck": false
 +}
 +</code>
 +  - Step6: config nginx with php-fpm for run this website:<code>
 +server {
 +    listen       80;
 +    server_name  memcache.zplay.com;
 +    root   /onec/www/monitor/phpmemadmin/web;
 +
 +    index index.html index.htm index.php;
 +    fastcgi_index  index.php;
 +
 +    access_log /onec/nginx/logs/memcache.access_log;
 +    error_log /onec/nginx/logs/memcache.error_log;
 +
 +    error_page  404              /404.html;
 +    error_page 500 502 503 504  /50x.html;
 +
 +    location ~* "^.+\.(js|ico|gif|jpg|png|css|swf|htc|xml|bmp)$" {
 +        access_log  off;
 +        expires     7d;
 +    }
 +
 +    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's front handler
 +        expires 30d; ## Assume all files are cachable
 +    }
 +    location @handler { ## zend framework uses a common front handler
 +        rewrite / /index.php;
 +    }
 +    location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler
 +        rewrite ^(.*.php)/ $1 last;
 +    }
 +    location ~ \.php$ {
 +      if (!-e $request_filename) { rewrite / /index.php last; }
 +      fastcgi_pass   127.0.0.1:9000;
 +      fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
 +      include        fastcgi_params;
 +    }
 +}
 </code> </code>
 ===== Varnish Cache ===== ===== Varnish Cache =====
Line 985: Line 1083:
 Loaded Configuration File /usr/local/php/etc/php.ini Loaded Configuration File /usr/local/php/etc/php.ini
 </code> </code>
-===== PHP-FPM Config and Optimize ===== 
-**global** config for all pools:<code> 
-[global] 
-; Error log file 
-; If it's set to "syslog", log is sent to syslogd instead of being written 
-; in a local file. 
-; Note: the default prefix is /usr/local/php/var 
-; Default Value: log/php-fpm.log 
-;error_log = log/php-fpm.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 
-</code> 
-**pool** www config:<code> 
-; Choose how the process manager will control the number of child processes. 
-; Possible Values: 
-;   static  - a fixed number (pm.max_children) of child processes; 
-;   dynamic - the number of child processes are set dynamically based on the 
-;             following directives. With this process management, there will be 
-;             always at least 1 children. 
-;             pm.max_children      - the maximum number of children that can 
-;                                    be alive at the same time. 
-;             pm.start_servers     - the number of children created on startup. 
-;             pm.min_spare_servers - the minimum number of children in 'idle' 
-;                                    state (waiting to process). If the number 
-;                                    of 'idle' processes is less than this 
-;                                    number then some children will be created. 
-;             pm.max_spare_servers - the maximum number of children in 'idle' 
-;                                    state (waiting to process). If the number 
-;                                    of 'idle' processes is greater than this 
-;                                    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: 
-;             pm.max_children           - the maximum number of children that 
-;                                         can be alive at the same time. 
-;             pm.process_idle_timeout   - The number of seconds after which 
-;                                         an idle process will be killed. 
-</code> 
-==== PHP-FPM Global Configuration Tweaks ==== 
-Set up **emergency_restart_threshold, emergency_restart_interval and process_control_timeout**. **Default values** for these options **are totally off**, but I think it’s better use these options example like following in **php-fpm.conf**(we can off for performance):<code> 
-emergency_restart_threshold 10 
-emergency_restart_interval 1m 
-process_control_timeout 10s 
-</code>  
-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://jeremymarc.github.io/2013/04/22/nginx-and-php-fpm-for-performance/ 
-=== 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):<code> 
-/etc/php-fpm.d/site.conf 
-/etc/php-fpm.d/blog.conf 
-/etc/php-fpm.d/forums.conf 
-</code>  
-Just example configurations for every pool:  
-  * /etc/php-fpm.d/site.conf<code>  
-[site] 
-listen = 127.0.0.1:9000 
-user = site 
-group = site 
-request_slowlog_timeout = 5s 
-slowlog = /var/log/php-fpm/slowlog-site.log 
-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 
-</code> =>pool **[site] use port 9000** 
-  * /etc/php-fpm.d/blog.conf<code> 
-[blog] 
-listen = 127.0.0.1:9001 
-user = blog 
-group = blog 
-request_slowlog_timeout = 5s 
-slowlog = /var/log/php-fpm/slowlog-blog.log 
-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 
-</code>=>pool **[blog] use port 9001** 
-  * /etc/php-fpm.d/forums.conf<code> 
-[forums] 
-listen = 127.0.0.1:9002 
-user = forums 
-group = forums 
-request_slowlog_timeout = 5s 
-slowlog = /var/log/php-fpm/slowlog-forums.log 
-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 
-</code> =>pool **[forums] use port 9002** 
-So this is just example howto configure multiple different size pools. 
-=== Optimize config === 
-Example Config:<code bash> 
-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 
-</code> 
-**process.max**: 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** 
- 
-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 :<code> 
-pm.max_children = total RAM - (500MB) / average process memory 
-</code> 
-  * To find the average process memory:<code bash> 
-ps -ylC php-fpm --sort:rss | awk '!/RSS/ { s+=$8 } END { printf "%s\n", "Total memory used by PHP-FPM child processes: "; printf "%dM\n", s/1024 }' 
-</code>=> get **total memory** used by all php-fpm process base on basic command **ps -ylC php-fpm**. Then get number of php-fpm processes:<code bash> 
-ps -ylC php-fpm --sort:rss | grep php-fpm | wc -l 
-</code>And the average process memory:<code> 
-Avg Memory = Total Memory/number of process 
-</code> 
-  * 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**: The number of children created on startup. Value must be between pm.min_spare_servers and pm.max_spare_servers.<code> 
-pm.start_servers = (pm.max_spare_servers + pm.min_spare_servers)/2 
-</code> 
-  * **pm.max_requests**: We want to keep it hight to prevent server respawn. Note: **If you have a memory leak** in your PHP code **decrease this value to recreate it quickly and free the memory**. 
  
  
Line 1163: Line 1094:
 session.name = PHPSESSID session.name = PHPSESSID
 session.save_path = "/tmp" session.save_path = "/tmp"
 +upload_max_filesize = 20M
 +post_max_size = 8M
 </code> </code>
 ==== PHP check ==== ==== PHP check ====
php/buildphpapachenginxfromsource.1490334575.txt.gz · Last modified: 2022/10/29 16:15 (external edit)