New Feature: Playlist Center! Pick a topic and let our playlists guide the way.

Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Configuring PHP

From: PHP with MySQL Essential Training

Video: Configuring PHP

In this movie, we're going to configure PHP to the settings that we like and we need for this tutorial. Three things that we're going to be looking at, error reporting, output buffering, and timezone. Those are the three areas that we want to address. In the last movie, I showed you how to get the PHP info page. You do that from your WAMPSERVER menu, and you choose local host and that will take you to the main WAMPSERVER page, and then phpinfo is a link down here that will actually take you to it. So once you're on that page, this has all the information about the way in which php is configured.

Configuring PHP

In this movie, we're going to configure PHP to the settings that we like and we need for this tutorial. Three things that we're going to be looking at, error reporting, output buffering, and timezone. Those are the three areas that we want to address. In the last movie, I showed you how to get the PHP info page. You do that from your WAMPSERVER menu, and you choose local host and that will take you to the main WAMPSERVER page, and then phpinfo is a link down here that will actually take you to it. So once you're on that page, this has all the information about the way in which php is configured.

So you can always come here if you want to see what is php running right now. What are its configuration options that it's using? This will tell you. The most important one of those is this one. Loaded configuration file. That tells us where the configuration file for PHP lives. It's called php.ini. Now WAMP also gives you a short cut so that you don't actually have to go directly there. You can just go to the WAMP menu and then under PHP you'll see there's an option for php.ini. Lets open that up now. Now it opens up in your default text editor.

For me right now, that's just Notepad that's built into Windows. And these are all the configuration options. Every line with a semi colon in front of it is a comment line. That means that it's not actually being processed. What's actually being processed are the lines that don't have semicolon the directives that are a little further down. So here, y2k_compliance equals on for example. Precision equals 14 for significant digits displayed at floating point numbers, and so on. Let's find the ones that we're interested in. I'll just do a search, and I can do that from the Edit and then I have Find or Control F you'll see also is what tells me will do it.

And then the first thing I want to find is display_ errors. And find the next occurrence to that. Now that's a commented outline, I'm not interested in that. Let's find the real one, and here it is down here. display_errors equals on. Now it also gives you some information on how to set this. And it typically gives you a development value and a production value. Development is what we're going to be doing on this computer locally. Production is when we actually deploy to a web server for the whole world to see and use. So we want to have different settings for those two things. For example with displaying errors, we want the errors to be on for us, so that we can see every single thing that goes wrong while we're building it. But when we put it in production, we don't want to to expose all of that data to our public.

We don't want to to tell them gobs and gobs of information about our code and about our set-up. So instead, we'll turn it off in that case. So you'll want to make sure that it's turned on for you and it should be. Now that's not the only setting related to errors, there are a couple more. The next one is error reporting, you can either search for it if you can't find it. For me, it's right above it here and let's just scroll up a little bit. Find out some of the information about that, and that tells you what all these different things are. And, why you would use them and gives you some common combinations that you might use.

Mine is set to report all errors. Now up until I think PHP 5.4. This said E_ALL and E_STRICT, which is what you can see is what it recommends up here. That E_STRICT is now included in E_ALL, so you don't have to do that anymore, but if you do, it's fine, it's just backwards compatible for older versions of PHP. Now when we're in production of course, we want to tell it not to do these and you put the little twiddle in front of it, the little tilde. So E_ALL and not the deprecations. Deprecations are code that's going to stop working in future versions. It works just fine right now, so there's no reason to bother the production server with it.

But as a developer, it's very important to see those deprecation, because it says hey, you're using something that's about to go out of date. You might want to think about a replacement for this soon, so make sure that you have either E_ALL or that you have E_ALL and this upright bar E_STRICT. Now if you're wondering, what is this weird E_ALL. It's actually a constant that represents a number. And if we just shoot back over here to our phpinfo page. Let's just do a find here real quick, for error reporting, and there it is.

And this is the number that it comes up with. But instead of trying to work with all the different numbers that correspond to these different things, those are settings of different bits. Instead we just use E_ALL. It's a lot more convenient. The next one I want us to look for in this same document is HTML errors. HTML errors, and here it is. You want to make sure that this is turned on. You would turn it off for production. But it basically says, when you create an error, do you want me to just give you text, or do you want me to put some HTML around the error as well? And It'll look better with the HTML around it, I think it looks a little nicer.

