PHP
Completed
-
Section 1: Getting Started
-
Section 2: Core Syntax
-
Section 3: Functions
-
Section 4: Object-Oriented PHP
-
Section 5: Working with Data
-
Section 6: Modern PHP (PHP 8)
-
Section 7: Working with Files and Networking
-
Section 8: Common PHP Frameworks Overview
-
Section 9: Tooling and Ecosystem
-
Section 10: Practical Projects
-
Section 11: Interview Practice
-
Section 12: More Standard Library
-
Section 13: Data Structures and Algorithms in PHP
-
Section 14: More Practice Exercises
-
Section 15: More Security and Best Practices
-
Section 16: More Testing and Tooling
-
Section 17: WordPress-Style CMS Concepts
-
Section 18: Advanced OOP Practice
-
Section 19: More Web Fundamentals
-
Section 20: Database Practice
-
Section 21: PHP Manual: Array Functions
-
Section 22: PHP Manual: Date and Calendar Functions
-
Section 23: PHP Manual: Filesystem and Directory Functions
-
Section 24: PHP Manual: Filter and Var Handling
-
Section 25: PHP Manual: Math Functions
-
Section 26: PHP Manual: JSON and XML
-
Section 27: PHP Manual: Network and Stream Functions
-
Section 28: PHP Manual: Error and Exception Handling
-
Section 29: PHP Manual: Output Control and Misc
-
Section 30: PHP Manual: FTP, Zip, and Mail
-
Section 31: Modern PHP Frameworks Deep Dive
-
Section 32: PHP Design Patterns
-
Section 33: More Practice Exercises
-
Section 34: PHP Performance and Deployment
-
Section 35: More Interview Practice
-
Section 36: More PHP Standard Library
-
Section 37: PHP Concurrency and Async
-
Section 38: More Web Development Practice
-
Section 39: PHP Testing Deep Dive
-
Section 40: Composer and Package Development
-
Section 41: PHP Security Deep Dive
-
Section 42: More Practical Projects
-
Section 43: Legacy PHP Maintenance
-
Section 44: More Algorithm Practice
-
Section 45: Final Practice and Review
-
Section 46: PHP for E-Commerce Patterns
-
Section 47: PHP API Design Deep Dive
-
Section 48: PHP Caching Strategies
-
Section 49: PHP Queue and Background Jobs
-
Section 50: PHP Multi-Tenancy Patterns
-
Section 51: PHP Real-Time Features
-
Section 52: PHP CMS and Content Modeling
-
Section 53: PHP Internationalization
-
Section 54: More Framework-Specific Practice
-
Section 55: PHP Legacy Code Refactoring
-
Section 56: More Practice Projects Round 2
-
Section 57: PHP Command-Line Applications
-
Section 58: PHP and Microservices
-
Section 59: More Interview and Review Round 2
4: PHP Configuration with php.ini
You've probably had this happen: you're building a feature that lets users upload a profile picture or a PDF, and everything looks perfect in your code. You've got the form, the move_uploaded_file() logic, and the validation. But then you try to upload a 5MB file, and the script just... fails. Or worse, the $_FILES array is completely empty, and PHP doesn't give you a helpful error message. It's one of the most frustrating "silent" failures in the language.
The illusion of control with ini_set
When I first started with PHP, my instinct was to fix everything inside the script. I figured if I needed a larger upload limit, I'd just tell PHP to change it right at the top of my file. I'd write something like ini_set('upload_max_filesize', '10M'); and wonder why it did absolutely nothing. It feels logical—you're in the code, you see the setting, you change it. But here is the catch: ini_set() only works for settings that are changeable at runtime.
PHP categorizes its configuration settings. Some can be changed anywhere (PHP_INI_ALL), some only in your .ini or .htaccess files (PHP_INI_PERDIR), and some only in the master php.ini (PHP_INI_SYSTEM). The upload limit is a PHP_INI_PERDIR setting. By the time your script actually starts executing and hits that ini_set() line, the PHP engine has already received the request, seen that the file was too large, and discarded it. You're trying to change the rules of the game after the whistle has already blown.
Changing the engine's blueprints
The real way to handle this is by editing the php.ini file itself. Think of this file as the blueprints for the PHP engine. It tells PHP how to behave before a single line of your application code ever runs. Instead of fighting the environment, you configure the environment to support your application.
To fix the upload issue, you have to find where your php.ini actually lives—which is often a scavenger hunt depending on whether you're using Apache, Nginx, or a built-in server—and modify the actual directives. You'll want to look for upload_max_filesize and post_max_size. I always remind people that post_max_size must be larger than or equal to upload_max_filesize, because the file upload is just one part of the total POST request. If you set the file limit to 10MB but leave the POST limit at 8MB, you're still going to crash.
; In php.ini
upload_max_filesize = 10M
post_max_size = 12M
memory_limit = 128M
After you save these changes, you have to restart your web server (like Apache or PHP-FPM). This is the part that trips up a lot of developers. Since php.ini is loaded into memory when the process starts, the engine won't see your changes until it's forced to reload that file.
When global changes bite back
Now, you might be thinking, "Why not just crank every limit up to the max so I never have to deal with this again?" I've seen this in production environments, and it's a recipe for a crash. If you set memory_limit to 2GB because one specific reporting script needs it, you've just given every single request on your server permission to eat 2GB of RAM. If you get ten concurrent visitors, your server will swap to disk and grind to a halt.
The trade-off here is between convenience and stability. The php.ini is a global hammer. If you're on a shared host where you can't touch the master file, you might be able to use a .user.ini file in your directory to override specific settings. But as a general rule: keep your global settings conservative and only increase them to the minimum required for your app to function. It forces you to write more efficient code and prevents a single buggy loop from taking down your entire infrastructure.
📋 Practical Task
Expanding the File Upload Ceiling
Your goal is to move beyond runtime configuration and successfully modify the PHP environment to allow larger file uploads.
- Create a file named
info.phpcontainingand run it in your browser. Search the page for "Loaded Configuration File" to find the exact absolute path to your activephp.ini. - Open that
php.inifile in a text editor with administrative privileges. - Locate the
upload_max_filesizeandpost_max_sizedirectives. Change them both to20M. - Restart your web server (e.g.,
sudo service apache2 restartor restarting your local development environment). - Refresh your
info.phppage and verify that the "Local Value" for both settings now reflects20M.
There are no comments for now.