1 00:00:00,490 --> 00:00:03,790 If you have a development server where you test your site before 2 00:00:03,790 --> 00:00:08,040 launching it to the world you should configure your development server to show 3 00:00:08,040 --> 00:00:10,040 all your PHP errors. 4 00:00:10,040 --> 00:00:12,760 However a production server that's live for 5 00:00:12,760 --> 00:00:17,390 the world to see should never display PHP system errors to the screen. 6 00:00:18,390 --> 00:00:24,290 There are more secure and helpful ways to inform your site's visitors of a problem. 7 00:00:24,290 --> 00:00:26,890 For example, you can catch an error or 8 00:00:26,890 --> 00:00:30,460 exception and display a message to the user. 9 00:00:30,460 --> 00:00:33,750 For more information on catching exceptions, check out the teacher's notes. 10 00:00:35,510 --> 00:00:38,750 By setting up your development server to display errors, 11 00:00:38,750 --> 00:00:43,480 you'll have a consistent setup for all of your projects as you work on them. 12 00:00:43,480 --> 00:00:47,840 The first thing you need to know is where your php.ini file is located. 13 00:00:47,840 --> 00:00:50,860 There are some standard locations for this file. 14 00:00:50,860 --> 00:00:53,750 But there is an easy way to find out for sure. 15 00:00:54,820 --> 00:00:59,070 The PHP info function will get the PHP environment's details for 16 00:00:59,070 --> 00:01:01,860 the specific project you're running. 17 00:01:01,860 --> 00:01:06,060 I've included a phpinfo.php file in the downloads. 18 00:01:06,060 --> 00:01:11,230 But you can put the call to the PHP info function in any PHP file you want. 19 00:01:11,230 --> 00:01:12,360 Let's take a look at our setting. 20 00:01:13,640 --> 00:01:16,890 Here's what our PHP info file looks like. 21 00:01:16,890 --> 00:01:18,750 I set this up to run on the local host. 22 00:01:20,138 --> 00:01:24,880 While your server's running go to the PHP info file in a browser. 23 00:01:24,880 --> 00:01:30,160 I'm using localhost/phpinfo.php. 24 00:01:30,160 --> 00:01:33,344 Do a search for php.ini. 25 00:01:33,344 --> 00:01:39,190 You should see something like Configuration File (php.ini) Path. 26 00:01:39,190 --> 00:01:47,475 My path is Applications/MAMP/bin/php/php7.0.0/conf. 27 00:01:47,475 --> 00:01:51,380 You can open the php.ini file in a text editor. 28 00:01:51,380 --> 00:01:53,492 But I prefer to use the terminal. 29 00:01:53,492 --> 00:01:56,630 I'm gonna copy this path so i can paste it into a terminal window. 30 00:01:59,420 --> 00:02:04,552 We'll type sudo vi, then paste the path, 31 00:02:04,552 --> 00:02:07,841 and finish with php.ini. 32 00:02:07,841 --> 00:02:10,070 You'll have to type in your password for this computer. 33 00:02:12,300 --> 00:02:16,793 To search in vi, type a forward slash and then the search term. 34 00:02:16,793 --> 00:02:23,705 /error_reporting =. 35 00:02:23,705 --> 00:02:27,660 The lines starting with the semicolon are all comments. 36 00:02:27,660 --> 00:02:29,610 You can see our error reporting here. 37 00:02:30,650 --> 00:02:34,662 By default, it's set to E_ALL & ~E_NOTICE, 38 00:02:34,662 --> 00:02:40,272 meaning that this would show all error levels except E_NOTICE. 39 00:02:40,272 --> 00:02:41,754 For a development server, 40 00:02:41,754 --> 00:02:45,110 you probably want to turn everything on by just using E_ALL. 41 00:02:48,622 --> 00:02:51,230 We type I to start editing the line. 42 00:02:52,990 --> 00:02:55,760 We can then delete all this and hit Escape. 43 00:02:57,440 --> 00:03:03,080 If we scroll down a little bit you'll see that display errors is off by default. 44 00:03:03,080 --> 00:03:07,799 We wanna turn that on for our development server. 45 00:03:07,799 --> 00:03:13,889 Again, I, Delete, On, Escape. 46 00:03:16,224 --> 00:03:20,490 Going down a little more, we see our display start up errors. 47 00:03:22,060 --> 00:03:22,800 For debugging, 48 00:03:22,800 --> 00:03:27,150 you can turn on the errors that occur during PHP startup sequence as well. 49 00:03:27,150 --> 00:03:27,940 So let's do that. 50 00:03:31,308 --> 00:03:35,789 I to edit, Delete, 51 00:03:35,789 --> 00:03:38,957 On, Escape. 52 00:03:38,957 --> 00:03:41,710 Logging errors. 53 00:03:41,710 --> 00:03:45,520 By default, our logging errors is turned on. 54 00:03:45,520 --> 00:03:48,218 But now let's search for error log string. 55 00:03:48,218 --> 00:03:56,299 /error_log =. 56 00:03:56,299 --> 00:04:00,156 And we can see by default our error log is stored in 57 00:04:00,156 --> 00:04:04,217 Applications/MAMP/logs/php_error.log. 58 00:04:04,217 --> 00:04:05,790 You could change this if you want. 59 00:04:08,810 --> 00:04:12,540 There's one additional setting I wanna show, HTML errors. 60 00:04:16,820 --> 00:04:19,520 By default HTML errors is turned on. 61 00:04:21,180 --> 00:04:24,120 HTML errors controls how your errors are displayed. 62 00:04:25,120 --> 00:04:28,750 The format for HTML errors produces clickable messages 63 00:04:28,750 --> 00:04:34,660 that direct the user to a page describing the error or function causing the error. 64 00:04:34,660 --> 00:04:36,920 This is on by default, but you can turn it off. 65 00:04:38,090 --> 00:04:43,026 To save this file we hit :w. 66 00:04:43,026 --> 00:04:45,342 And then to quit, :q. 67 00:04:47,580 --> 00:04:50,430 After saving the file, you must restart the servers for 68 00:04:50,430 --> 00:04:51,892 the changes to take effect. 69 00:04:58,203 --> 00:05:02,714 Using the php.ini file allows us to set different configurations for 70 00:05:02,714 --> 00:05:04,910 different environments. 71 00:05:04,910 --> 00:05:09,680 Remember, we want to show the most errors in a development environment, and 72 00:05:09,680 --> 00:05:12,260 suppress errors in a production environment. 73 00:05:13,290 --> 00:05:16,100 Error reporting itself should be turned on, but 74 00:05:16,100 --> 00:05:19,200 you should turn off display errors on production. 75 00:05:20,500 --> 00:05:24,300 You could also have separate error reporting for QA environments. 76 00:05:25,910 --> 00:05:28,190 Maybe you want to suppress notices there so 77 00:05:28,190 --> 00:05:30,700 they don't interfere with what people see. 78 00:05:30,700 --> 00:05:34,540 However you choose to set up your environments, placing your configuration 79 00:05:34,540 --> 00:05:39,720 settings in the php.ini file keeps them separate from your code. 80 00:05:39,720 --> 00:05:45,760 However, depending on your server, you may not have access to the php.ini file. 81 00:05:45,760 --> 00:05:49,700 Most shared hosting accounts don't give you access to this file. 82 00:05:49,700 --> 00:05:52,580 In that case, you'll need to use one of the other options. 83 00:05:53,720 --> 00:05:58,630 Workspaces is set up as a development environment to display all errors. 84 00:05:58,630 --> 00:06:01,770 However, you can use one of the other two options 85 00:06:01,770 --> 00:06:03,590 to override these settings as well.