---
title: "Custom php.ini file with FastCGI"
description: "In this article we'll discuss how you can set a custom php.ini file per user when using FastCGI on your server. FastCGI is a PHP handler that is good for reducing CPU usage on a server, you might be..."
url: https://www.inmotionhosting.com/support/website/custom-php-ini-with-fastcgi/
date: 2012-10-25
modified: 2021-08-16
author: "InMotion Hosting Contributor"
categories: ["Website"]
type: post
lang: en
---

# Custom php.ini file with FastCGI

In this article we’ll discuss how you can set a custom [php.ini](/support/website/update-local-php-settings/) file per user when using FastCGI on your server. FastCGI is a PHP handler that is good for reducing CPU usage on a server, you might be interested in [choosing the best PHP handler](/support/website/choosing-the-best-php-handler/) for your specific server needs if FastCGI isn’t working well for you.

These instructions will allow you to have separate PHP configurations per user, so for instance you can set different memory limits or use opcode caching only on certain users. Please note that making these changes yourself would require [root access](/support/server/ssh/root-access-faq/) to your server.

1. [Login to your server via SSH](/support/server/ssh/how-to-login-ssh/).
2. Make a backup copy of your cPanel PHP wrapper script with the following command: cp -frp /usr/local/cpanel/cgi-sys/php5 /usr/local/cpanel/cgi-sys/php5-BACKUP
3. Now edit the cPanel PHP wrapper script with your favorite text editor: vi /usr/local/cpanel/cgi-sys/php5 By default this script should look like: #!/bin/sh # If you customize the contents of this wrapper script, place # a copy at /var/cpanel/conf/apache/wrappers/php5 # so that it will be reinstalled when Apache is updated or the # PHP handler configuration is changed exec /usr/bin/php
4. Above the line **exec /usr/bin/php **add the following code: [[ -f ~/public_html/php.ini ]] && exec /usr/bin/php -c ~/public_html/php.ini Now the cPanel PHP wrapper script should look like: #!/bin/sh # If you customize the contents of this wrapper script, place # a copy at /var/cpanel/conf/apache/wrappers/php5 # so that it will be reinstalled when Apache is updated or the # PHP handler configuration is changed [[ -f ~/public_html/php.ini ]] && exec /usr/bin/php -c ~/public_html/php.ini exec /usr/bin/php What this does is uses the Bash syntax for seeing if a file exists **[[ -f ]]** and in this case we’re looking for the file **~/public_html/php.ini**. The **~** symbol would represent the current user calling the script, so this would be the same as entering in either **/home/user1/public_html/php.ini** or **/home/user2/public_html/php.ini** as the full path. The rest of the code simply executes the PHP binary at **/usr/bin/php** with the **-c** flag which sets the location where you’d like to load a php.ini from from. In this case we are telling the server we’d like to use the php.ini file inside the user’s **/public_html/** directory if one exists, instead of **/usr/local/lib/php.ini** which would be the server’s default.
5. Now you’ll want to copy the cPanel PHP wrapper script to a more permanent location, so that your settings are saved if you ever recompile Apache down the road. This can be done using the following command: mkdir -p /var/cpanel/conf/apache/wrappers cp -frp /usr/local/cpanel/cgi-sys/php5 /var/cpanel/conf/apache/wrappers/php5
6. Now restart Apache for the settings to become active: service httpd restart
7. In order to verify your settings have been applied you’ll want to create a PHP info script, the simplest way of doing this is simply copying any of your files to a file such as **info.php**, and then overwriting it with the **phpinfo(); **function: echo ‘<?php phpinfo(); ?>’ > ~user1/public_html/info.php Now when you visit your website and access the newly crated **info.php** script, you should see your custom **php.ini** being loaded next to the **Loaded Configuration File** section [![php-ini-loaded-configuration-file](https://www.inmotionhosting.com/support/wp-content/uploads/2012/10/website_php-ini-loaded-configuration-file.png)](/support/wp-content/uploads/2012/10/website_php-ini-loaded-configuration-file.png)

You should now know how to use custom **php.ini** files for your individual users when you’re using FastCGI as your PHP handler.
