Occasionally you might need to run a script from the command line in Vagrant (VVV)
I needed to do this when setting up a local version of a site for testing upgrades. Normally I do a search and replace on the domain name to change it to the .test equivalent but in this case the web based version of the script was timing out with the popup suggesting using the cli version of the script instead.
Time to complete: 10 minutes
- Log into the VagrantBox via ssh
- Locate php
- Determine which version of PHP your script requires
- Update the path th the PHP runtime in the script
- Run your script
1. Log into the VagrantBox via ssh
Run the following command to log into the vagrant box via ssh, you must be in a terminal in your vagrant root directory
2. Locate php
Run which to locate the directory where php is installed
This will output something like
3. Determine which version of PHP your script requires
You may have to complete this step after trying your script out via the command line. It will probably throw errors that it requires a specific minimum version of PHP in order to run.
You can see which versions of PHP are installed in VVV by browsing to the directory in the previous step and listing the directory contents. The path for other versions is something like:
4. Update the path th the PHP runtime in the script
My script needed a different version of PHP in order to run, so I had to update the script to use a specific version
5. Run your script
For Search & Replace DB I needed to run the following:
./srdb.cli.php -h localhost -u root -p root -n soy -s "https://domain.com" -r "http://soy.test"
Initially it complained about the PHP version being too low, so I had to go back to step 4 and update the shebang to use the correct version