Install Nginx/PHP-FPM on Fedora 29/28, CentOS/RHEL 7.5/6.10 - Comment Page: 5

This is guide howto install Nginx with PHP 7.2.12 and PHP-FPM on Fedora 29/28/27, CentOS 7.5/6.10 and Red Hat (RHEL) 7.5/6.10. PHP-FPM is easier to use and configure than FastCGI and some tests says that PHP-FPM is even much more efficient than FastCGI. Nginx (engine x) is a robust, small and high performance http server, reverse proxy server and also mail proxy server. PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with some additional features useful for sites of any size, especially busier sites. 1. Install Nginx, PHP 7.2.12 and PHP-FPM on Fedora 29/28/27, CentOS 7.5/6.10, Red Hat (RHEL) 7.5/6.10 [inttf_post_ad1] 1.1 Change to root...

198 comments on “Install Nginx/PHP-FPM on Fedora 29/28, CentOS/RHEL 7.5/6.10 - Comment Page: 5

1 3 4 5 6
    1. I have enabled remi and remi-php55 and still am not getting any packages for php-fpm or php-common – centos 6.5 and I am tearing my hair out.

      The last attempt of an install brought up the package errors but still showed me an nginx page on the site FE, more frustrating that a straight up fail ;)

      Any help or guidance you can give?

      Reply
      • Hi bungle,

        Could you post those errors here and output of following commands:

        
        yum --enablerepo=remi,remi-php55 repolist
        
        yum --enablerepo=remi,remi-php55 list all |grep -e php-fpm -e php-common
        
        Reply
    2. Please could you tell me how to set up Drupal 7 clean url for above configuration. Centos, Nginx, php-fp, and Drupal 7
      thank you!

      Reply
    3. Hi, thanks so much !!!

      BIG help, went smooth

      I am happy to try nginx, it is very fast !!! indeed !!!

      Ps:I am looking for a job, if you can help me, please do, I have a family and I am not ashamed to ask for help. I got a kid now and things in Brazil are tuff :(
      thks again

      Reply
    4. Hi, When i updated to php 5.5.12 after that my site facing slow processing.

      I already tried to uninstall php 5.5.12 and installed lower version still nothing comes good. Please help me out.

      php-fpm taking 20% process of each pool process.

      Total cpu usage is 80-95% us now.

      before it was low. load went 15-min 5 to 30 .

      Reply
      • Hi tom,

        I just checked PHP 5.5.12 changelog and there is not big changes on PHP-FPM. Problem might be also some other PHP package than FPM. It’s is of course hard to say without seeing/testing your config files and PHP scripts. Strange thing is that, if you downgraded older versions and same problem still exists.

        Did you changed any configs?
        Is it possible to reboot your server? Normally reboot is not of course needed, but sometimes it’s good to see what happens when every services is restarted.

        Reply
    5. I did rebooted 2 times. I uninstalled-installed php 10 times.

      I didn’t changed any config.

      okay. Here is my php-fpm.conf


      [site]
      listen = 127.0.0.1:9000
      user = nginx
      group = nginx
      request_slowlog_timeout = 5s
      slowlog = /var/log/php-fpm/slowlog-site.log
      listen.allowed_clients = 127.0.0.1
      pm = dynamic
      pm.max_children = 24
      pm.start_servers = 8
      pm.min_spare_servers = 8
      pm.max_spare_servers = 20
      pm.max_requests = 20000
      listen.backlog = -1
      pm.status_path = /status
      request_terminate_timeout = 300s
      rlimit_files = 131072
      rlimit_core = unlimited
      catch_workers_output = yes
      env[HOSTNAME] = $HOSTNAME
      env[TMP] = /tmp
      env[TMPDIR] = /tmp
      env[TEMP] = /tmp

      nginx config


      server {
      client_max_body_size 100M;
      listen 80;
      server_name example.com;
      access_log off;
      error_log /var/log/nginx/example.error.log;
      root /home/public_html;
      index index.php index.htm index.html;
      error_page 404 /404.php;
      location /404.php {
      root /home/public_html;
      allow all;
      limit_rate 150k;
      }

      location / {
      index index.php index.html index.htm;
      try_files $uri $uri/ /index.php?q=$uri&$args;

      rewrite ^/manga/feed/$ /rss.php last;
      rewrite ^/manga/(.*)/feed/$ /rss.php?series=$1 last;
      rewrite ^/manga/(.*)/feed$ /rss.php?series=$1 last;
      rewrite ^/([^/.]+)/([^/.]+)/([0-9]+)(/?)$ /index.php?manga=$1&chapter=$2&page=$3 last;
      rewrite ^/([^/.]+)/([^/.]+)(/?)$ /index.php?manga=$1&chapter=$2 last;
      }
      location /directory/ {
      index index.php index.html;
      try_files $uri $uri/ /index.php?q=$uri&$args;
      }
      location /favicon.ico { access_log off; log_not_found off; }
      location ~* \.(jpg|jpeg|gif|png)$ {
      access_log off;
      log_not_found off;
      expires 360d;
      }

      location ~ /\. {
      access_log off;
      log_not_found off;
      deny all;
      }

      location ~ .php$ {
      try_files $uri =404;
      fastcgi_pass 127.0.0.1:9000;
      fastcgi_read_timeout 30000;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME /home/public_html$fastcgi_script_name;
      include fastcgi_params;
      }
      }

      Reply
    6. I’m using OMV 1.4 version.

      WordPress with Kommiku.

      High traffic Site.

      sar says before update php load was only 3-5 == 15-min and for 1 min 1-2 .

      After update load is 30 == 1 min and 15 min 31

      Reply
      • Hi tom,

        Thank you! Your configs looks totally okay. I can’t say directly what is wrong/problem, but here is a few additional questions to get more background information about this situation:

        Did you updated from PHP 5.5.11 to PHP 5.5.12?

        Do you have any caching enabled (nginx, apc, memcache, etc.)? If yes, is it working normally?

        Do you see any (strange) errors on nginx, php-fpm, db or other logs?

        Could you also post output of following commands:

        
        uname -a
        
        rpm -qa php\* mysql\* Maria\* maria\* |sort
        
        Reply
    7. I’m using Centos 6.5

      Yes, Now i can’t re-installed 5.5.11 its not available :(
      Its give me latest version.

      Result of uname -a


      Linux sd-55593 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

      Result of 2nd command

      mysql-5.5.37-1.el6.remi.x86_64
      mysql-devel-5.5.37-1.el6.remi.x86_64
      mysql-libs-5.5.37-1.el6.remi.x86_64
      mysql-server-5.5.37-1.el6.remi.x86_64
      php-cli-5.5.12-1.el6.remi.x86_64
      php-common-5.5.12-1.el6.remi.x86_64
      php-fpm-5.5.12-1.el6.remi.x86_64
      php-gd-5.5.12-1.el6.remi.x86_64
      php-mbstring-5.5.12-1.el6.remi.x86_64
      php-mcrypt-5.5.12-1.el6.remi.x86_64
      php-mysqlnd-5.5.12-1.el6.remi.x86_64
      php-pdo-5.5.12-1.el6.remi.x86_64
      php-pear-1.9.4-27.el6.remi.noarch
      php-pecl-apcu-4.0.4-1.el6.remi.5.5.x86_64
      php-pecl-igbinary-1.1.2-0.5.git3b8ab7e.el6.remi.1.x86_64
      php-pecl-jsonc-1.3.5-1.el6.remi.5.5.x86_64
      php-pecl-memcache-3.0.8-2.el6.remi.5.5.x86_64
      php-pecl-memcached-2.2.0-2.el6.remi.5.5.x86_64
      php-pecl-mongo-1.5.2-1.el6.remi.5.5.x86_64
      php-pecl-msgpack-0.5.5-4.el6.remi.1.x86_64
      php-pecl-sqlite-2.0.0-0.4.svn332053.el6.remi.5.5.x86_64
      php-pecl-zip-1.12.4-1.el6.remi.5.5.x86_64
      php-pgsql-5.5.12-1.el6.remi.x86_64
      php-process-5.5.12-1.el6.remi.x86_64
      php-xml-5.5.12-1.el6.remi.x86_64

      Reply
    8. only php-fpm said its taking too much time to load some files.

      Nginx and php-fpm Okay. No strange log. :)

      mysql log is Okay.

      Reply
    9. Hi tom,

      If we think this situation and what we/I know. You upgraded PHP and load jumps to really high, you downgraded back to earlier version and it doesn’t help. This is actually really hard to debug because there is not any errors or other strange things.

      So here is a few options:

      1. Problem might be just PHP-FPM (this is unlikely, because the situation will continue same with the previous version and configs are same).
      2. Any installed/updated PHP modules might cause this problem.
      3. It may be that the problem is not necessarily in PHP itself. Problem might be in PHP code also.

      One more question, what WordPress version you use?

      What I recommend next:

      Check php-fpm slowlog, anything interesting there?

      Then you could disable/remove all not used PHP-modules. I think that at least following modules are not necessary (I assume that, this setup uses only mysql and you haven’t any memcache caching enabled):
      php-pgsql
      php-mongo
      php-pecl-sqlite
      php-pecl-memcache
      php-pecl-memcached

      If you know that your site uses some of listed modules, then of course do not disable/remove them. If you have some caching enabled, could you check that is it working properly?

      Then you can enable PHP errors, warnings and notices (logging). And then you might get some interesting info, what happens during PHP script execution.

      As it looks like everything is as it should be, there is no errors and everything looks good, but PHP script execution take too long (which cause high load), then next step is start debugging code to find functions which cause this. WordPress core is (should be) PHP 5.5 compatible, but all plugins, templates etc. might not be PHP 5.5 compatible.

      Reply
    10. I didn’t use these modules. I don’t know how those works.

      But phpinfo function show these are enabled.

      php-pecl-apcu
      php-pgsql
      php-mongo
      php-pecl-sqlite
      php-pecl-memcache
      php-pecl-memcached

      I tried to debug my custom php code. But no warning/error/notices show. Its uses GLOB() function. Its working fine.

      WordPress is Latest 3.9.1

      Thanks for your help. I will check it.

      Reply
      • Hi tom,

        PHP 5.5.13 is released, you could try to update your PHP again, to see is there any difference between PHP 5.5.12 and PHP 5.5.13. Hopefully that solve your problem. Let me know what happens.

        Reply
    11. Thanks it fixed.

      I forget i did install

      yum -y groupinstall Desktop

      after uninstall desktop everything works fine. My Cpu load went to Normal thanks JR

      yum clean all

      Reply
      • Hi tom,

        You are welcome and I’m very happy hear that the removing desktop fixed it, excellent!

        Reply
    12. Hi.Thanks for the article, but I am having some problems. When I enter http://77.47.198.10/index.php, the browser displays a “File not found”. I created index.html file in the same directory and http://77.47.198.10/index.html display it. So the problem with php, but I do not understand how to fix it.Can do you please help?

      nginx.conf

      # For more information on configuration, see:
      # * Official English Documentation: http://nginx.org/en/docs/
      # * Official Russian Documentation: http://nginx.org/ru/docs/

      user nginx;
      worker_processes 2;

      error_log /var/log/nginx/error.log;
      #error_log /var/log/nginx/error.log notice;
      #error_log /var/log/nginx/error.log info;

      pid /run/nginx.pid;

      events {
      worker_connections 1024;
      }

      http {
      include /etc/nginx/mime.types;
      default_type application/octet-stream;

      log_format main '$remote_addr - $remote_user [$time_local] "$request" '
      '$status $body_bytes_sent "$http_referer" '
      '"$http_user_agent" "$http_x_forwarded_for"';

      access_log /var/log/nginx/access.log main;

      sendfile on;
      #tcp_nopush on;

      #keepalive_timeout 0;
      keepalive_timeout 2;

      #gzip on;

      # Load modular configuration files from the /etc/nginx/conf.d directory.
      # See http://nginx.org/en/docs/ngx_core_module.html#include
      # for more information.
      include /etc/nginx/conf.d/*.conf;
      include /etc/nginx/sites-enabled/*;
      index index.php index.html index.htm;

      server {
      listen 80;
      root /usr/share/nginx/html;
      server_name briazkitka.vmk;
      access_log /srv/www/briazkitka.vmk/logs/access.log;
      error_log /srv/www/briazkitka.vmk/logs/error.log;
      # root /srv/www/briazkitka.vmk/public_html;

      #charset koi8-r;

      #access_log /var/log/nginx/host.access.log main;

      location / {
      # root /srv/www/briazkitka.vmk/public_html;
      root /usr/share/nginx/html;
      index index.php index.html index.htm;
      }

      # redirect server error pages to the static page /40x.html
      #
      error_page 404 /404.html;
      location = /40x.html {
      # root /srv/www/briazkitka.vmk/public_html;
      root /usr/share/nginx/html;
      }

      # redirect server error pages to the static page /50x.html
      #
      error_page 500 502 503 504 /50x.html;
      location = /50x.html {
      # root /srv/www/briazkitka.vmk/public_html;
      root /usr/share/nginx/html;
      }

      # proxy the PHP scripts to Apache listening on 127.0.0.1:80
      #
      #location ~ \.php$ {
      # proxy_pass http://127.0.0.1;
      #}

      # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
      #
      location ~ \.php$ {
      root /usr/share/nginx/html;
      # root /srv/www/briazkitka.vmk/public_html;
      # try_files $uri =404;
      # fastcgi_split_path_info ^(.+\.php)(/.+)$;
      # fastcgi_pass 127.0.0.1:9000;
      # fastcgi_index index.php;
      # fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      # include fastcgi_params;
      # root html;
      # fastcgi_pass 127.0.0.1:9000;
      # fastcgi_index index.php;
      # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
      # include fastcgi_params;
      include /etc/nginx/fastcgi_params;
      fastcgi_pass 127.0.0.1:9000;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      }

      # deny access to .htaccess files, if Apache's document root
      # concurs with nginx's one
      #
      location ~ /\.ht {
      deny all;
      }
      }

      # another virtual host using mix of IP-, name-, and port-based configuration
      #
      #server {
      # listen 8000;
      # listen somename:8080;
      # server_name somename alias another.alias;
      # root html;

      # location / {
      # }
      #}

      # HTTPS server
      #
      #server {
      # listen 443;
      # server_name localhost;
      # root html;

      # ssl on;
      # ssl_certificate cert.pem;
      # ssl_certificate_key cert.key;

      # ssl_session_timeout 5m;

      # ssl_protocols SSLv2 SSLv3 TLSv1;
      # ssl_ciphers HIGH:!aNULL:!MD5;
      # ssl_prefer_server_ciphers on;

      # location / {
      # }
      #}

      }

      php-fpm.conf

      ;;;;;;;;;;;;;;;;;;;;;
      ; FPM Configuration ;
      ;;;;;;;;;;;;;;;;;;;;;

      ; All relative paths in this configuration file are relative to PHP's install
      ; prefix.

      ; Include one or more files. If glob(3) exists, it is used to include a bunch of
      ; files from a glob(3) pattern. This directive can be used everywhere in the
      ; file.
      include=/etc/php-fpm.d/*.conf
      ;;;;;;;;;;;;;;;;;;
      ; Global Options ;
      ;;;;;;;;;;;;;;;;;;

      [global]
      ; Pid file
      ; Default Value: none
      pid = /run/php-fpm/php-fpm.pid

      ; Error log file
      ; If it's set to "syslog", log is sent to syslogd instead of being written
      ; in a local file.
      ; Default Value: /var/log/php-fpm.log
      error_log = /var/log/php-fpm/error.log

      ; syslog_facility is used to specify what type of program is logging the
      ; message. This lets syslogd specify that messages from different facilities
      ; will be handled differently.
      ; See syslog(3) for possible values (ex daemon equiv LOG_DAEMON)
      ; Default Value: daemon
      ;syslog.facility = daemon

      ; syslog_ident is prepended to every message. If you have multiple FPM
      ; instances running on the same server, you can change the default value
      ; which must suit common needs.
      ; Default Value: php-fpm
      ;syslog.ident = php-fpm

      ; Log level
      ; Possible Values: alert, error, warning, notice, debug
      ; Default Value: notice
      ;log_level = notice

      ; If this number of child processes exit with SIGSEGV or SIGBUS within the time
      ; interval set by emergency_restart_interval then FPM will restart. A value
      ; of '0' means 'Off'.
      ; Default Value: 0
      ;emergency_restart_threshold = 0

      ; Interval of time used by emergency_restart_interval to determine when
      ; a graceful restart will be initiated. This can be useful to work around
      ; accidental corruptions in an accelerator's shared memory.
      ; Available Units: s(econds), m(inutes), h(ours), or d(ays)
      ; Default Unit: seconds
      ; Default Value: 0
      ;emergency_restart_interval = 0

      ; Time limit for child processes to wait for a reaction on signals from master.
      ; Available units: s(econds), m(inutes), h(ours), or d(ays)
      ; Default Unit: seconds
      ; Default Value: 0
      ;process_control_timeout = 0

      ; 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

      ; Specify the nice(2) priority to apply to the master process (only if set)
      ; The value can vary from -19 (highest priority) to 20 (lower priority)
      ; Note: - It will only work if the FPM master process is launched as root
      ; - The pool process will inherit the master process priority
      ; unless it specified otherwise
      ; Default Value: no set
      ;process.priority = -19

      ; Send FPM to background. Set to 'no' to keep FPM in foreground for debugging.
      ; Default Value: yes
      daemonize = yes

      ; Set open file descriptor rlimit for the master process.
      ; Default Value: system defined value
      ;rlimit_files = 1024

      ; Set max core size rlimit for the master process.
      ; Possible Values: 'unlimited' or an integer greater or equal to 0
      ; Default Value: system defined value
      ;rlimit_core = 0

      ; Specify the event mechanism FPM will use. The following is available:
      ; - select (any POSIX os)
      ; - poll (any POSIX os)
      ; - epoll (linux >= 2.5.44)
      ; Default Value: not set (auto detection)
      ;events.mechanism = epoll

      ; When FPM is build with systemd integration, specify the interval,
      ; in second, between health report notification to systemd.
      ; Set to 0 to disable.
      ; Available Units: s(econds), m(inutes), h(ours)
      ; Default Unit: seconds
      ; Default value: 10
      ;systemd_interval = 10

      ;;;;;;;;;;;;;;;;;;;;
      ; Pool Definitions ;
      ;;;;;;;;;;;;;;;;;;;;

      ; See /etc/php-fpm.d/*.conf

      Very grateful for any help.

      Reply
      • Hi V_ra,

        Could you post output of following commands on your server:

        
        netstat -tulpn |grep 9000
        
        ls -la /usr/share/nginx/html
        

        Then could you post rows from your access and error logs related to this problem?

        Btw. you shouldn’t set root inside location blocks, it’s valid, but you set same root earlier on your config and it should be enough.

        Reply
1 3 4 5 6

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Close