/usr/bin/env: php: No such file or directory

Trying to setup grav on windows machine. I have git + bash and http://babun.github.io/ installed. Both cli give me the error when I try to use bin/grav commands. I am runing this command from grav folder, so it should work right? (works fine on my mac and on my linux server).

I know it could be not a grav problem, but I cannot find anything online.

hello nerijusgood. you most likely need to add php.exe to your path. http://stackoverflow.com/questions/7307548/how-to-access-php-with-the-command-line-on-windows is a good tutorial. If that fixes it I’ll add something regarding that in the docs (windows is a pain…) out of curiosity, are you using IIS or a different server?

Hi, no its a local machine. My server is running linux.

If i had windows server I would use IIS.

so what is your setup on your windows machine? are you running apache? (all vversions can have IIS enabled and if you’d like I can show you). But more importantly were you able to figure out the cli?

well, i was planing to run on Mamp, which works just fine. However I want to use cli to setup grav and maintain my project (i have grav settings, posts as git project + my custom theme as submodule).

I guess I need to somehow add php from mamp to path and it should work. I didn’t have time to try it out.

Actually first thing I tried was installing php packages with babun package manager (pact) and it actually passed that error, but some other popped-up, so I guess I need to stable solution.

you might be able to run these by ‘prefixing’ the CLI commands with PHP:

/path/to/php.exe bin/gpm index

For example

Hi, well I manually installed/downloaded php and added environment path, it works with php -v:

PHP 5.6.17 (cli) (built: Jan  6 2016 13:28:18)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies

However when I try to run bin/gpm index (or any other gpm or grav command), I get this:

Preparing to install vendor dependencies...

'C:\Program' is not recognized as an internal or external command,
operable program or batch file.

Warning: require_once(C:\Sites\solofront\bin/../vendor/autoload.php): failed to open stream: No such file or directory in C:\Sites\solofront\bin\gpm on line 26

Fatal error: require_once(): Failed opening required 'C:\Sites\solofront\bin/../vendor/autoload.php' (include_path='.;C:\php\pear') in C:\Sites\solofront\bin\gpm on line 26

What could be the issue? Is there something missing from php package?

i think the problem is not the Grav command, it’s that the #!/usr/bin/env php is trying to get the PHP path and it’s not able to deal with the space in C:\Program Files. What are you running this in? Can you try GitBash???

Same on git-bash. In the beginning I thought the same, however all env paths in Windos 10 are put with spaces - windows deals with that automatically:
Screen

In the mean time ill try to find an alternative way to have php in my env.

just edit the environment variable and put quotations around it. "C:\Program Files\p..."

Okey, commas have no difference at all. What actually helped was moving php installatin to root of harddrive - C:/php.

However it still does not work as intended. I still get the fallowing error:

Warning: require_once(C:\Sites\solofront\bin/../vendor/autoload.php): failed to open stream: No such file or directory in C:\Sites\solofront\bin\gpm on line 26

Fatal error: require_once(): Failed opening required 'C:\Sites\solofront\bin/../vendor/autoload.php' (include_path='.;C:\php\pear') in C:\Sites\solofront\bin\gpm on line 26

I thought maybe parts are missing, therefore I installed MAMP (i know it ships with php and other thing). So I actually put path to php in MAMP folder to environment, and try then: first i get error that php-curl is missing (install that) and now I get this error:

PHP Fatal error:  Call to undefined function Symfony\Component\Yaml\ctype_digit() in /cygdrive/c/Sites/grav/vendor/symfony/yaml/Inline.php on line 124

I am startin g suspect that I need very specific PHP package to get this running. Did anyone managed to get Grav shell installers working on Windows 10 for local development?

Sorry, i’m going to have to hand this off to someone with a windows machine. I have used macs for many years and have forgotten all my windows voodoo magic I used to know. Mac’s just work :slight_smile:

nerijusgood, I’ll try to run the gpm on my windows 10 machine. On my windows 8 machines I haven’t encountered problems (though I use IIS rather than MAMP)

The php in your path points to the MAMP installation of php?

Also, what is /cygdrive?

