From DreamHost
Jump to: navigation, search


PHP, or PHP: Hypertext Preprocessor, is a general-purpose server-side scripting language. It can be embedded within, or used to manipulate, HTML pages.

An example of PHP

The following text that is saved with a file extension of .php, outputs "Hello, world!" when opened with a web browser:

echo "Hello, world!";

Getting information about PHP

The language has a special function called phpinfo() that can retrieve information about a particular installation of itself, and the environment in which it has been installed.

This includes information about:

  • PHP compilation options and extensions
  • the PHP version
  • server information and environment (if compiled as a module)
  • the PHP environment
  • OS version information, paths, master and local values of configuration options
  • HTTP headers, and
  • the PHP License.

Save the file with the following contents using a .php extension. Then, upload the file to a web server and view it in your web browser:


If you need help uploading the file, take a look at the FTP wiki.

PHP on DreamHost

General requirements for using PHP at DreamHost

DreamHost currently allows the following PHP configurations:

  • User-installed PHP running as a CGI application
  • PHP 5 running as a CGI or FastCGI application
  • PHP 5 running as an Apache module (on DreamHost PS only)

DreamHost does not support mod_php on shared servers. For more information about mod_php, you can read more about on the DreamHost blog.

Changing the PHP version on your site

To change the PHP version on any of your domains/subdomains within the panel:

  1. Navigate to the (Panel > 'Domains' > 'Manage Domains') page.
    01 PHP.fw.png
  2. To the right of your domain, click the Edit button under the ‘Web Hosting’ column.
    The ‘Manage Domains’ page appears:
    02 PHP.fw.png
  3. In the 'Web Options' section, select which PHP version from the dropdown menu which you’d like your site to run.
  4. Scroll down and click the blue Change settings button to save your changes.

Advanced topics

Forcing PHP for HTML files

To process files with PHP whose names don't end with ".php", you can use a directive in .htaccess.

For example, create a file named myfile.test with the following code:

echo ‘testing an extension using PHP’;

The extension .test doesn’t exist. But, you can force it to run as PHP by adding this code to your .htaccess file:

AddHandler php-fastcgi .test
Action php-fastcgi /cgi-system/php54.cgi

If you load the file in a browser, it will now load as a normal PHP file.

In the above eample, the site is running under PHP 5.4. If you’re running under a different version, just change the second line. For example, change it to the following for PHP 5.6:

AddHandler php-fastcgi .test
Action php-fastcgi /cgi-system/php56.cgi

Instead, if you wish to use PHP as CGI, then use:

  AddHandler php5-cgi .html .htm

If you use the second directive in a FastCGI environment, you'll force PHP to run as PHP-CGI no matter what option you choose in the panel.

Using PHP from the Command line (PHP-CLI)

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.

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

  • PHP 5.3 – /usr/local/php53/bin/php (PHP 5.3.x where available)
  • PHP 5.4 – /usr/local/php54/bin/php (PHP 5.4.x where available)
  • PHP 5.5 – /usr/local/php55/bin/php (PHP 5.5.x)
  • PHP 5.6 – /usr/local/php56/bin/php (PHP 5.6.x)

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

lrwxrwxrwx 1 root root 16 Feb  7 23:35 /usr/local/bin/php-5.3 -> ../php53/bin/php
lrwxrwxrwx 1 root root 16 Feb  8 00:56 /usr/local/bin/php-5.4 -> ../php54/bin/php
lrwxrwxrwx 1 root root 16 Feb  8 02:12 /usr/local/bin/php-5.5 -> ../php55/bin/php
lrwxrwxrwx 1 root root 16 Feb  8 03:18 /usr/local/bin/php-5.6 -> ../php56/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.

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 PHP5.6 CLI binary as follows:

usernamer@server:~$ php-5.6 -v
PHP 5.6.5 (cli) (built: Feb  8 2015 11:16:19)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2014 Zend Technologies

The default PHP CLI interface on Dreamhost is PHP5.4.

[horsetail]$ php -v
PHP 5.4.37 (cli) (built: Feb  8 2015 08:55:06)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies

Changing the default PHP CLI in shell

In some cases, it may not be practical to have to specify the path to a particular version of PHP for each CLI command. Instead, you may decide to make PHP5.6 the default binary within your user's shell environment.

To change the default version of PHP under your Shell user:

  1. Log into your user via SSH.
  2. Make sure you’re in the user’s directory.
  3. Run the following command to open your .bash_profile file.
    nano .bash_profile
  4. Add the following line to force PHP 5.6.
    export PATH=/usr/local/php56/bin/:$PATH
  5. Update that file by running the following command:

If you now run php -v you’ll see the new version being used. You can also use an alias instead.

alias 'php=/usr/local/php56/bin/php'

This works the same as export PATH when added to your .bash_profile.

If you want these directives to be applied every time you log in, add either of the lines to your shell user’s profile. The current supported defaults are:

    • .bash_profile
    • .kshrc
    • .tcshrc
    • .zshrc
Note2 icon.png Note: If you’re using tcsh, you must modify the command before they can be added to the .tcshrc profile:
alias php /usr/local/php56/bin/php
set path=(/usr/local/php56/bin $path)

You can also modify this accordingly using the path to any of the PHP-CLI binaries.

Changing the output buffer cache

If you are using PHP FastCGI, the PHP functions flush(), ob_flush(), and ob_implicit_flush() will not function as expected. By default, output is buffered at a higher level than PHP (specifically, by the Apache module mod_deflate which is similar in form/function to mod_gzip).

If you need unbuffered output, you must either use CGI (instead of FastCGI) or contact support to request that mod_deflate is disabled for your site.

See also