So, let's go ahead and do that. It also allows it to include HTML links in those errors, which can be handy. So that's it for errors. Now let's look at output buffering. That's a concept that we'll talk about later on. For now, I'll just try and find output_buffering. It says it can't find it, but I need to search up. It's probably up above. that's not the one I want. There it is. So, let's go up a little bit more. Now, my default setting is just to have it turned on. It says here that you can also provide a number that's the amount of bytes that it will allow to buffer, 4,096 is a default value.

That's what more people use. So, you could also just have 4,096 in here. However, we're going to alternate off right now. Alpha buffering is a desirable feature. It's something we're going to talk about, and we're going to learn why you would want to use it, but until you know about it, I want us to have it off. And then you'll appreciate it and understand oh that's what it does and that's why I need to use it. So, for now let's all make sure that alpha buffering is turned off. And then the next thing that we want to look at is the timezone. So again, let's do a search. We'll do search for timezone.

There it is right there, date.timezone equals and you might have empty quotes here, it might be commented out, or like me you might have UTC. UTC is Greenwich Mean Time. You can leave it at UTC and it'll work just fine. But you do need to set it to something and that's because if you don't set it then PHP is going to start giving you some errors from time to time saying hey, you're doing something that's related to date and time but you don't have a default time zone set.

That's not a good idea. So let's avoid those warnings by having some times zones set. Now I'm not in UTC so I'm going to go ahead and give it my time zone. On the php.net website, you can find the list of those, php.net/manual/en/timeszones.php. And then I'm in America, so I'll click on America and you can scan down and you can find cities that are close to you. So maybe you're somewhere close to Denver, or you're close to Louisville, I'm actually going to be close to New York. So here it is for me. America, New_York.

So that's what I need to put in as my value. Has to be exactly like that. And I'm going to put it in quotes. It's going to be America/New_York. So that's going to be my timezone. And it will then use that as a default when it's working with dates. And most importantly, it'll get PHP to stop giving us warnings about it. So once you're done, you'll want to go to File and Save to save your changes, then you can close it. And then let's go back to WAMP. And let's Restart All Services. So that'll get all of those changes take effect.

It'll turn yellow briefly, red, yellow and then back to green. Now it's back online. Now if we go back here to our phpinfo page, scroll up to the top and reload the page. And then we can look for some of those changes to see if they took effect. The one that I'm most interested in is going to be Output Buffering. So let's see just see if we find that. Output and it has no value right now for it, which means that it's turned off. Let me look for my timezone, timezone. And you can see my default timezone now says America and New York.

So those are the three key configurations that you want to make sure that you set up before you start using PHP. There are plenty of other ones in there that you could set for yourself, but those are the ones that we really need to have before we move forward.

Show transcript

This video is part of

Image for PHP with MySQL Essential Training
PHP with MySQL Essential Training

131 video lessons · 31635 viewers

