Knowledgebase

Back to File Management

How To Make A php.ini File Recursive


This article is for cPanel Web Hosting Accounts.

Accounts in the cPanel shared may have trouble with local php.ini settings because you cannot change the server php.ini and using local php.ini files is not recursive by default.

This guide will add some direction on making a local php.ini file recursive. In this example, I will be using the domain name of example.com, which has a cpanel/ftp username of example and a password of PaSSword.

Step 1. Log into your account via SSH. If you do not have SSH access, please submit a ticket to Technical Support (for legacy clients) with account verification so that we can enable SSH for your account.

For clients within CHI please submit a ticket through the support section of your CHi account: Support Tab Overview in CHI

WINDOWS:

If you are using windows, you will want to download and run PuTTY. You can download it at http://www.chiark.greenend.org.uk/~s…/download.html

If you aren’t sure which one you need, you will want the very first option for Putty (putty.exe) under “For Windows on Intel x86.”

Once downloaded, open it up and type your domain name into the Host Name. Port 22 should be used by default, if it isn’t put in port 22, then push Open.

A Security alert will come up asking you if you trust the host. Push Yes and you will be.

This will bring you to a black dos-like window asking for a username. Put in your cPanel/FTP username that UK2 sent you. (This is not usually the same password that you use at Dashboard (controlpanel.uk2.net) or (chi.uk2.net). It will be in your welcome e-mail and it will say “cpanel/ftp” before the username and password).

So in this example I would type in ‘example’ for the username, and ‘PaSSword’ for the password.

Also note that when you put in the password it will not show anything that you are typing, no stars, or dots or anything, just type in the password and hit “enter” when prompted to do so. You are now connected to your server via SSH.

MAC:

If you are a Mac user, open up Terminal (Applications-> Utilities -> terminal) This will open up a black background dos-like window. Type in the following command without the quotes:

‘ssh user@domain.com’ then press enter. So in my case I would enter in ‘ssh example@example.com’. This will ask you if you trust the host, type in yes and it will bring you to a command prompt. You are now connected to your server using SSH.

Step 2: Make a copy of the server php.ini in your public_html directory and add a line to your .htaccess file to make it recursive to your sites.

This seems like a lot to do, but fortunately, you can do it all with one command that you just need to copy and paste into the command line. Copy the following line and and paste it into the command line and press [ENTER]. (For putty users, right click is paste in putty. Ctrl+V will do nothing in the putty window, so copy the line and the right click in the putty window.)

cp -i /usr/local/lib/php.ini $HOME/public_html/ && echo >> $HOME/public_html/.htaccess && sed -i -e ‘s/^\s*SetEnv PHPRC/#SetEnv PHPRC/i’ -e “1i # UK2.NET Custom php.ini\nSetEnv PHPRC $HOME/public_html/php.ini\n” $HOME/public_html/.htaccess

Make sure to copy it all as one big line. Once you hit enter, this command will place a php.ini file into your public_html directory and add the line “SetEnv PHPRC /home/username/public_html/php.ini” to your .htaccess file substituting your username for ‘username’.

Step 3: Edit php.ini

Now that the php.ini is in your account in an editable state, you can make changes to it that will affect the way php runs on your site. You can edit this file by downloading it, opening it in a text editor making and saving changes and then reuploading it, or by using a text editor such as ‘vi’ in your SSH session.

You can also log in to your cPanel control panel and click on file manager. Either open directly to your web root (www/public_html) or navigate there after opening file manager. Once there you will see a file in the list named ‘php.ini’. Check the box next to it and click on the “Code Editor” button at the top of the page.

You can also do this with the edit button, but I prefer the code editor as it provides line numbers and color codes to help with the changes. If you are asked what type of character encoding to use, just use us-ascii (it should be the default) and click the edit button at the bottom.

Once the code editor is open, you will see the text of the file. I recommend reading the opening warning paragraph and the “About this file” section. The most common changes required by users for programs or scripts is memory settings, and max uploads. The easiest way to do this is to push ctrl+f which brings up a find box. Put in a key word, such as ‘memory’ or ‘upload’ and press find next until it finds the line you are looking for.

Some common changes:

max_execution_time = 90
max_input_time = 60
memory_limit = 32M

The limits on your account may be different, this is just an example. To allocate more memory to php scripts, just change the 32 MB to whatever it needs to be like 64M or 128M if the script is really a memory hog.

To change the max upload size, search for upload_max and it should take you to about line 499 which will look like this:

; Maximum allowed size for uploaded files.
upload_max_filesize = 64M

just change the 64MB to whatever you need, and note that when changing upload size you will almost always want/need to change the post_max size.

; Maximum allowed size for uploaded files.
upload_max_filesize = 64M

Change that parameter to match what you set for upload and then save the changes. All other php settings will be changed in a similar fashion. Many parameters are simply changing Off to On or On to Off such as enabling php logging, or url_fopen.

As soon as the php.ini file is saved, the changes will go into effect.


Related Articles

How To Create A Backup of A Website Via FTP
How To Use File Manager In CPanel
How To Create A Custom 404 Error Page
How To Upload Files To My Website
Can I Use A .htpasswd File On My Account

Can’t Find what you need?

No worries, Our experts are here to help.