Giter Site home page Giter Site logo

wp-cli / server-command Goto Github PK

View Code? Open in Web Editor NEW
68.0 13.0 19.0 229 KB

Launches PHP's built-in web server for a specific WordPress installation.

License: MIT License

PHP 93.20% Gherkin 6.80%
wp-cli wp-cli-package wordpress cli server localhost local hacktoberfest

server-command's Introduction

wp-cli/server-command

Launches PHP's built-in web server for a specific WordPress installation.

Testing

Quick links: Using | Installing | Contributing | Support

Using

wp server [--host=<host>] [--port=<port>] [--docroot=<path>] [--config=<file>]

Uses php -S to launch a web server serving the WordPress webroot. http://php.net/manual/en/features.commandline.webserver.php

Importantly, PHP's built-in web server doesn't support .htaccess files. If this is a requirement, please use a more advanced web server.

OPTIONS

[--host=<host>]
	The hostname to bind the server to.
	---
	default: localhost
	---

[--port=<port>]
	The port number to bind the server to.
	---
	default: 8080
	---

[--docroot=<path>]
	The path to use as the document root. If the path global parameter is
	set, the default value is it.

[--config=<file>]
	Configure the server with a specific .ini file.

EXAMPLES

# Make the instance available on any address (with port 8080)
$ wp server --host=0.0.0.0
PHP 5.6.9 Development Server started at Tue May 24 01:27:11 2016
Listening on http://0.0.0.0:8080
Document root is /
Press Ctrl-C to quit.

# Run on port 80 (for multisite)
$ wp server --host=localhost.localdomain --port=80
PHP 5.6.9 Development Server started at Tue May 24 01:30:06 2016
Listening on http://localhost1.localdomain1:80
Document root is /
Press Ctrl-C to quit.

# Configure the server with a specific .ini file
$ wp server --config=development.ini
PHP 7.0.9 Development Server started at Mon Aug 22 12:09:04 2016
Listening on http://localhost:8080
Document root is /
Press Ctrl-C to quit.

Installing

This package is included with WP-CLI itself, no additional installation necessary.

To install the latest version of this package over what's included in WP-CLI, run:

wp package install [email protected]:wp-cli/server-command.git

Contributing

We appreciate you taking the initiative to contribute to this project.

Contributing isn’t limited to just code. We encourage you to contribute in the way that best fits your abilities, by writing tutorials, giving a demo at your local meetup, helping other users with their support questions, or revising our documentation.

For a more thorough introduction, check out WP-CLI's guide to contributing. This package follows those policy and guidelines.

Reporting a bug

Think you’ve found a bug? We’d love for you to help us get it fixed.

Before you create a new issue, you should search existing issues to see if there’s an existing resolution to it, or if it’s already been fixed in a newer version.

Once you’ve done a bit of searching and discovered there isn’t an open or fixed issue for your bug, please create a new issue. Include as much detail as you can, and clear steps to reproduce if possible. For more guidance, review our bug report documentation.

Creating a pull request

Want to contribute a new feature? Please first open a new issue to discuss whether the feature is a good fit for the project.

Once you've decided to commit the time to seeing your pull request through, please follow our guidelines for creating a pull request to make sure it's a pleasant experience. See "Setting up" for details specific to working on this package locally.

Support

GitHub issues aren't for general support questions, but there are other venues you can try: https://wp-cli.org/#support

This README.md is generated dynamically from the project's codebase using wp scaffold package-readme (doc). To suggest changes, please submit a pull request against the corresponding part of the codebase.

server-command's People

Contributors

danielbachhuber avatar drewapicture avatar francescolaffi avatar gitlost avatar janw-me avatar mweimerskirch avatar pdaalder avatar schlessera avatar scribu avatar swissspidy avatar szepeviktor avatar waviaei avatar wojsmol avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

server-command's Issues

Easy WordPress development server

I wrote this recently without knowing about wp-cli:
https://gist.github.com/bburky/9317876