Kevin Skoglund
Author

 
Expand all | Collapse all
  1. 4m 8s
    1. Welcome
      1m 0s
    2. Using the exercise files
      3m 8s
  2. 15m 6s
    1. What is PHP?
      3m 52s
    2. The history of PHP
      2m 51s
    3. Why choose PHP?
      4m 10s
    4. Installation overview
      4m 13s
  3. 54m 53s
    1. Overview
      2m 33s
    2. Working with Apache Web Server
      6m 56s
    3. Changing the document root
      7m 24s
    4. Enabling PHP
      6m 16s
    5. Upgrading PHP
      3m 30s
    6. Configuring PHP
      10m 3s
    7. Installing MySQL
      5m 46s
    8. Configuring MySQL
      7m 24s
    9. Text editor
      5m 1s
  4. 31m 25s
    1. Overview
      3m 27s
    2. Installing WampServer
      5m 46s
    3. Finding the document root
      2m 24s
    4. Configuring PHP
      8m 12s
    5. Configuring MySQL
      5m 45s
    6. Text editor
      5m 51s
  5. 19m 12s
    1. Embedding PHP code on a page
      6m 43s
    2. Outputting dynamic text
      5m 55s
    3. The operational trail
      2m 27s
    4. Inserting code comments
      4m 7s
  6. 1h 18m
    1. Variables
      7m 50s
    2. Strings
      4m 38s
    3. String functions
      8m 54s
    4. Numbers part one: Integers
      6m 27s
    5. Numbers part two: Floating points
      5m 25s
    6. Arrays
      10m 0s
    7. Associative arrays
      6m 37s
    8. Array functions
      6m 33s
    9. Booleans
      3m 50s
    10. NULL and empty
      5m 15s
    11. Type juggling and casting
      8m 27s
    12. Constants
      4m 43s
  7. 27m 37s
    1. If statements
      6m 0s
    2. Else and elseif statements
      4m 16s
    3. Logical operators
      7m 30s
    4. Switch statements
      9m 51s
  8. 42m 15s
    1. While loops
      8m 41s
    2. For loops
      5m 59s
    3. Foreach loops
      8m 16s
    4. Continue
      8m 28s
    5. Break
      4m 8s
    6. Understanding array pointers
      6m 43s
  9. 37m 25s
    1. Defining functions
      8m 25s
    2. Function arguments
      5m 32s
    3. Returning values from a function
      7m 33s
    4. Multiple return values
      4m 53s
    5. Scope and global variables
      6m 2s
    6. Setting default argument values
      5m 0s
  10. 20m 18s
    1. Common problems
      3m 47s
    2. Warnings and errors
      8m 36s
    3. Debugging and troubleshooting
      7m 55s
  11. 57m 57s
    1. Links and URLs
      5m 33s
    2. Using GET values
      5m 35s
    3. Encoding GET values
      8m 41s
    4. Encoding for HTML
      9m 26s
    5. Including and requiring files
      7m 40s
    6. Modifying headers
      6m 45s
    7. Page redirection
      6m 43s
    8. Output buffering
      7m 34s
  12. 1h 3m
    1. Building forms
      7m 28s
    2. Detecting form submissions
      5m 59s
    3. Single-page form processing
      7m 57s
    4. Validating form values
      10m 40s
    5. Problems with validation logic
      9m 54s
    6. Displaying validation errors
      7m 23s
    7. Custom validation functions
      6m 28s
    8. Single-page form with validations
      7m 25s
  13. 28m 5s
    1. Working with cookies
      2m 49s
    2. Setting cookie values
      5m 55s
    3. Reading cookie values
      6m 1s
    4. Unsetting cookie values
      4m 51s
    5. Working with sessions
      8m 29s
  14. 48m 39s
    1. MySQL introduction
      6m 43s
    2. Creating a database
      7m 41s
    3. Creating a database table
      7m 42s
    4. CRUD in MySQL
      5m 48s
    5. Populating a MySQL database
      7m 32s
    6. Relational database tables
      6m 40s
    7. Populating the relational table
      6m 33s
  15. 56m 4s
    1. Database APIs in PHP
      4m 51s
    2. Connecting to MySQL with PHP
      7m 45s
    3. Retrieving data from MySQL
      8m 47s
    4. Working with retrieved data
      6m 12s
    5. Creating records with PHP
      6m 58s
    6. Updating and deleting records with PHP
      9m 6s
    7. SQL injection
      3m 5s
    8. Escaping strings for MySQL
      6m 45s
    9. Introducing prepared statements
      2m 35s
  16. 35m 58s
    1. Blueprinting the application
      7m 19s
    2. Building the CMS database
      5m 14s
    3. Establishing your work area
      4m 38s
    4. Creating and styling the first page
      4m 22s
    5. Making page assets reusable
      6m 36s
    6. Connecting the application to the database
      7m 49s
  17. 32m 49s
    1. Adding pages to the navigation subjects
      5m 58s
    2. Refactoring the navigation
      6m 7s
    3. Selecting pages from the navigation
      6m 2s
    4. Highlighting the current page
      5m 26s
    5. Moving the navigation to a function
      9m 16s
  18. 1h 45m
    1. Finding a subject in the database
      9m 48s
    2. Refactoring the page selection
      10m 52s
    3. Creating a new subject form
      6m 55s
    4. Processing form values and adding subjects
      11m 20s
    5. Passing data in the session
      9m 16s
    6. Validating form values
      9m 40s
    7. Creating an edit subject form
      8m 30s
    8. Using single-page submission
      7m 44s
    9. Deleting a subject
      9m 44s
    10. Cleaning up
      10m 37s
    11. Assignment: Pages CRUD
      4m 30s
    12. Assignment results: Pages CRUD
      6m 10s
  19. 39m 26s
    1. The public appearance
      8m 52s
    2. Using a context for conditional code
      11m 37s
    3. Adding a default subject behavior
      6m 9s
    4. The public content area
      5m 51s
    5. Protecting page visibility
      6m 57s
  20. 1h 3m
    1. User authentication overview
      4m 3s
    2. Admin CRUD
      8m 41s
    3. Encrypting passwords
      7m 26s
    4. Salting passwords
      5m 42s
    5. Adding password encryption to CMS
      11m 54s
    6. New PHP password functions
      3m 13s
    7. Creating a login system
      11m 28s
    8. Checking for authorization
      5m 48s
    9. Creating a logout page
      5m 40s
  21. 2m 4s
    1. Next steps
      2m 4s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold

Are you sure you want to delete this note?

No

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.