Skip to content

3rd iteration of - Setting up a local Development Environment. #24555

Closed

Description

@paaljoachim

We have been working on 2 iterations of setting up a local dev WP environment:
Version 2: #23593

Version 2 was merged, and we need to continue onward with version 3. As there are still a few fixes needed to finish up the documentation. Making it easier for beginners to setup a local development environment.

Fixes to be included:
https://github.com/WordPress/gutenberg/pull/23593/files#r451950832

@mkaz and @noahtallen

Activity

  1. added
    [Type] Developer Documentation
    on Aug 18, 2020
  2. paaljoachim commented on Aug 25, 2020

    @paaljoachim
    ContributorAuthor

    https://github.com/WordPress/gutenberg/pull/23593/files

    Setting up a local WordPress Development Environment.

    Setup a local WordPress development environment using JavaScript for creating plugins and/or contributing to WordPress/Gutenberg.
    or
    The development environment setup guide is for setting up your local development environment for JavaScript development; creating plugins and tools for extending WordPress and the block editor.

    A development environment is a catch-all term for the setup on your computer to work. The three main pieces needed for our development environment are:

    1. Node/NPM Development Tools
    2. WordPress Development Site
    3. Code Editor

    The short guide.

    In terminal - Mac, Windows or Linux.

    Install nvm:
    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
    

    Quit and restart terminal.
    Install node:
    nvm install --lts

    Download and install Docker. Startup Docker (?) ...

    In terminal.
    npm -g install @wordpress/env
    Check to see it has been installed:
    wp-env --version

    Do something (?)
    Then in terminal:
    wp-env start

    The uninstall guide

    In terminal
    wp-env destroy
    to destroy the local environment data for a specific project
    run npm uninstall -g @wordpress/env
    will uninstall the npm package, but will not remove any environment data. (Environment data is .....?)

    Uninstall Docker by.... I made a search and found this: https://askubuntu.com/questions/935569/how-to-completely-uninstall-docker (not tested yet)

    Development Tools

    The tools needed for development are Node and NPM. Nodejs is a runtime environment that allows running JavaScript outside of the browser. NPM is the Node Package Manager, it is used for installing dependencies and running scripts. The script npx is installed with npm and is used to run packages not yet installed, we will use this to bootstrap a block.

    The tools needed for development are Node and NPM. Nodejs is a runtime environment that allows running JavaScript outside of the browser. NPM is the Node Package Manager, it is used for installing dependencies and running scripts. The script npx is also installed with Nodejs—this script is used to run packages not yet installed—we will use npx to bootstrap a block.

    The tools are used to convert the JavaScript we are going to write into a format that browsers can run. This is called transpiling or the build step.

    For Windows, or alternative installs, you can download a Nodejs installer

    Here are the quick instructions to install using nvm, see the full installation instructions for additional details.

    Note: On macOS, the required developer tools are not installed by default, if not already installed you may be prompted to download the install.

    Mac git command requies command line developer tools

    After installing nvm, you need to use it to install node, to install the LTS version of node, run:

    nvm install --lts

    If there is an error running the above command, for example a common error that occurs is:

    $ nvm install --lts
    zsh: command not found: nvm

    First, try quitting and restarting your terminal to pick up the installed config.

    If restarting did not resolve the problem, you might need to create the default profile file.

    On macOS Catalina, the default shell is zsh, to create the profile file type touch ~/.zshrc on the command-line. It is fine to run if the file already exists. Note, ~/ is a shortcut to your home directory. For Ubuntu, including WSL, the default profile is bash, use touch ~/.bashrc to create.

    After creating the profile file, re-run the install command:

    nvm install --lts
    
    The `wp-env` package requires Docker to be installed. There are instructions available for installing Docker on [Windows 10 Pro](https://docs.docker.com/docker-for-windows/install/), [all other versions of Windows](https://docs.docker.com/toolbox/toolbox_install_windows/), [macOS](https://docs.docker.com/docker-for-mac/install/), and [Linux](https://docs.docker.com/v17.12/install/linux/docker-ce/ubuntu/#install-using-the-convenience-script).
    
    After you have installed Docker, go ahead and install `wp-env` globally from the command-line using:
    
    ```sh
    npm -g install @wordpress/env

    To confirm it is installed and available, run:

    wp-env --version
    
    > 1.6.0

    The wp-env script is used to create a Docker WordPress environment, to use start from your plugin directory—if you are following the create block tutorial, this would be in the generated directory.

    sh
    wp-env start
    
    

    What happens after start?

    Alternatives

    You can access your environment in your browser at: http://localhost:8888/, the default username is admin and default password is password. For more information controlling the Docker environment see the @wordpress/env package readme.

    If you are developing a single plugin, you should run wp-env start from that plugin working directory—it will mount and activate the plugin automatically. Note: This also works for themes, run from the directory you are developing the theme.

    If you want a single environment for all your plugins/themes, you need to create a .wp-env.json in a working directory and add the plugins/themes to it. You then run wp-env start from the same directory as that config file. See the @wordpress/env package for additional details.

    Alternative to Docker

    A block is just a plugin, so any WordPress environment can be used for development. A couple of alternatives that might be easier, since they do not require Docker install and setup.

    The important part is having a WordPress site installed, and know where and how
    Alternative editors include Sublime Text that is also available across platforms, though is a commercial product; or other free alternatives include Vim, Atom, and Notepad++ all support standard JavaScript style development.

    You can use any editor you're comfortable with, it is more a personal preference. The development setup for WordPress block editor is a common JavaScript environment and most editors have plugins and support. The key is having a way to open, edit, and save text files.

    The above is being worked on.

  3. added
    [Status] In Progress
    on Aug 27, 2020
  4. paaljoachim commented on Aug 31, 2020

    @paaljoachim
    ContributorAuthor

    The uninstall guide - complete(?).

    My newest tests:

    In terminal
    wp-env destroy

    Results:

    paaljoachimromdahl@Paals-MacBook-Pro ~ % wp-env destroy
    ✖ No .wp-env.json file found at '/Users/paaljoachimromdahl/.wp-env.json' and could not determine if '/Users/paaljoachimromdahl' is a WordPress installation, a plugin, or a theme.
    paaljoachimromdahl@Paals-MacBook-Pro ~ % 
    

    to destroy the local environment data for a specific project
    run npm uninstall -g @wordpress/env

    will uninstall the npm package, but will not remove any environment data. (Environment data is .....?)

    Result:
    Uninstall-npm-wordpress

    Test to see that NPM is really uninstalled.
    wp-env start

    Result:

    paaljoachimromdahl@Paals-MacBook-Pro ~ % wp-env start
    zsh: command not found: wp-env
    

    ---- I am not sure if the following is valid any longer.----

    To remove node and npm.
    rm -rf "$NVM_DIR"

    https://github.com/nvm-sh/nvm#uninstalling--removal

    Check to see that node and npm is removed:
    node -v
    and
    npm -v

    Result:

    paaljoachimromdahl@Paals-MacBook-Pro ~ % node -v
    zsh: command not found: node
    paaljoachimromdahl@Paals-MacBook-Pro ~ % npm -v
    zsh: command not found: npm
    

    ------END-----


    Uninstall Docker.

    Mac.
    Click the Docker icon in the top Mac menu bar. In the drop down select Preferences.
    In the Preferences -> General screen. Click the bug icon button seen in the top bar beside the Sign in button.

    Docker-preferences

    The following screen is seen.
    Docker-bug-screen

    Click Uninstall to completely remove Docker Desktop, and follow the prompts given. Do also remember to drag the Docker icon from the Application folder to the trash can.

    (Found instructions here: https://stackoverflow.com/questions/37465526/how-to-uninstall-docker-completely-from-a-mac )

    Is it the same for Windows operating systems?


    What else is needed regarding uninstall?

  5. paaljoachim commented on Aug 31, 2020

    @paaljoachim
    ContributorAuthor

    Starting over after having done the uninstall instructions I wrote above.

    Quitting and restarting terminal.

    I am following the quick start instructions. https://github.com/WordPress/gutenberg/blob/update/docs-dev-env/docs/designers-developers/developers/tutorials/devenv/readme.md
    As it is much easier and quicker to just follow short instructions than to have to relate in detail to each step.
    That means the quick instructions needs to have identical steps to the longer instructions. Only the longer instructions will have more details. The quick start should not skip any of the longer instructions steps! As both should be made available for any user of any level of knowledge.

    Download and install Node Version Manager (nvm)
    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash

    Result:

    paaljoachimromdahl@Paals-MacBook-Pro ~ % curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100 13527  100 13527    0     0   3446      0  0:00:03  0:00:03 --:--:--  3445
    => Downloading nvm from git to '/Users/paaljoachimromdahl/.nvm'
    => Cloning into '/Users/paaljoachimromdahl/.nvm'...
    remote: Enumerating objects: 290, done.
    remote: Counting objects: 100% (290/290), done.
    remote: Compressing objects: 100% (257/257), done.
    remote: Total 290 (delta 35), reused 97 (delta 20), pack-reused 0
    Receiving objects: 100% (290/290), 163.27 KiB | 949.00 KiB/s, done.
    Resolving deltas: 100% (35/35), done.
    => Compressing and cleaning up git repository
    
    => nvm source string already in /Users/paaljoachimromdahl/.zshrc
    => bash_completion source string already in /Users/paaljoachimromdahl/.zshrc
    => Close and reopen your terminal to start using nvm or run the following to use it now:
    
    export NVM_DIR="$HOME/.nvm"
    [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
    [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
    
    

    NB! Some info on what the above does would be good to add.

    Quit and restart terminal

    nvm install --lts

    Result:

    paaljoachimromdahl@Paals-MacBook-Pro ~ % nvm install --lts
    Installing latest LTS version.
    Downloading and installing node v12.18.3...
    Downloading https://nodejs.org/dist/v12.18.3/node-v12.18.3-darwin-x64.tar.gz...
    ######################################################################### 100.0%
    Computing checksum with shasum -a 256
    Checksums matched!
    Now using node v12.18.3 (npm v6.14.6)
    Creating default alias: default -> lts/* (-> v12.18.3)
    paaljoachimromdahl@Paals-MacBook-Pro ~ % 
    

    NB! What does the above do? Some details about the why and what is happening will help.

    Downloaded and installed Docker on my Mac.
    NB! Be sure to open and run Docker before continuing the next step.
    Follow the prompts. Such as insert your user password.
    In the "Get started with Docker in a few easy steps" you can choose to click Start og Skip tutorial. When you close the Docker window Docker will remain open in the Mac top bar.

    Then installed:

    npm -g install @wordpress/env

    Result:

    paaljoachimromdahl@Paals-MacBook-Pro ~ % npm -g install @wordpress/env
    npm WARN deprecated request-promise-native@1.0.9: request-promise-native has been deprecated because it extends the now deprecated request package, see https://github.com/request/request/issues/3142
    npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
    npm WARN deprecated har-validator@5.1.5: this library is no longer supported
    /Users/paaljoachimromdahl/.nvm/versions/node/v12.18.3/bin/wp-env -> /Users/paaljoachimromdahl/.nvm/versions/node/v12.18.3/lib/node_modules/@wordpress/env/bin/wp-env
    
    > nodegit@0.26.5 install /Users/paaljoachimromdahl/.nvm/versions/node/v12.18.3/lib/node_modules/@wordpress/env/node_modules/nodegit
    > node lifecycleScripts/preinstall && node lifecycleScripts/install
    
    [nodegit] Running pre-install script
    [nodegit] Running install script
    node-pre-gyp
    WARN Using request for node-pre-gyp https download
    [nodegit] Success: "/Users/paaljoachimromdahl/.nvm/versions/node/v12.18.3/lib/node_modules/@wordpress/env/node_modules/nodegit/build/Release/nodegit.node" is installed via remote
    [nodegit] Completed installation successfully.
    
    > nodegit@0.26.5 postinstall /Users/paaljoachimromdahl/.nvm/versions/node/v12.18.3/lib/node_modules/@wordpress/env/node_modules/nodegit
    > node lifecycleScripts/postinstall
    
    + @wordpress/env@1.6.0
    added 274 packages from 236 contributors in 90.496s
    paaljoachimromdahl@Paals-MacBook-Pro ~ % 
    

    NB! What does the above do? Some details about the why and what is happening will help.

    NB!! It looks like a gutenberg is added to the root user folder. See additional info further below.
    ----1----

    Create a minimal .wp-env.json file:

    {
    "core": null
    }

    NB! What does the above do? Some details about the why and what is happening will help.

    Result:

    paaljoachimromdahl@Paals-MacBook-Pro ~ % {
            "core": null
    }
    zsh: command not found: core:
    paaljoachimromdahl@Paals-MacBook-Pro ~ % 
    

    The above does not look right.

    Moving on.

    wp-env start

    Result:

    paaljoachimromdahl@Paals-MacBook-Pro ~ % wp-env start
    ✖ No .wp-env.json file found at '/Users/paaljoachimromdahl/.wp-env.json' and could not determine if '/Users/paaljoachimromdahl' is a WordPress installation, a plugin, or a theme.
    paaljoachimromdahl@Paals-MacBook-Pro ~ % 
    

    There is now a gutenberg folder inside the root of the user folder.

    I did the following:

    paaljoachimromdahl@Paals-MacBook-Pro ~ % cd gutenberg
    paaljoachimromdahl@Paals-MacBook-Pro gutenberg % 
    

    Nb. To go back to the home directory:
    cd ~/

    Switching to the gutenberg directory and then adding wp-env start again results in the downloading of WordPress.

    Result:

    paaljoachimromdahl@Paals-MacBook-Pro ~ % {
            "core": null
    }
    zsh: command not found: core:
    paaljoachimromdahl@Paals-MacBook-Pro ~ % wp-env start
    ✖ No .wp-env.json file found at '/Users/paaljoachimromdahl/.wp-env.json' and could not determine if '/Users/paaljoachimromdahl' is a WordPress installation, a plugin, or a theme.
    paaljoachimromdahl@Paals-MacBook-Pro ~ % cd gutenberg
    paaljoachimromdahl@Paals-MacBook-Pro gutenberg % wp-env start
    ⠋ Starting WordPress.
    

    So it looks like the step of npm -g install @wordpress/env needs information about a new gutenberg folder is added to the root of the user folder and that one then also needs to switch to the gutenberg folder before continuing...... (?) ---1---

    You will have a full WordPress site installed, navigate to: http://localhost:8888/ the defualt user is "admin" and default password is "password"

    I clicked: http://localhost:8888/

    Result seen in a browser:
    Fatal error: Uncaught Error: Call to undefined function gutenberg_is_experiment_enabled() in /var/www/html/wp-content/plugins/gutenberg/gutenberg.php:189 Stack trace: #0 /var/www/html/wp-includes/class-wp-hook.php(287): gutenberg_register_widgets('') #1 /var/www/html/wp-includes/class-wp-hook.php(311): WP_Hook->apply_filters('', Array) #2 /var/www/html/wp-includes/plugin.php(478): WP_Hook->do_action(Array) #3 /var/www/html/wp-includes/widgets.php(1773): do_action('widgets_init') #4 /var/www/html/wp-includes/class-wp-hook.php(287): wp_widgets_init('') #5 /var/www/html/wp-includes/class-wp-hook.php(311): WP_Hook->apply_filters(NULL, Array) #6 /var/www/html/wp-includes/plugin.php(478): WP_Hook->do_action(Array) #7 /var/www/html/wp-settings.php(546): do_action('init') #8 /var/www/html/wp-config.php(101): require_once('/var/www/html/w...') #9 /var/www/html/wp-load.php(37): require_once('/var/www/html/w...') #10 /var/www/html/wp-blog-header.php(13): require_once('/var/www/html/w...') #11 /var/www/html/index.php(17): require('/v in /var/www/html/wp-content/plugins/gutenberg/gutenberg.php on line 189

    I quit and restarted terminal.

    paaljoachimromdahl@Paals-MacBook-Pro ~ % wp-env start
    ✖ No .wp-env.json file found at '/Users/paaljoachimromdahl/.wp-env.json' and could not determine if '/Users/paaljoachimromdahl' is a WordPress installation, a plugin, or a theme.
    paaljoachimromdahl@Paals-MacBook-Pro ~ % cd gutenberg
    paaljoachimromdahl@Paals-MacBook-Pro gutenberg % wp-env start
    ⠴ Starting WordPress.
    

    Result:

    ✖ Error while running docker-compose command.
    Starting 298877af3310ecb3b00c247cdeb1bd5d_mysql_1 ... done
    Starting 298877af3310ecb3b00c247cdeb1bd5d_tests-wordpress_1 ... done
    [31-Aug-2020 12:24:17 UTC] PHP Fatal error:  Uncaught Error: Call to undefined function gutenberg_is_experiment_enabled() in /var/www/html/wp-content/plugins/gutenberg/gutenberg.php:189
    Stack trace:
    #0 /var/www/html/wp-includes/class-wp-hook.php(287): gutenberg_register_widgets('')
    #1 /var/www/html/wp-includes/class-wp-hook.php(311): WP_Hook->apply_filters('', Array)
    #2 /var/www/html/wp-includes/plugin.php(478): WP_Hook->do_action(Array)
    #3 /var/www/html/wp-includes/widgets.php(1773): do_action('widgets_init')
    #4 /var/www/html/wp-includes/class-wp-hook.php(287): wp_widgets_init('')
    #5 /var/www/html/wp-includes/class-wp-hook.php(311): WP_Hook->apply_filters(NULL, Array)
    #6 /var/www/html/wp-includes/plugin.php(478): WP_Hook->do_action(Array)
    #7 /var/www/html/wp-settings.php(546): do_action('init')
    #8 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1237): require('/var/www/html/w...')
    #9 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1158): WP_CLI\Runner->load_wordpress()
    #10 phar:///usr/local/bin/wp/vendor/wp-cli/w in /var/www/html/wp-content/plugins/gutenberg/gutenberg.php on line 189
    Fatal error: Uncaught Error: Call to undefined function gutenberg_is_experiment_enabled() in /var/www/html/wp-content/plugins/gutenberg/gutenberg.php:189
    Stack trace:
    #0 /var/www/html/wp-includes/class-wp-hook.php(287): gutenberg_register_widgets('')
    #1 /var/www/html/wp-includes/class-wp-hook.php(311): WP_Hook->apply_filters('', Array)
    #2 /var/www/html/wp-includes/plugin.php(478): WP_Hook->do_action(Array)
    #3 /var/www/html/wp-includes/widgets.php(1773): do_action('widgets_init')
    #4 /var/www/html/wp-includes/class-wp-hook.php(287): wp_widgets_init('')
    #5 /var/www/html/wp-includes/class-wp-hook.php(311): WP_Hook->apply_filters(NULL, Array)
    #6 /var/www/html/wp-includes/plugin.php(478): WP_Hook->do_action(Array)
    #7 /var/www/html/wp-settings.php(546): do_action('init')
    #8 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1237): require('/var/www/html/w...')
    #9 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1158): WP_CLI\Runner->load_wordpress()
    #10 phar:///usr/local/bin/wp/vendor/wp-cli/w in /var/www/html/wp-content/plugins/gutenberg/gutenberg.php on line 189
    Error: There has been a critical error on your website.Learn more about debugging in WordPress. There has been a critical error on your website.
    paaljoachimromdahl@Paals-MacBook-Pro gutenberg % 
    

    NB. I also received the same error code in the browser as I added above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

[Status] In Progress[Type] Developer Documentation

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions