How to Find the Location of Your php.ini File

tutuploadsphp.gif

A critical file you often need to manage is the php.ini file. It controls many import aspects of what you can and can not do with your site, including the size of files that you can upload.

Different hosts use different schemes for storing and accessing files and so you’ll need to research where your php.ini file.

This tutorial will show you how to find the location of the file on any server.

Step 1. Create a script to display your PHP information

tutuploadsmedia_1330111995810.png

You’ll need to create a very simple php script and place it in your home directory. Using a script editor or a plain text editor (not a word processor) create file called phpinfo.php with this code:

{codecitation}<?php phpinfo(); ?>{/codecitation}

That’s all you need. Just one single line. Save the file and call it phpinfo.php.

Upload this file to the public_html directory or whatever your main HTML directory is called.

In your browser address bar, access the file by typing in: http://yourdomain.com/phpinfo.php

You’ll get a complete list of all your php settings. In the phpinfo.php page you can see:

  • the PHP version at the top of the file.
  • the location of your php.ini file

If you scroll down the page, and you can find the current version of MySQL. and php settings like safe_mode and register_globals and much much more.

tutuploadsmedia_1330112143774.png

This will work on your local computer using XAMPP or WAMP as well. This is what my XAMPP installation looks like.

GoDaddy servers are a Special Case

tutuploadsmedia_1330112626882.png

When you run phpinfo.php on the GoDaddy server you’ll see the php5.ini file located in /web/config/php5.ini.

This folder is inaccessible using FTP or the File Manager in the control panel, so you cannot make changes to it if you need to fix errors. To fix this you need to make your own php5.ini file and upload it to your html directory.

tutuploadsmedia_1330112876304.png

Use FTP or your file manager to upload or create a php5.ini folder in your main directory on GoDaddy servers.

IMPORTANT: on GoDaddy, if you are running PHP 4, name your initialization file php.ini. If you are running PHP 5, name your initialization file php5.ini. Always upload the initialization file to the root directory of your site.

tutuploadsmedia_1330113031325.png

Now run your phpinfo.php script and you will see the path to the one you uploaded. You can edit this file to make changes to your PHP settings.

Instructor

0 0 votes
Blog Rating
Subscribe
Notify of
29 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
$herman

Thanks for informative article, it’s bookmarked. Now all I need to do is figure out what settings I need.Getting “Warning: Cannot modify header information – headers already sent by (output started at /home/content/…” error. You helped point me in the right direction. $herman

leandantio18

I am using Godaddy server and I have created a program to upload large files. When I try to upload, after 4 min, the connection gets reset/timed out. I have made changes to the server control panel and also in my php.ini i.e I adjusted the memory_limit, max_upload_filesize and post_maxi_size and still I face the same problem….so as you suggested in your article….if I create php5.ini will this solve my problem ??….Please help

Techh Dann

Are you trying to upload these files using FTP? If so FTP may have some issues with that, you may have to switch the user to SFTP and do it again.

Prof BJ

Thanks a lot! I just used the information to solve a magic_quote issue on my Joomla 3.0 website

Wes

mine didnt even work 403 error

Wes

Mine literally just brings up the strip of code in for actual file… What am i doing wrong?

Craig

I know this is an old post, but maybe this’ll help someone else. I just ran into this problem, myself, on a local WAMP-type installation (Acquia Dev Desktop2). The problem is that after I created the phpinfo.php file in the appropriate directory, I just dragged it to my browser (or entered the local path to the file). The solution was to enter the actual address that you would to view your local website followed by /phpinfo.php NOT file:///C:/Users/…/phpinfo.php
Worked as advertised after I actually followed the directions 🙂

Da Burga Chef, Fool!

yeah, this totally doesn’t work at all

unadventurer

I know this is an old post but.. It was the only one that clearly on concisely showed how to do this. Thank you!

zo

very clear, thank you – but on my phpinfo() my php.ini file is at /usr/lib/php5.4/php.ini but I don’t know how to locate that – help please anyone!!!

Trailsnails Trailsnails

same problem, did you solve it? how??

raghavendra

my form is not submitting the message …I am getting this error …. Could not send mail! Please check your PHP mail configuration……help me..and here is my code….
‘error’,
‘text’ => ‘Request must come from Ajax’
));
die($output);
}
//check $_POST vars are set, exit if any missing
if(!isset($_POST[“userEmail”]) || !isset($_POST[“userName”]) || !isset($_POST[“userSubject”]) || !isset($_POST[“userMessage”]))
{
$output = json_encode(array(‘type’=>’error’, ‘text’ => ‘Input fields are empty!’));
die($output);
}
// DETECT & PREVENT FROM HEADER INJECTIONS
$malicious = “/(content-type|bcc:|cc:|to:|href)/i”;
foreach ( $_POST as $key => $val ) {
if ( preg_match( $malicious, $val ) ) {
exit( ‘FAILURE’ );
}
}
//Sanitize input data using PHP filter_var().
$user_Name = filter_var($_POST[“userName”], FILTER_SANITIZE_STRING);
$user_Email = filter_var($_POST[“userEmail”], FILTER_SANITIZE_EMAIL);
$user_Subject = filter_var($_POST[“userSubject”], FILTER_SANITIZE_STRING);
$user_Message = filter_var($_POST[“userMessage”], FILTER_SANITIZE_STRING);
//additional php validation
if(!filter_var($user_Email, FILTER_VALIDATE_EMAIL)) //email validation
{
$output = json_encode(array(‘type’=>’error’, ‘text’ => ‘Please enter a valid email!’));
die($output);
}
if(strlen($user_Message)’error’, ‘text’ => ‘Too short message! Please enter something.’));
die($output);
}
// SEND EMAIL
$sentMail = mail(
// RECIPIENT
$to_Email,
// SUBJECT
$user_Subject,
// MESSAGE
$user_Message,
// HEADERS
“From: =?UTF-8?B?” . base64_encode( $user_Name ) . “?= \nReply-To: ” . $user_Email . “\nMIME-Version: 1.0\nContent-Type:text/html;charset=utf-8\n”
);
if(!$sentMail)
{
$output = json_encode(array(‘type’=>’error’, ‘text’ => ‘Could not send mail! Please check your PHP mail configuration.’));
die($output);
}else{
$output = json_encode(array(‘type’=>’message’, ‘text’ => ‘Thank you ‘.$user_Name .’! Your message was successfully sent.’));
die($output);
}
}
?>