I got the same issue when following the recent serverpilot blog post on ubuntu 14.
To get it to work I needed to install php-cli the curl extension and had to change the permissions of the files in the bin folder to 774 to get them to run under the system user.
Possibly not just a windows issue.

Okey, so I managed to pass that stage.

Windows 10 proper PHP setup:

  1. Install PHP via Microsoft Web Platform Installer (https://www.microsoft.com/web/downloads/platform.aspx)
  2. Find and install desired PHP version.
  3. Manually go to C:\Program Files\PHP folder and copy it to a directory that would not have spaces in path (windows 10, disregards quotations in path env)
  4. Press Windows + X, then go to System > Advanced system settings and click Environment Variables. Find in System (or user) variables the “Path” variable and edit it: find the php path that MS Platform installer added and edit to your php path without white spaces.

This fixes the problem with PHP not working properly, and windows ignoring double quotation marks in path env.

Admittedly, I’m a newb at CLI but I did get Grav CLI ALMOST working on Windows 10. Over many days I was able to muddle through. For others like me, here are the steps I finally came up with:

First Steps:

Install MAMP for Windows – https://www.mamp.info/en/downloads/
Install githubDesktop –
https://desktop.github.com/tBash

Use Git Bash as terminal.
Open destination folder and right-click. Choose “Git Bash Here” to cd directly into the correct directory.

PHP Setup:
I use PHP that came with MAMP: C:\MAMP\bin\php\php5.6.13
(Make note of this location as it will be used later when setting PATH)

NOTE: php5.6.13 folder does not contain “php.ini”. You’ll need to copy php.ini from C:\MAMP\conf\php5.6.13 and paste it into C:\MAMP\bin\php\php5.6.13.
Open your newly pasted php.ini and verify that “php_openssl” in not commented (:wink: out.
Restart MAMP if it is running.

Set PATH to PHP
Type “System” into Start search field. Choose “System -Control panel” This should open Control Panel > System and Security > System
Click on “Advanced system settings”.
Click on "Environmental Variables"
Select PATH in top frame.
Click on "Edit…"
Click "New"
Paste in the complete path to the MAMP php "C:\MAMP\bin\php\php5.6.13"
Keep clicking OK until all windows are closed

Open a directory in MAMP with Grav installed. Right-click and choose Git Bash. You should be good to go. At least it works for me.

  • I say almost as there is seemingly one remaining sticking point: after “bin/grav new-project /C/MAMP/htdocs/my-new-porject” I am unable to complete the process by installing the dependencies. However, I’ll leave that issue for another forum question.
1 Like

I’ve saved this thread and I will endeavor to write up some docs for windows users as soon as I can get a working Windows VM setup :slight_smile:

Two speed-bumps that beginners will encounter

Here are a couple of issues that will slow you down at first – both easily navigated. One is a Windows thing the other is Grav related.

The first issue is Windows related. MAMP will not work out of the box as it will be un-able to start the Apache server and open a connection to localhost. First time you run MAMP a pop-up alert will say,

Port already in use
APACHE needs open port "80' which is already used by another service or application. Please configure 'APACHE' to use free port.

Easy enough to straighten out…

Type ‘services’ into Start search field
Click on item at top of returned list: Services - Desktop App
Scroll down to bottom of the list and right-click on "World Wide Web Publishing Services"
Click on "Stop"
Close the Services window

MAMP will now be able to start the Servers and open a connection to localhost

Note that you will need to repeat this sequence after every computer shut-down or re-start.

There are probably methods to permanently stop Windows from hogging the World Wide Web Publishing Services connection, but it’s not worth my time to pursue. Apparently Windows claims this space for Skype (and probably) other things that, frankly, scare me.

The next issue is a Grav thing.

In my ignorance, I assumed that I could simply click into MAMP htdocs, start up GitBash and create a new project with:

$ bin/grav new-project C:/MAMP/htdocs/zzTestNewestProject

Not so. Git Bash needs to be opened from the root of an already installed instance of Grav in order for Grav CLI to even begin working.

These are a couple of issues that slowed me down. Perhaps others can contribute the speed-bumps (with solutions) that they encountered?