diff --git a/ee/cli/plugins/stack.py b/ee/cli/plugins/stack.py index 2407872e..67418bf8 100644 --- a/ee/cli/plugins/stack.py +++ b/ee/cli/plugins/stack.py @@ -259,7 +259,39 @@ class EEStackController(CementBaseController): ee_nginx.close() Log.debug(self, 'Writting the nginx configuration to ' - 'file /etc/nginx/common/ php.conf') + 'file /etc/nginx/common/php-hhvm.conf') + ee_nginx = open('/etc/nginx/common/php-hhvm.conf', + encoding='utf-8', mode='w') + self.app.render((data), 'php-hhvm.mustache', + out=ee_nginx) + ee_nginx.close() + + Log.debug(self, 'Writting the nginx configuration to ' + 'file /etc/nginx/common/w3tc-hhvm.conf') + ee_nginx = open('/etc/nginx/common/w3tc-hhvm.conf', + encoding='utf-8', mode='w') + self.app.render((data), 'w3tc-hhvm.mustache', + out=ee_nginx) + ee_nginx.close() + + Log.debug(self, 'Writting the nginx configuration to ' + 'file /etc/nginx/common/wpfc-hhvm.conf') + ee_nginx = open('/etc/nginx/common/wpfc-hhvm.conf', + encoding='utf-8', mode='w') + self.app.render((data), 'wpfc-hhvm.mustache', + out=ee_nginx) + ee_nginx.close() + + Log.debug(self, 'Writting the nginx configuration to ' + 'file /etc/nginx/common/wpsc-hhvm.conf') + ee_nginx = open('/etc/nginx/common/wpsc-hhvm.conf', + encoding='utf-8', mode='w') + self.app.render((data), 'wpsc-hhvm.mustache', + out=ee_nginx) + ee_nginx.close() + + Log.debug(self, 'Writting the nginx configuration to ' + 'file /etc/nginx/common/php.conf') ee_nginx = open('/etc/nginx/common/php.conf', encoding='utf-8', mode='w') self.app.render((data), 'php.mustache', @@ -531,12 +563,23 @@ class EEStackController(CementBaseController): "hhvm.mysqli.socket = " "/var/run/mysqld/mysqld.sock\n") - with open("/etc/nginx/conf.d/fastcgi.conf", "a") as hhvm_file: - hhvm_file.write("fastcgi_keep_conn on;\n") - - with open("/etc/nginx/conf.d/upstream.conf", "a") as hhvm_file: - hhvm_file.write("upstream hhvm {\nserver 127.0.0.1:8000;\n" - "server 127.0.0.1:9000 backup;\n}\n") + if os.path.isfile("/etc/nginx/conf.d/fastcgi.conf"): + if not EEFileUtils.grep(self, "/etc/nginx/conf.d/" + "fastcgi.conf", + "fastcgi_keep_conn"): + with open(, "a") as hhvm_file: + hhvm_file.write("fastcgi_keep_conn on;\n") + + if os.path.isfile("/etc/nginx/conf.d/upstream.conf"): + if not EEFileUtils.grep(self, "/etc/nginx/conf.d/" + "upstream.conf", + "hhvm"): + with open("/etc/nginx/conf.d/upstream.conf", + "a") as hhvm_file: + hhvm_file.write("upstream hhvm {\nserver " + "127.0.0.1:8000;\n" + "server 127.0.0.1:9000 backup;\n}" + "\n") EEGit.add(self, ["/etc/hhvm"], msg="Adding HHVM into Git") EEService.restart_service(self, 'hhvm') diff --git a/ee/cli/templates/fastcgi.mustache b/ee/cli/templates/fastcgi.mustache index db82c459..6d4bc4ba 100644 --- a/ee/cli/templates/fastcgi.mustache +++ b/ee/cli/templates/fastcgi.mustache @@ -7,3 +7,4 @@ fastcgi_buffers 16 16k; fastcgi_buffer_size 32k; fastcgi_param SERVER_NAME $http_host; fastcgi_ignore_headers Cache-Control Expires Set-Cookie; +fastcgi_keep_conn on; diff --git a/ee/cli/templates/php-hhvm.mustache b/ee/cli/templates/php-hhvm.mustache new file mode 100644 index 00000000..54f4d2aa --- /dev/null +++ b/ee/cli/templates/php-hhvm.mustache @@ -0,0 +1,10 @@ +# PHP NGINX CONFIGURATION +# DO NOT MODIFY, ALL CHNAGES LOST AFTER UPDATE EasyEngine (ee) +location / { + try_files $uri $uri/ /index.php?$args; +} +location ~ \.php$ { + try_files $uri =404; + include fastcgi_params; + fastcgi_pass hhvm; +} diff --git a/ee/cli/templates/upstream.mustache b/ee/cli/templates/upstream.mustache index 8a265179..aeb8230f 100644 --- a/ee/cli/templates/upstream.mustache +++ b/ee/cli/templates/upstream.mustache @@ -7,3 +7,8 @@ upstream debug { # Debug Pool server 127.0.0.1:{{debug}}; } +upstream hhvm { +# HHVM Pool +server 127.0.0.1:8000; +server 127.0.0.1:9000 backup; +} diff --git a/ee/cli/templates/virtualconf.mustache b/ee/cli/templates/virtualconf.mustache index cadb946b..48ddd7c2 100644 --- a/ee/cli/templates/virtualconf.mustache +++ b/ee/cli/templates/virtualconf.mustache @@ -28,6 +28,7 @@ server { {{/static}} {{^static}}include{{/static}} {{#basic}}common/php.conf;{{/basic}}{{#w3tc}}common/w3tc.conf;{{/w3tc}}{{#wpfc}}common/wpfc.conf;{{/wpfc}} {{#wpsc}}common/wpsc.conf;{{/wpsc}} + {{^static}}include{{/static}} {{#basic}}common/php-hhvm.conf;{{/basic}}{{#w3tc}}common/w3tc-hhvm.conf;{{/w3tc}}{{#wpfc}}common/wpfc-hhvm.conf;{{/wpfc}} {{#wpsc}}common/wpsc-hhvm.conf;{{/wpsc}} {{#wpsubdir}}include common/wpsubdir.conf;{{/wpsubdir}} {{#wp}}include common/wpcommon.conf;{{/wp}} include common/locations.conf; diff --git a/ee/cli/templates/w3tc-hhvm.mustache b/ee/cli/templates/w3tc-hhvm.mustache new file mode 100644 index 00000000..dbaca7c0 --- /dev/null +++ b/ee/cli/templates/w3tc-hhvm.mustache @@ -0,0 +1,31 @@ + +# W3TC NGINX CONFIGURATION +# DO NOT MODIFY, ALL CHNAGES LOST AFTER UPDATE EasyEngine (ee) +set $cache_uri $request_uri; +# POST requests and URL with a query string should always go to php +if ($request_method = POST) { + set $cache_uri 'null cache'; +} +if ($query_string != "") { + set $cache_uri 'null cache'; +} +# Don't cache URL containing the following segments +if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|wp-.*.php|index.php|/feed/|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") { + set $cache_uri 'null cache'; +} +# Don't use the cache for logged in users or recent commenter +if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in") { + set $cache_uri 'null cache'; +} +# Use cached or actual file if they exists, Otherwise pass request to WordPress +location / { + try_files /wp-content/cache/page_enhanced/${host}${cache_uri}_index.html $uri $uri/ /index.php?$args; +} +location ~ ^/wp-content/cache/minify/(.+\.(css|js))$ { + try_files $uri /wp-content/plugins/w3-total-cache/pub/minify.php?file=$1; +} +location ~ \.php$ { + try_files $uri =404; + include fastcgi_params; + fastcgi_pass hhvm; +} diff --git a/ee/cli/templates/wpfc-hhvm.mustache b/ee/cli/templates/wpfc-hhvm.mustache new file mode 100644 index 00000000..54255c4f --- /dev/null +++ b/ee/cli/templates/wpfc-hhvm.mustache @@ -0,0 +1,36 @@ +# WPFC NGINX CONFIGURATION +# DO NOT MODIFY, ALL CHNAGES LOST AFTER UPDATE EasyEngine (ee) +set $skip_cache 0; +# POST requests and URL with a query string should always go to php +if ($request_method = POST) { + set $skip_cache 1; +} +if ($query_string != "") { + set $skip_cache 1; +} +# Don't cache URL containing the following segments +if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|wp-.*.php|index.php|/feed/|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") { + set $skip_cache 1; +} +# Don't use the cache for logged in users or recent commenter +if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") { + set $skip_cache 1; +} +# Use cached or actual file if they exists, Otherwise pass request to WordPress +location / { + try_files $uri $uri/ /index.php?$args; +} +location ~ ^/wp-content/cache/minify/(.+\.(css|js))$ { + try_files $uri /wp-content/plugins/w3-total-cache/pub/minify.php?file=$1; +} +location ~ \.php$ { + try_files $uri =404; + include fastcgi_params; + fastcgi_pass hhvm; + fastcgi_cache_bypass $skip_cache; + fastcgi_no_cache $skip_cache; + fastcgi_cache WORDPRESS; +} +location ~ /purge(/.*) { + fastcgi_cache_purge WORDPRESS "$scheme$request_method$host$1"; +} diff --git a/ee/cli/templates/wpsc-hhvm.mustache b/ee/cli/templates/wpsc-hhvm.mustache new file mode 100644 index 00000000..29e9ebd9 --- /dev/null +++ b/ee/cli/templates/wpsc-hhvm.mustache @@ -0,0 +1,31 @@ +# WPSC NGINX CONFIGURATION +# DO NOT MODIFY, ALL CHNAGES LOST AFTER UPDATE EasyEngine (ee) +set $cache_uri $request_uri; +# POST requests and URL with a query string should always go to php +if ($request_method = POST) { + set $cache_uri 'null cache'; +} +if ($query_string != "") { + set $cache_uri 'null cache'; +} +# Don't cache URL containing the following segments +if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|wp-.*.php|index.php|/feed/|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") { + set $cache_uri 'null cache'; +} +# Don't use the cache for logged in users or recent commenter +if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in") { + set $cache_uri 'null cache'; +} +# Use cached or actual file if they exists, Otherwise pass request to WordPress +location / { + # If we add index.php?$args its break WooCommerce like plugins + # Ref: #330 + try_files /wp-content/cache/supercache/$http_host/$cache_uri/index.html $uri $uri/ /index.php; +} +location ~ \.php$ { + try_files $uri =404; + include fastcgi_params; + fastcgi_pass hhvm; + # Following line is needed by WP Super Cache plugin + fastcgi_param SERVER_NAME $http_host; +} diff --git a/ee/core/fileutils.py b/ee/core/fileutils.py index 115d1797..d6a171e7 100644 --- a/ee/core/fileutils.py +++ b/ee/core/fileutils.py @@ -218,6 +218,7 @@ class EEFileUtils(): for line in open(fnm, encoding='utf-8'): if sstr in line: return line + return false except OSError as e: Log.debug(self, "{0}".format(e.strerror)) Log.error(self, "Unable to Search string {0} in {1}"