Title: Precache NGINX
Last modified: August 21, 2016

---

# Precache NGINX

 *  Resolved [JayFry](https://wordpress.org/support/users/jayfry/)
 * (@jayfry)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/precache/)
 * Hi! You made a really great plugin!
 * But I have some troubles with precache.
    I set once hourly precache schedule 
   but it doesn`t run. Also there is a message says: “sh: php: command not found“
   [https://dl.dropboxusercontent.com/u/16667581/wp1.png](https://dl.dropboxusercontent.com/u/16667581/wp1.png)
 * I`m running wordpress on nginx 1.4.1 sever with php-fpm.
    My conf file:
 *     ```
       worker_processes  1;
   
       error_log  /var/log/nginx/error.log;
       #error_log  logs/error.log  notice;
       #error_log  logs/error.log  info;
   
       #pid        logs/nginx.pid;
   
       events {
           worker_connections  1024;
       }
   
       http {
           include       mime.types;
           default_type  application/octet-stream;
   
           log_format  main  '$http_x_forwarded_for - $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  65;
   
           # memcached servers, generated according to wp-ffpc config
           upstream memcached-servers {
       	server 10.128.5.232:11211;
   
           }
           # PHP-FPM upstream; change it accordingly to your local config!
           upstream php-fpm {
       	server 127.0.0.1:9000;
           }
   
           server {
               listen       80;
               listen  [::]:80;
               server_name  localhost;
   
               #charset koi8-r;
   
               #access_log  logs/host.access.log  main;
       	include /etc/nginx/aliases.conf;
   
       	# root of WordPress
       	root /var/www/webroot/ROOT/;
   
       	## PHP5-FPM
       	location ~ (\.php) {
       	# these settings are usually in fastcgi_params
   
       		fastcgi_index                           index.php;
       		fastcgi_connect_timeout                 10;
       		fastcgi_send_timeout                    180;
       		fastcgi_read_timeout                    180;
       		fastcgi_buffer_size                     512k;
       		fastcgi_buffers                         4       256k;
       		fastcgi_busy_buffers_size               512k;
       		fastcgi_temp_file_write_size            512k;
       		fastcgi_intercept_errors                on;
       		fastcgi_split_path_info ^(.+\.php)(/.*)$;
       		fastcgi_keep_conn			on;
   
       		fastcgi_param	QUERY_STRING			$query_string;
       		fastcgi_param	REQUEST_METHOD			$request_method;
       		fastcgi_param	CONTENT_TYPE			$content_type;
       		fastcgi_param	CONTENT_LENGTH			$content_length;
       		fastcgi_param	SCRIPT_FILENAME			$document_root$fastcgi_script_name;
       		fastcgi_param	SCRIPT_NAME				$fastcgi_script_name;
       		fastcgi_param	REQUEST_URI				$request_uri;
       		fastcgi_param	DOCUMENT_URI			$document_uri;
       		fastcgi_param	DOCUMENT_ROOT			$document_root;
       		fastcgi_param	SERVER_PROTOCOL			$server_protocol;
       		fastcgi_param	GATEWAY_INTERFACE		CGI/1.1;
       		fastcgi_param	SERVER_SOFTWARE			nginx;
       		fastcgi_param	REMOTE_ADDR				$remote_addr;
       		fastcgi_param	REMOTE_PORT				$remote_port;
       		fastcgi_param	SERVER_ADDR				$server_addr;
       		fastcgi_param	SERVER_PORT				$server_port;
       		fastcgi_param	SERVER_NAME				$server_name;
       		fastcgi_param	PATH_INFO				$fastcgi_path_info;
       		fastcgi_param	PATH_TRANSLATED			$document_root$fastcgi_path_info;
       		fastcgi_param	REDIRECT_STATUS			200;
   
       		# uncomment these for HTTPS usage
       		#fastcgi_param	HTTPS					$https if_not_empty;
       		#fastcgi_param	SSL_PROTOCOL			$ssl_protocol if_not_empty;
       		#fastcgi_param	SSL_CIPHER				$ssl_cipher if_not_empty;
       		#fastcgi_param	SSL_SESSION_ID			$ssl_session_id if_not_empty;
       		#fastcgi_param	SSL_CLIENT_VERIFY		$ssl_client_verify if_not_empty;
   
       		fastcgi_pass php-fpm;
       	}
   
               location / {
               	try_files $uri $uri/ @memcached;
                       index index.php;
               }
   
       # try to get result from memcached
       	location @memcached {
       		default_type text/html;
       		set $memcached_key data-$scheme://$host$request_uri;
       		set $memcached_request 1;
   
       		# exceptions
       		# avoid cache serve of POST requests
       		if ($request_method = POST ) {
       			set $memcached_request 0;
       		}
   
       		# avoid cache serve of wp-admin-like pages, starting with "wp-"
       		if ( $uri ~ "/wp-" ) {
       			set $memcached_request 0;
       		}		
   
       		if ( $memcached_request = 1) {
       			add_header X-Cache-Engine "WP-FFPC with memcache via nginx";
       			memcached_pass memcached-servers;
       			error_page 404 = @rewrites;
       		}
   
       		if ( $memcached_request = 0) {
       						rewrite ^ /index.php last;
       		}
       	}
   
       	location @rewrites {
       		add_header X-Cache-Engine "";
       		rewrite ^ /index.php last;
       	}
   
           }
   
       include /etc/nginx/conf.d/*.conf;
   
       }
       ```
   
 * It`s code from nginx tab of your plugin except line:
 *     ```
       location / {
               	try_files $uri $uri/ @memcached;
                       index index.php;
               }
       ```
   
 * I added “index index.php;”.
 * Could you help me with this problem?
 * [http://wordpress.org/plugins/wp-ffpc/](http://wordpress.org/plugins/wp-ffpc/)

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Plugin Author [petermolnar](https://wordpress.org/support/users/cadeyrn/)
 * (@cadeyrn)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/precache/#post-4349833)
 * Hi!
 * You need to have command line php for the precache modul. I’ll put in a check
   for it’s existens later on.
 * The reason is that the precaching can take a very long time and it runs in the
   background, semi-forked from the original process.
 *  Thread Starter [JayFry](https://wordpress.org/support/users/jayfry/)
 * (@jayfry)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/precache/#post-4349834)
 * So there is a problem with my settings? And if so how i can fix it?
 *  Plugin Author [petermolnar](https://wordpress.org/support/users/cadeyrn/)
 * (@cadeyrn)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/precache/#post-4349844)
 * Please try the following:
    replace line #1002 in wp-ffpc-class.php from the following:`
   $shellfunction( 'php '. $this->precache_phpfile .' >'. $this->precache_logfile.'
   2>&1 &' );`
 * to this:
    `$shellfunction( '/usr/bin/env php '. $this->precache_phpfile .' >'.
   $this->precache_logfile .' 2>&1 &' );`
 * This might solve it.
 * If not, that means you don’t have php-cli installed.
    `apt-get install php-cli`
   if you’re on Debian derivative, I don’t know the others.
 *  Thread Starter [JayFry](https://wordpress.org/support/users/jayfry/)
 * (@jayfry)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/precache/#post-4349926)
 * I installed php-cli, and replaced line #1002, but it didn`t help.
    And I still
   see message “sh: php: command not found”
 *  [ericgillette.com](https://wordpress.org/support/users/ericgillettecom/)
 * (@ericgillettecom)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/precache/#post-4349990)
 * Just chiming in to help out here Peter. . .
 * If you’re on any RHEL derivative the command would be:
 * yum install php-cli
 * Odds are you would need to have a repository that will see this to install it,
   as I don’t know if it’s in the default CentOS repo.
 * You could try using Atomicorp’s repo:
 * wget -q -O – [http://www.atomicorp.com/installers/atomic](http://www.atomicorp.com/installers/atomic)
   | sh
 *  [ericgillette.com](https://wordpress.org/support/users/ericgillettecom/)
 * (@ericgillettecom)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/precache/#post-4349991)
 * JayFry,
 * To add to Peter’s comments, try this:
 * Please try the following. . .
 * 1) Check for your php-cli using like this:
 *     ```
       which php-cli
       ```
   
 * Or just:
 *     ```
       which php
       ```
   
 * Depending on your OS, you may get two different results:
 * /usr/bin/php-cli
 * or
 * /usr/local/bin/php
 * With that information, try replacing this:
 *     ```
       $shellfunction( 'php '. $this->precache_phpfile .' >'. $this->precache_logfile .' 2>&1 &' );
       ```
   
 * to this:
 *     ```
       $shellfunction( '/usr/local/bin/php'. $this->precache_phpfile .' >'. $this->precache_logfile .' 2>&1 &' );
       ```
   
 * Or this:
 *     ```
       $shellfunction( '/usr/bin/php-cli'. $this->precache_phpfile .' >'. $this->precache_logfile .' 2>&1 &' );
       ```
   
 * See if that works for you. . .

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Precache NGINX’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/wp-ffpc_ffffff.svg)
 * [WP-FFPC](https://wordpress.org/plugins/wp-ffpc/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-ffpc/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-ffpc/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-ffpc/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-ffpc/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-ffpc/reviews/)

 * 6 replies
 * 3 participants
 * Last reply from: [ericgillette.com](https://wordpress.org/support/users/ericgillettecom/)
 * Last activity: [12 years, 3 months ago](https://wordpress.org/support/topic/precache/#post-4349991)
 * Status: resolved