Forum Moderators: coopster

Message Too Old, No Replies

PHP Configuration Settings

Changing the settings on php.ini has no effect

         

Foxhole

1:30 pm on May 8, 2010 (gmt 0)

10+ Year Member



Hi all,

I hope I am posting this in the right part of the forum,

As I am learning to write php into my web pages and thought it would be wise to set up a local test environment.

I am using PHP with the Apache 2.2 web server, I have them both installed and working together ok.

A book I am reading recommends that I change the following settings:

display_errors, Off to On
error_reporting, On to Off

I open the configuration file for PHP (php.ini) and make the necessary changes to the code, after restarting Apache and checking the settings, they still have not changed.

The settings say my file locations are:

Configuration File (php.ini) Path : C:\Windows
Loaded Configuration File: C:\Program Files (x86)\PHP\php.ini

There does not seem to be a php.ini file located in C:\Windows and the configuration file that I have actually changed is C:\Program Files (x86)\PHP\php.ini.


There is also a small paragraph in this book which says: "Frequently Windows users complain that changes to php.ini have no effect. This usually means an old version has been left in the Windows system folder and is taking precedence. Remove the redundant file, and restart your web server.

I have looked in Windows/System folder and there is no such file there,

Something else to note, I have tried removing the php.ini file from C:\Program Files (x86)\PHP\ and it still seems to load a configuration file from somewhere.

Can somebody please tell me why my settings are not changing, is there something that I am doing wrong? I change the settings by simply opening php.ini in notepad and changing the settings text then saving, (after giving myself administrative rights to the file).

Thank you all in advance for your help,

Best regards,

Foxhole.

Matthew1980

6:50 pm on May 8, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there Foxhole,

Are you looking in the right place! The php.ini file usually resides in the php directory on the root of your c:/ if you are installing them as seperate programmes.

Do a search of your PC and you should only find one copy of the php.ini file, this should be in the php install dir too, at least this is what I have found doing installs over the years on various laptops & desktops!

This is why it is usually recommened (if you are doing a localhost install) to use something along the lines on WAMP or XAMP, as this is just an all-in-one install, ie everything is done for you :)

With regards to the setting of the error_reporting(); generally what should be done, and is easier is this:-

<?php
//turn on & set error_reporting
error_reporting(E_ALL); //do E_ALL | E_STRICT if you want to though
//
//Rest of your code
//
?>

This is a recommended thing if you are developing a website locally, though you must remember to comment out the line when you go live, as this can reveal aspects of your site to potential hackers. But if you are not sure what you are doing with your ini file, it is generally best to make a copy of it so you can at least put the original version back.

Just out of curiosity what book are you reading? There are lots of good ones out there, but some books teach rather odd ways of doing things, check out the book from "Luke Welling and Laura Thomson", I have a well thumbed copy, it is an excellent reference book, though there are lots to choose from ;)

Hope this helps you ;)

Cheers,
MRb

Foxhole

9:33 am on May 9, 2010 (gmt 0)

10+ Year Member



Thanks for the response MRb,

I have done the search of my pc and the only php.ini file found is as my settings say is the loaded configuration file located in: C:\Program Files (x86)\PHP\php.ini , and this is the one I made the changes to.

I think I will just add the code like you have suggested whilst testing my page, it will give me the same result but less of a headache!

The book I am reading is: PHP Solutions, Dynamic Web Design Made Easy - David Powers. To be honest, the more I read this book the more I realise I made a bit of a mistake buying it. It purely rely's on you downloading the tuition files and has you altering aspects of the code.
I prefer to learn by typing the code out fully, this way it helps drum in the information and learn properly. There is very little in the way of PHP coding shown in this book, more snippets of code.

I will have another look around for a better book I think, as this seems a bit harder to pick up than HTML or CSS.

I have written out a simple form to practice with, my XHTML coding for my form is this:



<form action="" method="post" id="enquiryform">

<fieldset>

<p id="compulsoryfields">Fields Marked * Are Compulsory.</p>

<p>
<label for="subject">Subject *</label><br />

<select name="subject" id="subject" tabindex="1">

<option value="">Select</option>
<option value="General Enquiry">General Enquiry</option>
<option value="Quotation">Quotation</option>

</select>
</p>

<p>
<label for="name">Name *</label><br />
<input type="text" name="name" id="name" tabindex="2" />
</p>

<p>
<label for="email">Email *</label><br />
<input type="text" name="email" id="email" tabindex="3" />
</p>

<p>
<label for="message">Message Or Enquiry Below</label><br />
<textarea name="message" id="message" rows="11" cols="30" tabindex="4">
</textarea>
</p>

<p>
<label for="updates">I Would Like To Receive News Updates:</label><br />
<input type="checkbox" name="updates" id="updates" value="n" tabindex="5" />
</p>

</fieldset>

<input type="submit" value="Send This Enquiry" tabindex="6" />

</form>


Between the action quotes, is this where I define the delivery email address?

