diff --git a/managed_vms/wordpress/.gitignore b/managed_vms/wordpress/.gitignore new file mode 100644 index 0000000000..b13ec3f29e --- /dev/null +++ b/managed_vms/wordpress/.gitignore @@ -0,0 +1 @@ +my-wordpress-project diff --git a/managed_vms/wordpress/README.md b/managed_vms/wordpress/README.md index bfe342688a..a51834f5e2 100644 --- a/managed_vms/wordpress/README.md +++ b/managed_vms/wordpress/README.md @@ -114,10 +114,10 @@ running): ``` $ cd my-wordpress-project -$ php -S localhost:8000 -t wordpress wp.php +$ vendor/bin/wp(.bat) server --path=wordpress ``` -Then access http://localhost:8000/. Follow the installation steps, +Then access http://localhost:8080/. Follow the installation steps, create the admin user and its password. Login to the Dashboard and update if any of the plugins have update. I’m assuming that the local network is secure here. If you think differently, maybe you can first @@ -133,7 +133,7 @@ Use the shell script wrapper for deployment as follows: ``` $ sh deploy_wrapper.sh \ gcloud preview app deploy \ - --promote --stop-previous-version app.yaml + --promote --stop-previous-version app.yaml cron.yaml ``` Then access your site, use the username and the password you created @@ -170,7 +170,14 @@ see the following Batcache stats in the HTML source: Because the wp-content directory on the server is read-only, you have to do this locally. Run WordPress locally and update plugins/themes in the local Dashboard, then deploy, then activate them in the production -Dashboard. +Dashboard. You can also use the `wp-cli` utility as follows: + +``` +# To update all the plugins +$ vendor/bin/wp plugin update --all --path=wordpress +# To update all the themes +$ vendor/bin/wp theme update --all --path=wordpress +``` ### Remove plugins/themes diff --git a/managed_vms/wordpress/src/Project.php b/managed_vms/wordpress/src/Project.php index 6fac9509f8..48f6b4548e 100644 --- a/managed_vms/wordpress/src/Project.php +++ b/managed_vms/wordpress/src/Project.php @@ -85,11 +85,11 @@ public function runComposer() { chdir($this->dir); exec( - 'composer install --no-interaction --no-progress --no-ansi', + 'composer update --no-interaction --no-progress --no-ansi', $output, $ret); $this->info = array_merge($this->info, $output); if ($ret !== 0) { - $this->info[] = 'Failed to run composer install in ' . $dir + $this->info[] = 'Failed to run composer update in ' . $dir . '. Please run it by yourself before running WordPress.'; } } diff --git a/managed_vms/wordpress/src/WordPressSetup.php b/managed_vms/wordpress/src/WordPressSetup.php index 4aa9c5dbd4..0643236703 100644 --- a/managed_vms/wordpress/src/WordPressSetup.php +++ b/managed_vms/wordpress/src/WordPressSetup.php @@ -124,6 +124,7 @@ protected function execute(InputInterface $input, OutputInterface $output) ); $copyFiles = array( 'app.yaml' => '/', + 'cron.yaml' => '/', 'composer.json' => '/', 'deploy_wrapper.sh' => '/', 'Dockerfile' => '/', @@ -131,7 +132,6 @@ protected function execute(InputInterface $input, OutputInterface $output) 'nginx-app.conf' => '/', 'php.ini' => '/', 'wp-config.php' => '/wordpress/', - 'wp.php' => '/' ); $authKeys = array( 'auth_key', 'secure_auth_key', 'logged_in_key', 'nonce_key', diff --git a/managed_vms/wordpress/src/files/composer.json b/managed_vms/wordpress/src/files/composer.json index 93ce09849a..366f473537 100644 --- a/managed_vms/wordpress/src/files/composer.json +++ b/managed_vms/wordpress/src/files/composer.json @@ -1,5 +1,8 @@ { "require": { "google/appengine-php-sdk": "^1.9" + }, + "require-dev": { + "wp-cli/wp-cli": "^0.22.0" } } diff --git a/managed_vms/wordpress/src/files/cron.yaml b/managed_vms/wordpress/src/files/cron.yaml new file mode 100644 index 0000000000..c47b1767fa --- /dev/null +++ b/managed_vms/wordpress/src/files/cron.yaml @@ -0,0 +1,4 @@ +cron: +- description: wordpress cron tasks + url: /wp-cron.php + schedule: every 15 minutes diff --git a/managed_vms/wordpress/src/files/wp-config.php b/managed_vms/wordpress/src/files/wp-config.php index 5c468730cb..da2892fe51 100644 --- a/managed_vms/wordpress/src/files/wp-config.php +++ b/managed_vms/wordpress/src/files/wp-config.php @@ -35,6 +35,15 @@ // Cache settings define('WP_CACHE', ON_MVM); +// Disable pseudo cron behavior +define('DISABLE_WP_CRON', true); + +if (isset($_SERVER['HTTP_HOST'])) { + define('HTTP_HOST', $_SERVER['HTTP_HOST']); +} else { + define('HTTP_HOST', 'localhost'); +} + $memcached_servers = array( 'default' => array( getenv('MEMCACHE_PORT_11211_TCP_ADDR') @@ -42,11 +51,9 @@ ) ); -// Auto detect the URL fails. -define('WP_HOME', ON_MVM ? 'https://' . $_SERVER['HTTP_HOST'] - : 'http://' . $_SERVER['HTTP_HOST']); -define('WP_SITEURL', ON_MVM ? 'https://' . $_SERVER['HTTP_HOST'] - : 'http://' . $_SERVER['HTTP_HOST']); +// Use https on MVMs. +define('WP_HOME', ON_MVM ? 'https://' . HTTP_HOST : 'http://' . HTTP_HOST); +define('WP_SITEURL', ON_MVM ? 'https://' . HTTP_HOST : 'http://' . HTTP_HOST); // Need this for cookies. define('FORCE_SSL_ADMIN', ON_MVM); diff --git a/managed_vms/wordpress/src/files/wp.php b/managed_vms/wordpress/src/files/wp.php deleted file mode 100644 index 4125249901..0000000000 --- a/managed_vms/wordpress/src/files/wp.php +++ /dev/null @@ -1,49 +0,0 @@ - - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -/** - * This file is originally hosted at: - * http://ripeworks.com/run-wordpress-locally-using-phps-buily-in-web-server/ - */ - -// This file is a front controller for running your WordPress locally with -// PHP's built-in web server. This allows you to maintain the plugins/themes -// in the UI when running locally. - -$root = $_SERVER['DOCUMENT_ROOT']; -chdir($root); -$path = '/' . ltrim(parse_url(https://github.com/$_SERVER['REQUEST_URI'])['path'], '/'); -set_include_path(get_include_path() . ':' . __DIR__); -if (file_exists($root . $path)) { - if (is_dir($root . $path) && substr($path, strlen($path) - 1, 1) !== '/') { - $path = rtrim($path, '/') . '/index.php'; - } - if (strpos($path, '.php') === false) { - return false; - } else { - chdir(dirname($root . $path)); - require_once $root . $path; - } -} else { - include_once 'index.php'; -} diff --git a/managed_vms/wordpress/tests/DeployTest.php b/managed_vms/wordpress/tests/DeployTest.php index 111bb6f7e3..32f1d6e650 100644 --- a/managed_vms/wordpress/tests/DeployTest.php +++ b/managed_vms/wordpress/tests/DeployTest.php @@ -67,7 +67,7 @@ public static function deploy($project_id, $e2e_test_version) "sh $target/deploy_wrapper.sh gcloud -q preview app deploy " . "--version $e2e_test_version " . "--project $project_id --no-promote " - . "$target/app.yaml", + . "$target/app.yaml $target/cron.yaml", $output, $ret );