Comments (11)
My setup failed at first on macOS because I didn't have wp-cli or robo yet. Would it be worth it to check for those, or is that prerequisite a fair assumption to start with?
from headless-wp-starter.
While exploring how to get this working on a windows environment, I've observed multiple things and managed to replicate the same environment of the scripts as on windows.
Preliminary comments
- The installation script in
package.json
is very Mac oriented with the use ofhomebrew
- Installing MySQL as part of the installation script not recommended (at least in my opinion)
- You may already have an existing installation of MySQL or MariaDB
- The current scripts assume the default password for root is empty string
- It is generally nice to have a installer config where you have mysql options as params that the user eneters
- Either way using scoop on windows you can install mysql like on brew
- Starting mysql from the script, is dependent on how mysql was installed
- Using scoop on windows this may not be an issue, though windows user
services
to start/stop - Depending on the Linux distro there are many ways to start/stop system services
- Using scoop on windows this may not be an issue, though windows user
- PHP is used as the installer script
RoboFile.php
- This is fine since PHP can be installed in full on all 3 platforms
Requirements
Methods
In order to get the environment all working the decision was taken to use Scoop which is a "command line installer for windows" and seems to work really great inter-mixing linux packages with windows. Scoop lies on top of Windows Powershell.
Below are a series of command line steps to be done in order to setup a working environment to get all the packages installed. Assuming scoop has been installed as per the instructions on Scoop then the below is valid when opening the windows PowerShell.
Install core tools
$ scoop install 7zip
$ scoop install grep
$ scoop install gzip
$ scoop install less
$ scoop install sed
$ scoop install sudo
$ scoop install tar
$ scoop install touch
$ scoop install which
$ scoop install curl
$ scoop install cacert
$ scoop install wget
$ scoop install yarn
$ scoop install git
$ scoop install openssh
$ [environment]::setenvironmentvariable('GIT_SSH', (resolve-path (scoop which ssh)), 'USER')
Install tools for wordpress
$ scoop install php
$ scoop bucket add extras
$ scoop install vcredist2017
$ curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
$ php wp-cli.phar --info
$ wget http://robo.li/robo.phar
$ php robo.phar --info
Integration Magic
So we got php, yarn, git, wp-cli and robo installed and we have run commands to check that they actually work. Now it's time to do integration magic so that RoboFile
calls wp-cli
and robo
in a way that is not prefixed by the php
command.
We need to move the .phar files to a separate directory and alias them on the command line so that when we run wp
it will run wp-cli using php.
$ mkdir ~\Programs\php
$ mv wp-cli.phar ~\Programs\php
$ mv robo.phar ~\Programs\php
For the integration magic to work we need to create 2 windows script files.
- A powershell script that uses scoop in order to run the command
- A batch script that will call the powershell script
- This is because PHP's
_exec()
runs on the command prompt and not the powershell
- This is because PHP's
- Create symlinks linking the batch scripts to the commands
wp
androbo
- Setting user or system wide environment variable with the location of the scripts
You will notice this is not too different that how things are setup on Linux environments
wp.bat
@echo off
set arg1=%1
shift
powershell -Command "& iex 'wp.ps1 %arg1%'"
wp.ps1
param([string]$wpCommand = "--info")
$wp = 'php $Env:PHP_TOOLS_HOME\wp-cli.phar'
iex "& $wp $wpCommand"
robo.bat
@echo off
set arg1=%1
shift
powershell -Command "& iex 'robo.ps1 %arg1%'"
robo.ps1
param([string]$roboCommand = "--info")
$robo = 'php $Env:PHP_TOOLS_HOME\robo.phar'
iex "& $robo $roboCommand"
Create the Symlinks
$ cd ~\Programs\php
$ sudo ln -s wp.bat wp
$ sudo ln -s robo.bat robo
Now running the command wp --info
should work directly at the command line
Fixes in RoboFile.php
For some reason the MySQL binaries on windows do not like non-string literals being passed as arguments. So in the PHP script there is a mix of mysql commands where some are enclosed in double quotes and some in single quotes. Just changing them so that they are all in double quotes makes all the commands succeed. As well as adding IF NOT EXISTS
to the create statements helps avoid getting errors when running the scripts again and again if the users already exist from a previous installation or if they were already setup.
WP-CLI breaks
Running $ robo wordpress:setup
will always fail. When debugging using a more direct command
php $ php .\wp-cli.phar core download --version=4.8.2
Downloading WordPress 4.8.2 (en_US)...
PHP Notice: Undefined index: a:1:{s:3:"ssl";b:1;} in phar://C:/Users/George Haddad/Programs/php/wp-cli.phar/vendor/rmccue/requests/library/Requests.php on line 213
Warning: No working transports found
PHP Notice: Undefined index: a:1:{s:3:"ssl";b:1;} in phar://C:/Users/George Haddad/Programs/php/wp-cli.phar/vendor/rmccue/requests/library/Requests.php on line 213
Error: No working transports found
Trying to figure out how to resolve this issue.
from headless-wp-starter.
@ginatrapani I am starting to think that maybe the best way to go about this setup is to just do a pure Linux installation and setup on a virutal machine image and run it locally on a PC. Then just keep the frontend in a docker which will work pretty much on any platform. Connecting the frontend to the virtual machine is easy.
For development purposes this technique looks nice and contained. Even if I had a mac or linux box having all this installed locally might conflict with other installations and/or setups. It is not uncommon to setup servers in virtual machines like this.
Interested to know your thoughts on this matter.
from headless-wp-starter.
Update
Enabled the Linux Subsystem on Windows 10 Pro
I was able to install everything and run the wp-cli
just need to tweak some of the parameters. For example on linux you cannot connect to a mysql instance without a root password, which I think makes sense so when installing mysql I just defaulted the root password to root
. Also the host name needs to be specified because we're breaking out of the linux subsystem and into the windows networking env so specifying something like -h 0.0.0.0
works fine.
from headless-wp-starter.
Wow @ wp-cli/wp-cli#4370
Spent an hour trying figure this one out, this worked wp core download --version=4.8.2 --locale=en_GB --force
And yeah it only seems to succeed on Mac but fail on Linux
from headless-wp-starter.
Good news, everything working on Windows without a Virtual Machine (which is not wrong to have one) just using the Linux Subsystem.
The install script was very MacOS oriented so anyone running Linux or Windows would have had these issues. The RoboFile.php
needed just minor modifications to get everything running.. Would be cool to see if the Linux oriented fixes wtill work on mac.
from headless-wp-starter.
This is great news! We used a VM for over a year but found it slow, memory-intensive, and cumbersome to work with, so we much prefer running mysql and wp server locally.
from headless-wp-starter.
Just tested the frontend portion and it works flawlessly on just pure windows environment with docker.
from headless-wp-starter.
@morgvanny yarn install
uses Homebrew to install wp-cli and Robo, but it sounds like that didn't work for you. Want to open a separate ticket to address that? For OS X users, we only assume that Yarn and Homebrew are installed.
from headless-wp-starter.
@ginatrapani interesting. I'll do that if I can replicate it. I don't remember the details - I was mainly surprised I didn't have wp-cli on that machine yet
from headless-wp-starter.
Got a version of this to work on windows, ubuntu linux and macosx on my forked branch. I tested it on windows and ubuntu and still need to test it on a mac. If that succeeds then I'll get it PR'ed here :)
from headless-wp-starter.
Related Issues (20)
- Sub navigation? HOT 1
- functions acf_register_block_type and acf_register_block do not exist
- wp-headless container: No such file or directory HOT 1
- Nonce doesn't work for draft previews HOT 1
- Errors popping up while installing since wordpress 5.3
- Errors installing Windows 10 LTSC HOT 11
- Changed current directory to /var/www/.composer error
- faild to build wp-headless : Permission denied HOT 1
- How to deploy it on server?
- CORS errors HOT 1
- Which frontend if SEO is important HOT 1
- No Schema Available HOT 2
- Multisite setup - SSR wpapi connection issue
- Is there a complete guide from A to Z how to setup this repo INCLUDING details like setting up the users node and www-data? HOT 1
- Getting a rest_post_invalid_id when i try to visit wp-admin
- [meta]: Project status? HOT 1
- wp-headless: permission denied
- How can I make a PR? HOT 2
- Error loading Requests.php file in WordPress Docker container
- Docker compose ERROR HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from headless-wp-starter.