Overview
This article details how to install a custom version of PHP on a shared server. This allows you to install and build specific packages not available in the standard DreamHost shared installation of PHP.
DreamHost support is unable to assist in any way with this custom installation.
Download PHP
This article uses version 7.2.5.
- Log into your server via SSH.
- Make sure you're in your user's home directory by running the following command:
[server]$ cd ~
- In a browser, visit the following link to choose your desired version of PHP.
- Click the .tar.bz2 link. This takes you to a page where you can select a mirror site. In this example, scroll down to the 'United States' and right click the link for php.net. From the popout menu, choose Copy link address.
- Back in your SSH terminal, download the file using wget. Type in wget and paste the link you just copied.
[server]$ wget https://php.net/get/php-7.2.5.tar.bz2/from/this/mirror
- This saves to a new file named /mirror
- Make sure to check your downloaded file's checksum. Compare it to the version on the downloads page above.
[server]$ sha256sum mirror
- Decompress the file:
[server]$ tar -vxjf mirror
- This creates a new directory named php-7.2.5
Installing PHP
- Make sure you're in your user's home directory by running the following command:
[server]$ cd ~
- Create a /local directory in your user's directory.
[server]$ mkdir local
- Navigate to your PHP download directory:
[server]$ cd ~/php-7.2.5
- Run the following to install:
[server]$ ./configure --prefix=$HOME/local [server]$ make [server]$ make install
- View the creating and editing a file via SSH article for instructions on how to edit your existing .bash_profile. Then enter the following line. This adds your /local/bin/ directory to your user's PATH.
export PATH=$HOME/local/bin:$PATH
- Save and close the file and return to your shell.
- Run the following to update your .bash_profile in the current session:
[server]$ . ~/.bash_profile
- Check where your user is now locating the PHP installation.
[server]$ which php /home/username/local/bin/php
- Also, check which version of PHP your shell is using:
[server]$ php -v PHP 7.2.5 (cli) (built: Apr 30 2018 11:20:21) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
Force your site to use the new version
The new version works for SHELL commands, but your website currently does not recognize it. To make your site use the new version, create an .htaccess file, and put the following lines in it. Make sure to change username to your Shell user.
AddHandler fcgid-script .php
FCGIWrapper "/home/username/local/bin/php-cgi" .php
Create a phpinfo.php file, then visit the file on your site. You'll see it's now using the custom version of PHP.
See also
Internal links
- PHP overview
- php.ini overview
- How do I change the PHP version of my site?
- Default PHP settings at DreamHost