Giter Site home page Giter Site logo

Comments (11)

morgvanny avatar morgvanny commented on May 8, 2024

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.

george-haddad avatar george-haddad commented on May 8, 2024

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

  1. The installation script in package.json is very Mac oriented with the use of homebrew
    • homebrew is a MacOs package manager that uses Ruby
    • Linux users would have to workaround this by installing linuxbrew
    • Windows users would alternatively use scoop
  2. 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
  3. 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
  4. 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.

  1. A powershell script that uses scoop in order to run the command
  2. A batch script that will call the powershell script
    • This is because PHP's _exec() runs on the command prompt and not the powershell
  3. Create symlinks linking the batch scripts to the commands wp and robo
  4. 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.

george-haddad avatar george-haddad commented on May 8, 2024

@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.

george-haddad avatar george-haddad commented on May 8, 2024

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.

george-haddad avatar george-haddad commented on May 8, 2024

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.

george-haddad avatar george-haddad commented on May 8, 2024

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.

ginatrapani avatar ginatrapani commented on May 8, 2024

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.

george-haddad avatar george-haddad commented on May 8, 2024

Just tested the frontend portion and it works flawlessly on just pure windows environment with docker.

from headless-wp-starter.

ginatrapani avatar ginatrapani commented on May 8, 2024

@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.

morgvanny avatar morgvanny commented on May 8, 2024

@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.

george-haddad avatar george-haddad commented on May 8, 2024

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)

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.