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, view the FTP article.

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 Domains Control Panel.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 other file types

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 fcgid-script .test
FCGIWrapper "/dh/cgi-system/php56.cgi" .test

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

In the above example, files with the extension .test are using PHP 5.6 with FastCGI.

If you do not want to change the version of PHP but want PHP to use CGI (instead of FastCGI), use this line in your .htaccess file:

AddHandler php5-cgi .test

If you want to use the default version of PHP and CGI, use the following:

AddHandler php-cgi .test
Dh-kb-note-icon.fw.png Note: If you use either the ‘php5-cgi’ or ‘php-cgi’ directive in a FastCGI environment you'll force all PHP code in the specified extensions to be run using CGI regardless of 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) - Soon to be EOL'd
  • PHP 5.4 – /usr/local/php54/bin/php (PHP 5.4.x) - Soon to be EOL'd
  • PHP 5.5 – /usr/local/php55/bin/php (PHP 5.5.x)
  • PHP 5.6 – /usr/local/php56/bin/php (PHP 5.6.x)
Important icon.png Important: It's highly recommended that you upgrade to the latest version of PHP as DreamHost will officially EOL PHP versions 5.3 and 5.4 on all hosting plans on January 26, 2016. Please visit the following pages to view information on how to update to the latest PHP version:

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 can be seen by running php -v

php -v

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 PHP 5.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:
    . ~/.bash_profile

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
Dh-kb-note-icon.fw.png Note: If you’re using tcsh, you must modify the command as shown below 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