Command line PHP overview


DreamHost offers command line interface versions of PHP that are useful for developing shell applications. There are quite a few differences between the CLI (Command Line Interface), SAPI (Server Application Programming Interface), and other SAPIs (such as PHP-CGI). It's worth mentioning that CLI and CGI are different SAPIs even though they share many of the same behaviors. To learn more about these differences, you can begin by reviewing the PHP Manual's chapter, Using PHP from the command line.

View the following article for instructions on how to access your Shell.

PHP locations

The paths for the default DreamHost PHP-CLI installed binaries are as follows:

  • PHP 7.1  – /usr/local/php71/bin/php
  • PHP 7.2  – /usr/local/php72/bin/php
  • PHP 7.3  – /usr/local/php73/bin/php
  • PHP 7.4  – /usr/local/php74/bin/php
  • PHP 8.0  – /usr/local/php80/bin/php

For convenience, DreamHost maintains shortcuts for all PHP versions in the /usr/local/bin/ directory:

lrwxrwxrwx 1 root root 16 Sep 17 2020 php-7.1 -> ../php71/bin/php
lrwxrwxrwx 1 root root 16 Sep 9 2020 php-7.2 -> ../php72/bin/php
lrwxrwxrwx 1 root root 16 Sep 9 2020 php-7.3 -> ../php73/bin/php
lrwxrwxrwx 1 root root 16 Feb 9 11:30 php-7.4 -> ../php74/bin/php
lrwxrwxrwx 1 root root 16 Feb 9 11:50 php-8.0 -> ../php80/bin/php

/usr/local/bin is included in the shell PATH for users by default, so you can use the shortcuts instead of the full path to the binaries.

Support for PHP 5.6, 7.0, and 7.1 is being removed from DreamHost servers, and their binaries may no longer be available on your server via the command line.

Please visit the following article for further details:

Checking the version via SSH

You can confirm the exact version numbers in use by executing the binary from within the shell using the "-v" option. For example, you can check the version of the PHP7.4 CLI binary as follows:

[server]$ php-7.4 -v
PHP 7.4.14 (cli) (built: Feb 9 2021 19:30:37) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.14, Copyright (c), by Zend Technologies

The default PHP CLI interface on DreamHost can be seen by running php -v

[server]$ php -v

Checking PHP modules installed

You can which PHP modules are installed for a specific version of PHP my running the following command.

[server]$ /usr/local/php74/bin/php -m

Just change the PHP number to the version you wish to check. Your terminal will then output all installed modules.

You can also check the following page for a list of active modules.

See also

Did this article answer your questions?

Article last updated PST.

Still not finding what you're looking for?