- You can still change configuration settings, even if you can't edit the main PHP configuration file, php.ini In this video, I'll cover briefly three alternative approaches. This could be useful if the company hosting your website doesn't give you control of a php.ini. The most common alternative is to use a file called .htaccess, but this woks only if your server is running Apache. In the exercise files in the Chapter 101_03 folder, I've created this file, htaccess.txt and this shows you how to change the configuration settings on Apache for error reporting, display errors, and date.timezone.
The lines that begin with a hash or pound sign are treated as comments, so the lines that don't have the pound or hash sign are the actual configuration directives. Each setting must be on a separate line, and where the configuration directive sets of value, the line begins with php_value, followed by a space, the name of the directive that you want to set, another space, and then the value. In the case of error_reporting, you need to use an actual number, rather than e_all, because Apache doesn't understand PHP constants.
When the directive toggles a setting on or off, the line begins with php_flag, then the name of the directive, and after a space, either on or off. To change the settings on an Apache server, save this file in the server's document root folder as .htaccess and remove the .txt on the end of the file name. I've put that .txt on the end of the file name because on a Mac, file names that begin with a .
are hidden in the Mac finder. Using a .htaccess file has an immediate effect. There's no need to restart the web server. Some installations of PHP support a different type of user configuration file called .user.ini, and there's an example of that here in user.ini.txt. This uses exactly the same syntax as php.ini. So if you check with your hosting company and is says that it supports .user.ini files, you can rename this file.
Just take off the .txt on the end and begin it with .user.ini. And then you can upload it to your remote server and it will change the configuration settings. If neither of these alternatives is available to you, or you simply want to change the settings for a single file, you can change some settings on the fly at run time, and there's an example of how to do that in this file: runtime_config.php. For most settings, you use ini_set and then between a pair of parenthesis the first argument is the configuration settings that you want to change, then after a comma the value that you want to set it to.
In the case of e_all, that's a php constant, so it's not in quotes. But normally, the second value should be in quotes. And if you want to change the timezone setting, you need to use date_defaut_timezone_set and then between the parenthesis, the timezone setting. So, that's three alternative ways to change configuration settings in PHP. You should consider these only if you don't have direct access to editing the main configuration file, php.ini If your web server is running Apache, you can use this style, the .htaccess style.
If your server supports .user.ini you use this style. And then if you want to change just the run time, you can use this ini_set. But this is the least efficient way to do it, unless you need to make only a temporary change, or make the change for a specific script.
Author
Released
11/20/2015- Naming variables
- Storing text as strings
- Doing calculations with PHP
- Using conditional statements to make decisions
- Creating custom functions
- Deciphering error messages
- Emailing the contents of an online form
- Dealing with multiple-choice form fields
Skill Level Beginner
Duration
Views
-
Introduction
-
Welcome1m 11s
-
Using the exercise files4m 14s
-
-
1. Checking Your Setup
-
2. PHP Basics
-
PHP: The big picture6m 39s
-
Comments and white space6m 7s
-
Joining strings9m 4s
-
-
3. Making Decisions with Conditional Statements
-
The truth according to PHP3m 21s
-
Setting a default value8m 52s
-
-
4. Doing Calculations with PHP
-
Arithmetic operators9m 15s
-
Challenge: Integer division1m 18s
-
Solution: Integer division3m 27s
-
-
5. Using Loops for Repetitive Actions
-
Using a for loop5m 44s
-
Alternative syntax for loops2m 32s
-
6. Using Functions and Objects
-
Creating custom functions7m 53s
-
7. Including External Files
-
Using server-side includes3m 32s
-
Using include and require8m 16s
-
Examining the include_path5m 12s
-
-
8. Handling Errors
-
Dealing with PHP errors1m 27s
-
-
9. Emailing the Contents of an Online Form
-
Blocking suspect phrases8m 2s
-
Preparing to send email5m 10s
-
Automating the reply address7m 46s
-
Building the message body10m 18s
-
Sending the email5m 7s
-
Troubleshooting mail()3m 17s
-
10. Dealing with Multiple-Choice Form Fields
-
Introduction1m 58s
-
Handling checkbox groups7m 26s
-
Handling select menus6m 21s
-
-
Conclusion
-
Where next?1m 56s
-
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.
CancelTake notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.
Share this video
Embed this video
Video: Alternative ways to change configuration settings