Prins Prem

Hi im using godaddy server and im not able to find php.ini file in cpanel and in the file directory

ジョアン

Mine looks like this: /opt/users/ipg/g/l/ipg.glenatgrandviewcom/php53/php.ini
I’m not even sure where to find that… Any tips?

Mecatronium Chips

Looks like you have Netfirms hosting :
1. Log in to your Netfirms Control Panel.

2. Go to CGI and Scripted Language Support.

3. Click PHP Scripting.

hugronaphor

just run:

$ php –ini

Mayapur Voice

Pretty strange that there isn’t a simple “find” command! 🙂

James Abran

if i have a php.ini file in my wordpress installation and unfortunately it got corrupted or something.. can the default php.ini file do its job? or does my site goes down?

trynodev

A new php5 or php ini files does not work for me. Nothing works to upload large files on my GoDaddy WordPress multi-site account. The recommended “Add from server” plugin does not work. The backup version does not work. The developer does not know. I have all my settings at the right levels in the cPanel configuration settings. I certainly can’t add directly though my WordPress media browser. GoDaddy said I can’t do anything more on the hosting end. Creating a user.ini files does not work. Nothing. They said WordPress was easy, but this shit is not at all.

Josh

Any info about if you’re using Azure as a host? I ran the above script and got: (took out the config command to save space)
PHP Version 5.4.45

SystemWindows NT RD0003FFACDD06 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586

Build DateSep 2 2015 23:45:20

CompilerMSVC9 (Visual C++ 2008)
Server APICGI/FastCGI

Virtual Directory Supportdisabled

Configuration File (php.ini) PathD:\Windows

Loaded Configuration FileD:\local\Config\PHP-5.4.45\php.ini
Despite it saying its in the D drive, I know its not on my computer, (D drive is the DVD dive). I’m going to try and get at it from Filezilla. Its not showing in my Visual Studio files list.

adminDomo

is there a command line for that?

BuzzyMag

Help…Mine is in /opt/php.conf.d/[username privacy :].ini ……….wth?!?! My hosting is Hostinger(NL) please help me!! i’ve already filed a ticket but they refused to help me. I cant find /opt anywhere.

no

For a hosting it’s insecure to allow customers to edit php.ini or accessing directories other than your home dir.

Full Picture Art

Thanks for valuable info. i will follow these steps as you shared with us.

Yaqub

What if you are using PHP 7? do you rename it php7.ini ?

Mark

great tutorial through and through. simple directions to finding the php.ini file location. Thanks!

Mario Digiglio

my loaded conf file display (none)! what I can do?

Md. Sahidul Islam

Thank you so much for this article and it was helpful for me a lot.

mikall

So glad OST was able to help you!

29
0
Would love your thoughts, please comment.x
()
x