Wordpress Dev with Windows Subsystem for Linux
Before starting, make sure Valet has not been installed previously on Windows. Uninstall that version before attempting to install Valet for Linux. See "Uninstalling Valet for Windows" below.
- Follow the guide: Windows Subsystem for Linux Installation Guide for Windows 10
- Note: The choice of Linux distribution is up to you. For these instructions, we are using Ubuntu 18.04LTS
- Install PHP: `
sudo apt install php
` - Install Composer
- Note:
- There are requirements before installing Composer for Linux. See this page for the list of dependencies
- Most of the php dependencies can be satisfied by running `
sudo apt install php-[module-name]
`. - php-mcrypt may require additional steps to install (see Installing php-mcrypt).
- Note:
- Install Laravel Valet for Windows Subsystem Linux
- `composer global require valeryan/valet-wsl`
- After installing Valet, you will need to add it to the PATH. Example: `
export PATH=/home/username/.config/composer/vendor/bin/:$PATH
` - Acrylic needs to be configured - see this documentation for Windows 10.
- Check configuration
- Assuming Valet and Acrylic have been set up from step 4, you should be able to run `ping foo.test` (or any *.test domain) and get a result.
- Install wp-cli
- Install the wp cli auto-completion too
- Configure mysql for system user
- In some cases only the root user is set up with mysql initially. The system user (your user account, not root) needs to be added to mysql users in order for Wordpress to set up properly. To set up mysql for your user account, see this post on Stackoverflow, Option 2 is recommended.if not already done in step 3. See https://github.com/valeryan/valet-wsl/wiki/Installation-Guide#mysql
- Install wp-cli-valet-command
- build a WP site
- try `
wp valet new <project name> --dbuser=<system username>
` to build a new site.- Replace '
<project name>
' with a name for your project. A new directory will be created with this name and will contain Wordpress. - Replace '
<system username>
' with your Linux system username.
- Replace '
- It is possible that going to https://<project name>.test may give a 404 error. You may have to manually link using Valet from within the Wordpress project directory. i.e. `
valet link
`.
- try `
After Installing WP with WSL
Using Windows for development, and Wordpress on Ubuntu
Ubuntu on WSL lacks a rich IDE aside from terminal based text editors (vi, emacs, etc.). To use Windows for development, and use Ubuntu for Wordpress hosting try the following:
- Checkout your code project to a directory on Windows. (i.e. c:\development\my-project-plugin)
In Ubuntu, make a symbolic link to your project on Windows. Example:
Code Block ln -s /mnt/c/development/my-project-plugin/ ~/wordpress/wp-content/plugins/my-project-plugin
- Now you can use your Windows IDE to code, and Ubuntu for Wordpress.
Restarting Wordpress after Shutting down Ubuntu
After shutting down Ubuntu, you may need to restart Wordpress the next time logging in. Note: some of this may not be required if it is scripted / automated.
- Launch Ubuntu
- Start mysql. i.e. `sudo service mysql start`
- Start Valet. i.e. `valet install`
- From your Wordpress directory, link to Valet. i.e. `valet link`
Other Useful Packages to Install
Wordpress Dev for Windows 10 Natively
- Install Laravel Valet for Windows - follow the instructions in the project's Readme (i.e. install PHP, Composer, etc.)
- Note: you may need to configure the Acrylic DNS proxy for your network. Instructions on the Laravel Valet for Windows readme.
- Once you have run `valet install`, and rebooted, run `ping foo.test` to confirm valet is working.
- Install wp cli
- Create a directory where wp-cli will live (i.e. c:\wp-cli\ or c:\program files\wp-cli, etc.)
- From the new wp-cli directory, using Powershell execute: wget -O wp-cli.phar https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
In the same directory, create a batch file called `wp.bat`. The batch file should contain:
Code Block @ECHO OFF php "C:\Program Files (x86)\wp-cli\wp-cli.phar" %*
The path to this new directory needs to be added to Windows 10 environment variable so the wp cli can be used. To do this:
Go to Windows menu > Settings > type "environment" into the search bar > choose "Edit System Environment Variables"
In the dialog that appears, choose "Environment Variables" button (bottom right)
Under the "System variables" pane, choose "Path" from the list and select Edit button.
Select "Browse" button and find the directory for wp-cli created earlier and OK to confirm.
Logout of Windows 10 or restart
Open a command prompt and type `
wp
`. You should see the following output:Code Block NAME wp DESCRIPTION Manage WordPress through the command-line. SYNOPSIS wp <command> SUBCOMMANDS cache Adds, removes, fetches, and flushes the WP Object Cache object. ...
Uninstalling Valet for Windows
If Valet for Windows is installed, it may interfere with installation of Valet for Linux. To uninstall Valet for Windows:
- Locate Composer in the Windows file system. This may be located in a directory `c:\Users\Username\AppData\Roaming\Composer`.
- Open a Powershell prompt as Administrator.
- Change to the directory of Composer (i.e. `
cd \Users\Username\AppData\Roaming\Composer
`) - Run `
valet uninstall
` to stop the valet service - Run `
composer global remove cretueusebiu/valet-windows
`- If the process stops stating nginx error.log is locked by Windows, try restarting and trying step 5 again.
- If after restarting uninstall still reports error.log is locked, you may have to manually terminate nginx.exe using the Task Manager.
Wordpress Development Resources
- Human Made Engineering Standards: https://engineering.hmn.md/standards/
- 10up Engineering Best Practices: https://10up.github.io/Engineering-Best-Practices/
- WordPress Coding Standards: https://github.com/WordPress/WordPress-Coding-Standards
- wp-cli: https://developer.wordpress.org/cli/commands/ (especially https://developer.wordpress.org/cli/commands/scaffold/)