It works quite well for quickly setting up a development server without MySQL (which yes, I'm aware is unsupported).

I tried to set up the same environment using wp-cli, but it seems to be necessary to do a lot of the installation manually because a MySQL server is not available:

wp core download

# This actually needs MySQL running, can't use this
# Really just need a default configuration, the database settings will be ignored
# wp core config --dbname=wp --dbuser=wp --dbpass=pass

# Use this instead
# It would be nice to still set the salts automatically somehow though
cp wp-config-sample.php wp-config.php

# This doesn't work, it tries to connect to MySQL and fails
# wp plugin install sqlite-integration

# Use this instead
cd wp-content/plugins
curl -O https://downloads.wordpress.org/plugin/sqlite-integration.1.5.zip
unzip sqlite-integration.1.5.zip
rm sqlite-integration.1.5.zip
mv sqlite-integration/db.php ../
cd ../../

wp core install --title=Dev --admin_name=admin --admin_email="[email protected]" --admin_password=pass --url="http://localhost:8080/"

wp server

Once db.php is patched everything works fine. Is there any easy way to install the plugin and the initial wp-config.php configuration without accessing MySQL?

If this workflow is easy enough, it is a very nice way to do plugin or theme development as long as nothing MySQL-specific is needed.

(Should I raise any of these issues at https://github.com/wp-cli/wp-cli instead?)

Adopt and enforce new `WP_CLI_CS` standard

We have a new PHPCS standard for WP-CLI called WPCliCS (props @jrfnl). It is part of the wp-cli/wp-cli-tests package starting with version v2.1.0.

To adopt & enforce this new standard, the following actions need to be taken for this repository:

  • Create a PR that adds a custom ruleset phpcs.xml.dist to the repository

    • Add phpcs.xml.dist file
    • Adapt .distignore to ignore phpcs.xml.dist & phpunit.xml.dist
    • Adapt .gitignore to ignore phpunit.xml, phpcs.xml & .phpcs.xml
    • Require version ^2.1 of the wp-cli/wp-cli-tests as a dev dependency
  • Make any required changes to the code that fail the checks from the above ruleset in separate PRs

  • Merge thre ruleset once all required changes have been processed and merged

A sample PR for a simple repository can be seen here: https://github.com/wp-cli/maintenance-mode-command/pull/3/files

Related wp-cli/wp-cli#5179

Move command over to new v2 structure

The following changes need to be made to move the command over to the v2 structure:

  • Make sure the correct framework is required:
    composer require wp-cli/wp-cli:^2
    
  • Require the testing framework as a dev dependency:
    composer require --dev wp-cli/wp-cli-tests:^0
    
  • Use the .travis.yml file from wp-cli/wp-cli:
    wget https://raw.githubusercontent.com/wp-cli/wp-cli/master/.travis.yml
    
  • Add the default script configuration to Composer file:
      "scripts": {
          "lint": "run-linter-tests",
          "phpcs": "run-phpcs-tests",
          "phpunit": "run-php-unit-tests",
          "behat": "run-behat-tests",
          "prepare-tests": "install-package-tests",
          "test": [
              "@lint",
              "@phpcs",
              "@phpunit",
              "@behat"
          ]
      },
    
  • Remove scaffolded binary files:
    git rm bin/install-package-tests.sh
    git rm bin/test.sh
    
  • Remove scaffolded Behat setup:
    git rm features/bootstrap/*
    git rm features/extra/*
    git rm features/steps/*
    
  • Remove scaffolded Behat tags util script:
    git rm utils/behat-tags.php
    
  • Add command packages that are needed for Behat tests as --dev dependencies.
    The following commands are already available, anything else needs to be explicitly required:
    • cli *
    • config *
    • core *
    • eval
    • eval-file
    • help
  • Update all dependencies:
    composer update
    
  • Optional - Add PHPCS rule set to enable CS & compatibility sniffing:
    wget https://raw.githubusercontent.com/wp-cli/wp-cli/master/phpcs.xml.dist
    
  • Run and adapt tests to make sure they all pass:
    composer test
    

wp-cli server in the sample installation for some reason does not serve JS or CSS resulting in a broken HTML render

I followed https://make.wordpress.org/cli/handbook/how-to/how-to-install/ and https://make.wordpress.org/cli/handbook/how-to/how-to-start-webserver/ to create my first WordPress local installation (serving at 127.0.0.1:8080, calling it as php wp-cli.phar server --path=./wpssgblog).

http://127.0.0.1:8080 opens in the web browser, but CSS/JS are not server by the server, so the render is broken.

image

a CSS http://127.0.0.1:8080/wpssgblog/wp-includes/blocks/navigation/style.min.css/?ver=6.4.2 and http://127.0.0.1:8080/wpssgblog/wp-includes/js/dist/interactivity.min.js/?ver=6.4.2 are some of the resources that the browser tries to load (./wpssgblog is the wordpress dir I'm passing to wp-cli as --path=./wpssgblog) serve the exact same HTML for some reason instead of CSS and JS contents. Chrome browser is obviously not happy about this:
image

I'm obviously missing something very simple. How can I fix the serve? Thank you :)

bbPress menu icons don't show up

Setup script (OS X):

#!/usr/bin/env bash
mkdir /tmp/wp-cli-server-bbpress
cd /tmp/wp-cli-server-bbpress/

echo 'path: wp' > wp-cli.yml
echo 'url: example.com' >> wp-cli.yml

wp core download
mv wp/wp-content/ .

wp core config --dbname=wp_test --dbprefix=wp_cli_server --dbuser=travis --extra-php <<EOB
define('WP_CONTENT_DIR', __DIR__ . '/wp-content');
define('WP_CONTENT_URL', \$_SERVER['HTTP_HOST'] . '/wp-content');
EOB
mv wp/wp-config.php .

mv wp/index.php .
sed -i .bak 's|\./wp-blog-header|./wp/wp-blog-header|' index.php

wp db create

wp core install --title='Test' --admin_user='admin' --admin_password=asd [email protected]
wp option set siteurl 'http://example.com/wp'

wp plugin install --activate bbpress

wp server --port=8084

When I access http://localhost:8084/wp/wp-admin/ the bbPress menu icons aren't there.

Doesn't run correctly from a subdirectory

If I'm in wp-content/plugins/my-plugin and I run wp server, I get:

PHP Warning:  require_once(index.php): failed to open stream: No such file or directory in /Users/User/.wp-cli/vendor/wp-cli/server-command/router.php on line 25

Failed opening required 'phar:///usr/local/bin/wp/vendor/wp-cli/server-command/router.php

I got an error with the nightly build like following.

$ ./wp server --host=0.0.0.0 --port=8080 --docroot=www
PHP 7.0.17 Development Server started at Wed Mar 29 19:48:42 2017
Listening on http://0.0.0.0:8080
Document root is /Users/miyauchi/Desktop/wp/www
Press Ctrl-C to quit.
[Wed Mar 29 19:48:46 2017] PHP Warning:  Unknown: failed to open stream: phar error: invalid url or non-existent phar &quot;phar:///Users/miyauchi/Desktop/wp/wp/vendor/wp-cli/server-command/router.php&quot; in Unknown on line 0
[Wed Mar 29 19:48:46 2017] PHP Fatal error:  Unknown: Failed opening required 'phar:///Users/miyauchi/Desktop/wp/wp/vendor/wp-cli/server-command/router.php' (include_path='.:') in Unknown on line 0

My installation method is as follows.

$ curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli-nightly.phar
$ mv wp-cli-nightly.phar wp
$ chmod 755 wp
$ ./wp --info
PHP binary:	/usr/local/Cellar/php70/7.0.17_9/bin/php
PHP version:	7.0.17
php.ini used:	/usr/local/etc/php/7.0/php.ini
WP-CLI root dir:	phar://wp-cli.phar
WP-CLI packages dir:	/Users/miyauchi/.wp-cli/packages/
WP-CLI global config:	/Users/miyauchi/.wp-cli/config.yml
WP-CLI project config:	
WP-CLI version:	1.2.0-alpha-e0ad2a5

But current master from GitHub worked fine.

I am sorry that I tried to solve the problem but I couldn't. 😓

Permalinks altered

Hi there :)

A question: is just a problem of mine to have permalinks altered like this using wp server?

screenshot 2015-01-28 11 36 08

that way I have to use a custom one to get WP work: /%postname%/

Support custom rewrite rules

The first fork of the server-command repo has popped up (yay!):

https://github.com/leoj3n/server-command/compare/roots-rewrites

It would be neat if there was a way to support custom rewrite rules in a generic way. One potential idea:

wp server --rewrites=some-file.php

The wp server command could pass the path via an environment variable to the router, which would then load it where the roots_rewrites() function is called now.

Passthrough args via `--`?

Feature Request

Describe your use case and the problem you are facing

I want to load Xdebug module into the web server via php -S -dzend_extension=xdebug.so.

Describe the solution you'd like

wp server could pass through additional arguments to php after -- argument.

Example: wp server --docroot=public -- -dzend_extension=xdebug.so

Doing this via wp server --config argument is problematic, because I want to define universally usable commands centrally in composer.json scripts. Due to variety of INI configuration file locations on user's system, which we actually don't want to replace, this doesn't seem to be achievable with a single --config argument.

Automatically rerun failed scenarios

The following changes need to be made:

  1. In the .travis.yml file, the - composer behat line in the script: section needs to be changed into the following:
- composer behat || composer behat-rerun
  1. In the composer-json file, the requirement on wp-cli/wp-cli-tests needs to be adapted to require at least v2.0.7:
"wp-cli/wp-cli-tests": "^2.0.7"
  1. In the composer-json file, the "scripts" section needs to be extended. Immediately after the line "behat": "run-behat-tests",, the following line needs to be inserted:
"behat-rerun": "rerun-behat-tests",

Here's an example of how this should look like:

WP CLI does not populate SERVER_ADDR & HTTP_REFERER

I am having issues creating a new command because I can't get SERVER_ADDR and HTTP_REFERER through it.

$_SERVER['SERVER_ADDR'];
$_SERVER['HTTP_REFERER'];

Notice: Undefined index: SERVER_ADDR
Notice: Undefined index: HTTP_REFERER

Any workaround for this?

ini file with `auto_prepend_file` doesn't work with router.php

Bug Report

It seems loading a config file with auto_prepend_file does not work with the router.php file.
If I use the internal PHP server without this, it works.

https://github.com/wp-cli/server-command/blob/master/src/Server_Command.php#L90

This works without any problems:

php -c .../.user.ini -S localhost:8080 -t .

Describe the current, buggy behavior

php wp-cli.phar server --config=.user.ini

Describe how other contributors can replicate this bug

  • create a .user.ini file with a auto_prepend_file setting
  • run php wp-cli.phar server --config=.user.ini
  • open the browser
  • check if the file is actually executed (add an echo to it)

Describe what you would expect as the correct outcome

The ini file should be loaded and the auto_prepend_file setting should work.

Let us know what environment you are running this on

(Paste the output of "wp cli info" into this box)

Provide a possible solution

If you happen to have a suggestion on how to fix this bug, please tell us in here.

Just leave this section out if you don't know how to fix it.

Provide additional context/Screenshots

Add any other context about the problem here.

If applicable, add screenshots to help explain (you can just drag&drop images into the Github issue).

PHP built-in webserver doesn't handle rewrite conditions defined in .htaccess

Hello
i Have an issue using wp server for hosting in development a multi-network of multi-site.
here is my conf

$ wp core version --extra
WordPress version: 4.8.1
Database revision: 38590
TinyMCE version:   4.603 (4603-20170530)
Package language:  fr_FR
$ wp site list --fields=blog_id,url,site_id
+---------+------------------------------------------------+---------+
| blog_id | url                                            | site_id |
+---------+------------------------------------------------+---------+
| 1       | http://dev.example.fr:8090/            | 1       |
| 2       | http://dev.example.fr:8090/test/       | 1       |
| 3       | http://dev.other-example.fr:8090/      | 2       |
| 4       | http://dev.other-example.fr:8090/test/ | 2       |
+---------+------------------------------------------------+---------+ 
$ wp plugin list
+-----------------------------------+----------------+--------+---------+
| name                              | status         | update | version |
+-----------------------------------+----------------+--------+---------+
| advanced-access-manager           | active-network | none   | 5.0     |
| contact-form-7                    | inactive       | none   | 4.9.1   |
| diamond-multisite-widgets         | active-network | none   | 1.8.2   |
| google-analytics-dashboard-for-wp | active-network | none   | 5.1.2.2 |
| wp-multisite-feed                 | active-network | none   | 1.0.3   |
| mailchimp-for-wp                  | inactive       | none   | 4.1.11  |
| movabletype-importer              | active-network | none   | 0.4     |
| multisite-enhancements            | active-network | none   | 1.4.1   |
| multisite-list-widget             | inactive       | none   | 0.1     |
| network-latest-posts              | inactive       | none   | 3.7.1   |
| require-featured-image            | inactive       | none   | 1.3.0   |
| w3-total-cache                    | active-network | none   | 0.9.5.4 |
| wp-multi-network                  | active-network | none   | 1.8.1   |
| wordpress-seo                     | active-network | none   | 5.8     |
| common                            | must-use       | none   | 1.0.0   |
| sharer                            | must-use       | none   | 1.0.0   |
| advanced-cache.php                | dropin         | none   |         |
| db.php                            | dropin         | none   |         |
+-----------------------------------+----------------+--------+---------+

My problem are on blog 2 & 4 :

  • I can't access wp-admin for blog 2 & 4
  • All Static (CSS/JS/IMG) files from blog 2&4 are in 404

when i use an Basic nginx server or Apache Server, all is working well.

Please help

Support pretty permalinks

Describe your use case and the problem you are facing

wp server does not handle wp-login.php and, more generally, any WP entry-point other than index.php

Describe the solution you'd like

Hardwiring entrypoints logic (or even parse the htaccess using PHP) in order to support them would make it.

A fully browsable WordPress instance off Apache/nginx/php-fpm would be handy in Q&A situations/simulations. The (probably < 100) lines needed may be worth it.

If login.php is requested by the client, that file would be require'd dynamically.
Some tweaks to $_SERVER may be needed though in order to mimic mod_rewrite behavior.

Does not use run "require" php scripts defined in wp-cli.yml?

In my wp-cli.yml I have the following which tells wp-cli to run a php script before every command:

require:
    - wp-env.local.php

This file contains lines such as:

$_SERVER['DB_NAME']='wordpress';
$_SERVER['RDS_HOSTNAME']='127.0.0.1';

But these environment variables do not seem to be set when the server is run. The php script does not seem to be loaded. 'wp core install' and other related commands work fine however.

How come the variables are not passed through to the server environment?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.