Skip to main content

How to Increase PHP Memory Limit on DreamHost using .phprc (The Correct Way)

 If you are hosting a WordPress site or a custom PHP application on DreamHost, you have likely encountered the "Allowed memory size exhausted" fatal error.

Your first instinct was probably to edit wp-config.php. When that failed, you likely added rules to your .htaccess file, resulting in an immediate "500 Internal Server Error." Finally, you might have tried dropping a php.ini file into your web root, only to find it completely ignored.

This failure occurs because DreamHost’s architecture handles PHP configuration differently than standard cPanel hosts. To persistently increase memory limits, execution time, or upload sizes, you must utilize a specific, non-standard configuration file known as .phprc.

This guide covers the root cause of these failures and details the precise engineering method to override PHP settings on DreamHost using SSH and the .phprc file.

The Architecture: Why .htaccess and php.ini Fail

To solve the problem, we must understand the environment. Most shared hosting environments historically used mod_php, an Apache module that loads the PHP interpreter directly inside the Apache process. In that environment, Apache directives in .htaccess (like php_value) could directly modify PHP runtime settings.

DreamHost, however, utilizes FastCGI (and increasingly PHP-FPM) for performance and security isolation.

The FastCGI Disconnect

In a FastCGI setup, PHP runs as a separate process entirely distinct from the Apache web server.

  1. Apache's Role: It acts as a proxy, passing web requests to the PHP executable.
  2. The Limitation: Because they are separate processes, Apache's .htaccess file cannot modify the internal configuration of the running PHP process. Directives like php_value cause syntax errors in Apache, triggering a 500 error.

The php.ini Hierachy

While PHP does look for php.ini, DreamHost configures the PHP binary to look in a specific, locked global directory first. Local php.ini files in the public web root are often ignored to prevent recursive loading issues or are overridden by the master process configuration.

DreamHost compiles their PHP binaries to look for a user-specific override file located outside the public web root. This file is named .phprc.

Step-by-Step Implementation

We will perform this operation via SSH (Secure Shell). While FTP can be used, SSH provides the ability to force a process restart, which is required for the changes to take effect immediately.

1. Verify Your PHP Version

Before creating configuration files, you must know exactly which version of PHP your domain is using.

Log in to your server via SSH and navigate to your web root (usually yourdomain.com). Create a temporary file to check the version being used by the web server, or check the DreamHost panel.

Note: Running php -v in the terminal might show the CLI version, which can differ from the CGI version running your website.

2. Locate or Create the Configuration Directory

The .phprc file must reside in a specific directory structure relative to your user home.

The path format is: /home/username/.php/phpx.x/

If your user is jdoe and your site runs PHP 8.2, the path is /home/jdoe/.php/8.2/.

Run the following commands to ensure this directory exists. Replace 8.2 with your actual PHP version.

# Ensure you are in your home directory
cd ~

# Create the directory structure if it doesn't exist
# The -p flag creates parent directories as needed
mkdir -p .php/8.2

3. Create and Edit the .phprc File

Now we will create the file. This file functions exactly like a php.ini file but is strictly for user-level overrides.

# Navigate to the config directory
cd .php/8.2

# Create or edit the file using Nano or Vim
nano .phprc

Paste the following configuration. This example increases the memory limit to 512MB, increases the maximum execution time to 300 seconds, and adjusts upload limits to match.

; Increase PHP Memory Limit
memory_limit = 512M

; Increase Max Execution Time (prevents timeouts on heavy tasks)
max_execution_time = 300

; Increase Upload Sizes (optional but recommended)
upload_max_filesize = 64M
post_max_size = 64M
max_input_vars = 3000

Press CTRL+O to save and CTRL+X to exit Nano.

4. The Critical Step: Kill Running PHP Processes

This is the step most developers miss. DreamHost creates persistent PHP processes to handle web requests efficiently. If you edit the .phprc file, the currently running processes will not see the change until they naturally expire and respawn (which can take minutes or hours).

You must manually kill the PHP processes to force a reload of the configuration.

Run the following command to terminate all running PHP CGI processes for your user:

# Kill all processes matching 'php'
killall -9 php82.cgi

Note: Adjust php82.cgi to match your version (e.g., php81.cgiphp74.cgi). If you are unsure of the process name, run ps aux | grep php to see exactly what is running.

Verifying the Configuration

Do not assume the fix worked. Verify it technically.

Method A: WordPress Site Health

If you are running WordPress:

  1. Log in to the Dashboard.
  2. Navigate to Tools > Site Health.
  3. Click the Info tab.
  4. Dropdown the Server accordion.
  5. Check "PHP memory limit" and "PHP time limit".

Method B: The phpinfo() Script

For non-WordPress sites or raw debugging:

  1. Create a file named info.php in your public web root.
  2. Add the following code:
<?php
// Validates runtime configuration
phpinfo();
?>
  1. Visit yourdomain.com/info.php.
  2. Search the page for "Loaded Configuration File" and "Additional .ini files parsed". You should see your .phprc file listed there.
  3. Search for memory_limit to confirm the Local Value is 512M.

Security Warning: Delete info.php immediately after verification. Leaving this file accessible exposes server vulnerabilities to attackers.

Common Pitfalls and Edge Cases

The "Recursive" Error

If you mistakenly place a php.ini file in your web root attempting to load the .phprc file manually, you may trigger a loop that crashes the site. Ensure you delete any old php.ini files in your public folder (/home/username/yourdomain.com/php.ini) when switching to the .phprc method.

Syntax Errors in .phprc

Unlike .htaccess, a syntax error in .phprc usually won't throw a 500 error; PHP will simply fail to parse the file and revert to defaults. If your changes aren't reflecting after a process kill, check your syntax. Ensure you are not using Apache directives (like php_value) inside this file. It accepts standard INI syntax only: key = value.

WooCommerce and Heavy Plugins

If you are running WooCommerce, 256MB is the bare minimum. For high-traffic stores utilizing complex logic (e.g., dynamic pricing, subscriptions), setting memory_limit to 512M or even 768M is standard practice to prevent checkout failures.

Conclusion

Managing server resources on DreamHost requires adhering to their specific FastCGI implementation. While the inability to use .htaccess for PHP config can be jarring for developers used to Apache modules, the .phprc method provides a cleaner, more portable way to manage configuration that persists across CMS updates.

By placing your configuration in ~/.php/[version]/phprc and forcefully recycling the PHP processes, you ensure a stable, high-performance environment for your applications.