Would you be able to point me in the right direction with some simple php coding to get me off on the right tracks please, in the mean time I will be sourcing a new beginners book!

Thanks again for your help,

Much appreciated,

Best regards,

Foxhole

Matthew1980

5:34 pm on May 9, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there Foxhole,

Right then, this is extremely simplified code, there is no error checking or blank entry checking here this is just used to illustrate how to do a simple mail script, and as it is literally typed "on-the-fly", there is more than likely some errors in there. I am just trying to show you some of the building blocks of doing a simple mail script.

If you leave the action="" attribute blank, the form by default will post back to itself, hence why I have done the php code in the same file.

There are other things as you could add to this to make it secure, again, this is purely as an illustration.

I have used the strip_tags() function on the inputs to show that you can try to stop any bad code being submitted that may harm your site, use mysql_real_escape_string() to do the same to any data that is being used in conjunction with any sql queries.

Hope this helps you a bit, and good luck finding a decent book.

A good website to check out is: [w3schools.com ] This is excellent if you want to learn coding to standards set out by the W3C people, I learnt a lot here.

And of course: [php.net ] also the mail function directly: [uk.php.net ]

The action attribute is used to tell the form where it should look to send the data that is being submitted by the form, so in effect this is where you are sending the data, this can either be the same file ((action="")default) or to a specific file ie action="mymailfile.php" when you specify a file, make sure that the file path is used, or if its in the same directory as the form file, use this: action="/mymailfile.php"

Anyway, have fun!

<?php
if(isset($_POST['submit']) && ($_POST['submit'] == "send comments")){
//assign vars
$formname = trim(strip_tags($_POST['name']));
$formemail = trim(strip_tags($_POST['email']));
$formsubject = trim(strip_tags($_POST['subject']));
$formcomments = trim(strip_tags($_POST['comments']));

$mailheaders = "MIME-version: 1.0\r\n";
$mailheaders .= "content-type: text/plain; charset=UTF-8\r\n";
$mailheaders .= "your friendly webmaster! <someone@somesite.com>\r\n";

mail($formemail, $formsubject, $formcomments, $mailheaders);
?><!--break out of php here to allow easier html editing-->
<html>
<meta refresh>can be used to redirect the page back to homepage etc
<body>
<div>Thanks for the mail, see you again soon!</div>
</body>
</html>
<?php
//break back in to close script
exit;//this terminates the script so that you won't get the form echoed twice :)
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Email Template</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<base href="" />
<meta name="description" content="" />
<meta name="keywords" content="" />
</head>
<body>
<form action="" method="post">
<p>
Your name:<input type="text" name="name" />
</p>
<p>
Your email:<input type="text" name="email" />
</p>

<p>
The subject:<input type="text" name="Subject" />
</p>
<p>
Your Comments:
</p>
<p>
<textarea name="comments" cols="50" rows="25"></textarea>
</p>
<p>
<input type="submit" name="submit" value="send comments"/>
</p>
</form>
</body>
</html>


Cheers,
MRb

Foxhole

5:40 pm on May 10, 2010 (gmt 0)

10+ Year Member



Hi MRb

Thank you so much for your time and effort explaining things to me, it makes a little more sense now, I suppose the best way is to practice, practice and more practice! I have my web site up and running now so I can try it properly and see how (and if) the email arrives to my message box.

Thanks again and I really appreciate your help,

Best regards,

Foxhole

Matthew1980

6:50 pm on May 10, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there Foxhole,

I'm glad as you are getting somewhere now! The first stages can be quite daunting, especially when you are attempting sending an email via a website form being submitted.

The Way I usually test it is by developing the entire system locally, because when you attempt to connect to the smtp server for outgoing mail using a localhost type environment, the php parser throws an error saying something like "cannot connect to smtp server on port 25" and when you get that error you know as you have the mail(); function being called. But the trouble with the mail() function is - you cannot guarantee the mail being delivered until you actually have it arrive in the inbox of the specified email account.

There are some ready made scripts available that allow for things like attachments too, phpmailer is one that springs to mind, though I have used it in the past, I find it a little complex for my own requirements, though its nice to know as there are things like that available.

Anyway, good luck with the "alpha/beta testing", and any problems, just post a new thread on the forum, and there are plenty of people here to help/advise.

Cheers,
MRb

Foxhole

6:19 pm on May 17, 2010 (gmt 0)

10+ Year Member



Hi again all,

I am still having the same issue, The changed settings to my php.ini file have absolutely no effect what so ever, it says the loaded conficuration file is: C:\Program Files (x86)\PHP\php.ini, I have even removed this file from the folder and it still brings up the same info!

I am getting very confused with this now, I have even tried adding in the code manually to display errors as Matthew1980 instructed me, this still does not report any error messages just a white blank screen, if I remove the code then I get the standard internet explorer error saying either the web page is unavailable or there is an error in the code.

Is there anyone out there that can please help me?

Thanks again all,

Best regards,

Foxhole

Matthew1980

7:16 pm on May 17, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there Foxhole,

Right, first question: Can you get any script to run? Try this:-

<?php
echo phpinfo();
?>

Save it to something like test.php and save it in your server root directory, and access it from your browser, using your localhost address.

When you view this file it should reflect the changes as you have made in the ini file search the page for error_reporting, and display errors, they should be listed under the heading of "core", I have just checked my own to see.

The only other thing I will ask you is, are you installing the components under 1 application (Programs like WAMP or XAMP) or is it seperate installs for each program? Even so they should still be functional, and usually the first type of script any book will get to to run to test the installation is the one I have given above.

Hopefully I have understood you correctly,

Cheers,
MRb

Foxhole

5:12 pm on May 18, 2010 (gmt 0)

10+ Year Member



Hi again Mrb!

Once again, thanks for getting back to me and helping out.
I can get scripts to run, the code you have put there that is the same code I am currently using to check my settings:

<?php
echo phpinfo();
?>

Then looking in the "Core" section.

In the top section it says:

Configuration File (php.ini) Path : C:\Windows
Loaded Configuration File: C:\Program Files (x86)\PHP\php.ini


And the settings I wish to change are:

display_errors, Off to On
log_errors, On to Off




When I have figured out how to change these settings, I will need to also incorporate mySQL, is this also going to be a bit of a task?

If I wanted to pay someone who is able to help me set up, configure and check over my local test environment, where would I start looking? as I suppose this is a little off the beaten track for I.T. isn't it? It would just give me a little peace of mind that everything is set up as it should be and leave me to just learn the programming.


By the way, they were installed as seperate items,

Best regards,

Glenn

Matthew1980

6:59 pm on May 18, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there Foxhole,

Something has just occurred to me, the settings that you are changing is it this:-

[size=1]; (php website url here)
[b]error_reporting = E_ALL | E_STRICT[/b]

; This directive controls whether or not and where PHP will output errors,
; notices and warnings too. Error output is very useful during development, but
; it could be very dangerous in production environments. Depending on the code
; which is triggering the error, sensitive information could potentially leak
; out of your application such as database usernames and passwords or worse.
; It's recommended that errors be logged on production servers rather than
; having the errors sent to STDOUT.
; Possible Values:
; Off = Do not display any errors
; stderr = Display errors to STDERR (affects only CGI/CLI binaries!)
; On or stdout = Display errors to STDOUT
; Default Value: On
; Development Value: On
; Production Value: Off
; (php dot net url)
[b]display_errors = on[/b][/size]


Which is exactly what my ini file say's (copied and pasted from my own ini file)

don't alter this one:-

[size=1]
; display_errors
; Default Value: On
; Development Value: On
; Production Value: Off

; display_startup_errors
; Default Value: Off
; Development Value: On
; Production Value: Off

; error_reporting
; Default Value: E_ALL & ~E_NOTICE
; Development Value: E_ALL | E_STRICT
; Production Value: E_ALL & ~E_DEPRECATED

[/size]


The ones with the ; preceding the directive are there just to show the options, the one's I have put as bold are the ones that will reflect when changed in the phpinfo() script.

Also changing the error_reporting() will show a numeric value when set, otherwise, it will show not set (in italic)

I have a feeling as you have been changing the wrong one :)

