Overview
This article explains how to add and compile PHP extensions and loaders to your website.
Background
Extensions
PHP Extensions are libraries of pre-built code. They allow you to use specific functions already created to simplify your code. See this page for a list of PHP Extensions.
Loaders
PHP Loaders add special types of PHP files that have been encoded with an encoding product such as ionCube Loader.
Checking if an extension is active in the panel
You can view which PHP extensions are available for your domain and which are enabled by default directly in the DreamHost panel.
- Navigate to the Manage Websites page.
- Click the Manage button to open Website settings, which allows you to modify various configurations for your site.
- Select the Settings tab.
- Next to PHP, click Manage.
-
In the PHP Settings section, click Modify to the right of Extensions.
The following sections display:
Optional Extensions
These extensions are optional and can be enabled or disabled using the toggles.
- gmp — Provides support for arbitrary-precision arithmetic using the GNU Multiple Precision (GMP) library.
- tidy — Cleans and repairs HTML and XML markup, and can be used to format output.
Auto-enabled Extensions
This section lists PHP extensions that are automatically enabled and cannot be modified, as they are included to ensure compatibility with common PHP applications (like WordPress) and platform features. The extensions shown depend on the PHP version currently selected for your domain.
You can also view active extensions by adding a phpinfo.php file to your site.
If an extension is active, you'll see its corresponding block when visiting the phpinfo.php file. For example, search for the word Phar, and you see Phar: PHP Archive support and enabled.
- Click the Save Changes button when finished.
Enabling an extension
The following steps only apply to extensions that are already installed with the version of PHP currently on the server, but are not currently enabled. The section below should be used instead if the extension is NOT installed on the server.
The following steps add code to your user's phprc file to enable an extension.
Create a phprc file
See the following articles for instructions on how to create a phprc file:
If the file already exists, you just need to update it using either an FTP client or SSH:
Load the extension
Add a line to your phprc file to load an extension using this syntax:
extension = extension_name.so
Kill off all running PHP processes
Make sure to kill running php processes to ensure your new settings take effect.
Confirm your changes
After you've edited the file and killed off all PHP processes, check to confirm the extension has been enabled by creating a phpinfo.php file. When you view this file in a browser, you should see the extension listed.
If you do not see your changes have updated, try killing off all PHP processes again.
Compiling PHP extensions
These steps are only necessary if an extension is NOT already installed on the server. See the section above to make sure which ones are installed using a phpinfo.php file.
Although DreamHost includes the most common PHP extensions needed for your website, you might need to configure and compile additional ones.
Please be aware of the number and types of extensions you add, as these can significantly impact your site’s performance.
In the following instructions, replace myphpextension with the name of your extension.
Download the PHP extension and file
Download the PHP extension you wish to use into your user's home directory on your DreamHost server. It should be a .tar.gz file, which you can find on one of the following sites:
Then, run the following command to download it to your user's home directory:
[server]$ wget myphpextension.tgz
Change to the home directory
Make sure you are in your user's home directory by running the following:
[server]$ cd ~
Extract the file
Use the command below to extract the file:
[server]$ tar -xvzf myphpextension.tgz
Then, change to directory the file was extracted to:
[server]$ cd myphpextension/
Run the phpize version
phpize is a command-line tool that comes with PHP and is used when you want to compile and install custom PHP extensions from source code.
Run the version of phpize that matches the version of PHP your site uses. For example, if your site uses PHP 8.4, run the following command:
[server]$ phpize-8.4
Specify the path
The instructions that come with your PHP extension should include a command to configure it. It may look like this:
[server]$ ./configure --enable-myphpextension --with-php-config=/usr/local/php84/bin/php-config
Compile your extension
Compile your extension using the make install command:
[server]$ make
Check the output to see where the libraries are installed. You should see something like this:
Libraries have been installed in: /home/username/myphpextension/modules
If you are following the documentation included with your PHP extension, you do not need to run make install, as you are not modifying the server's PHP configuration directly. Instead, perform a local change to the PHP configuration for your user account.
Include the path to the .so file
If you compiled your own PHP extension, be sure to include the full path to the .so file:
zend_extension=/home/username/.php/extensions/myphpextension.so
Organize your extensions and copy your .so file (optional)
To keep your custom PHP extensions organized, create a directory for them in your user's .php directory:
[server]$ mkdir -p $HOME/.php/extensions/
A .so file is a type of compiled library file used primarily on Unix-like systems (such as Linux) — including those where PHP runs. Copy your .so file to the new directory you just created:
[server]$ cp modules/myphpextension.so $HOME/.php/extensions/
WebP
Support for the WebP image format is available via GD, which is activated by default on DreamHost servers.