Grav PHP CLI Tutorial

Hits: 2526
| How-To | GRAV CMS, CLI

Change the PHP CLI version

First, why do we want to access Grav's CLI and what is its purpose? The Grav CLI is a powerful tool that runs tasks like downloading plugins and themes to clearing cache or managing updates.

CLI stands for command-line interface and this interface is nativaly dispatched with Grav. It is located at the root of your installation under the directory bin/grav. To access the Grav CLI you will need to use a terminal:

Terminal:

  • Windows = CMD (or command prompt)
  • Mac = Terminal,
  • Linux = Any Shell

Most of the time you will access the Grav CLI via SSH if your site is already hosted. This can be done via your host provider. We will not get into all of the features you can run via CLI but how to configure you host (if not configured already to run) the Grav CLI.

Once you can master CLI for GRAV you will unlesh the full potintual of GRAV. These instructions are based on the newest version of GRAV 1.7.*

The first thing we are going to want to do is check our current php-cli version. This can be done logging into your server (via SSH) to the root directory of your GRAV installation.

Run the Command: php -v which will look something like this:

[USER]@[SERVER]:~/RELATIVE/PATH/TO-GRAV-INSTALLATION$ php -v

Note: [USER] is your username & [SERVER] is the server you are logged into.

This command should return something simular to this:

USER@SERVER:~/RELATIVE/PATH/TO-GRAV-INSTALLATION$ php -v
PHP 7.4.14 (cli) (built: Jan  5 2021 10:45:06) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

NOTE: That the CLI PHP version can be different than the PHP version used by the web server.

Now we know the version of CLI PHP we are running. The way we like to setup GRAV CLI is to run the same PHP version and CLI PHP Version but our host allows us to run different versions at the same time.

So which version should we run?

Grav 1.7 requires PHP v7.3.6 or above and this will also apply to CLI.

If you have signed up for application hosting with fullsailsystems.com this will not be reqiured as it is set as default depending on the version of Grav you have signed up for.

If you need to set this manually we will walk you through the steps to accomplish these.

We will need to modify some configuration files. We can use .bashrc or .bash_profile in your account home folder. This folder is typically found one level above your "public_html" or "web" directories. Create those files if you don't already have them in the user folder. They are hidden files, so you might have to do ls -al to show them. Once the configuration is added, you'll need to start a new terminal session for those settings to apply.

An example configuration could be:

alias php="/usr/local/bin/php53"
export PHP_PATH = /usr/local/bin/php53

An alternative way is to add:

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=/usr/local/lib/php-5.5/bin:$PATH:$HOME/bin'

export PATH

The exact path of course depends on how your system is set up, where it stores the more recent PHP version binaries.

That might be something you find in the Hosting documentation, or you can ask your hosting setup if you do not find it anywhere.

You could also try looking in the php-something files or folders under the /usr/local/bin or /usr/local/lib folders, with ls -la /usr/local/lib/ |grep -i php.


Leave a Comment