Oh, and as you are using individual programmes, I don't see that there would be a problem with installing Sql, try it, personally I go with wampserver, an all-in-one installation that takes the hassle out of setting up a localhost environment on your computer.

Hope this helps you, other than that I am stumped!

Cheers,
MRb

Foxhole

5:00 pm on May 19, 2010 (gmt 0)

10+ Year Member



Hi there MRb,

Be stumped no longer, that thing that occured to you was just the thing that I was doing wrong, I have changed the text back that I had wrongly changed and then made the alterations to the lines where you said, without the preceding ;. I just restarted the apache server and all works well, settings have changed and errors are shown!

You have made my day!

Thanks again for all your time and effort helping me out, the way things are going, I'm sure it won't be the last time you see me on here.

I suppose in hind sight it would have been better to go for one of the all in one packages and have the headache taken out.

When I install Sql, is it another one of these programs that requires path names and settings manually changing, or is it fairly straight forward?

Cheers,

Foxhole

Matthew1980

6:43 pm on May 19, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there Foxhole,

Glad your all sorted now! I would have been stumped if you had come back saying it was still not working..

No problem about the help - that's what this forum is all about, and as it's an archive it should helps others too.

With regards to installing mysql, it's been about 5 years since I last set up as individual installs - I'm not trying to discourage you at all, try it and see what happens. I can't remember if you have to set any parameters or not, I think you have to set an admin password, but I could be wrong there.

If you carry on the install, you will need to install phpmyadmin or similar so that you can use the mysql database via a GUI, as doing it though the command/console line is tricky if you don't know what your doing.

Again - not trying to put you off at all ;)

All the best for the rest of your coding!

Cheers,
MRb

Foxhole

4:54 pm on May 20, 2010 (gmt 0)

10+ Year Member



Cheers MRb