In this chapter
We'll open php.ini, PHP's settings file, and learn the handful of settings that matter most, why development and production use different values, why the command line and the web can have separate settings files, how environment variables keep secrets out of code, and a step-by-step way to fix "I changed the setting but nothing happened".
The Problem in Real Life
Mia writes her first useful script (a script is a PHP file that PHP runs from top to bottom, like next-slot.php): it prints the time of the next free slot at Tom's Barbershop. Her laptop clock says 10:00. Her script says 09:00. Exactly one hour wrong.
Marcus looks over. "PHP doesn't know you're in London, so it's using UTC — world time. That's a setting." He shows her where the settings file is, she adds the right timezone, saves, runs the script again… still 09:00.
"I changed it! Why doesn't PHP listen?" Marcus points at the path in the file she edited. "Because that's not the file this PHP is reading."
I changed the setting, saved the file, and nothing happened. How do I know which file PHP actually reads?
Mia
Changing Code vs. Changing Settings
Right code, wrong result
Some problems aren't in your code at all — they come from how PHP is configured.
More than one settings file
The command line and the web server can each read their own php.ini.
Secrets don't belong in code
Passwords and API keys must change between your laptop and the server without touching the code.
PHP Configuration and php.ini
Don't memorise this
This chapter shows many setting names, file paths and commands. Don't try to remember them. Read through to understand the ideas — what php.ini is, why development and production differ, and how to find the right file. The exact names you'll look up when you need them, like every developer does.
What php.ini is: PHP has hundreds of settings — how much memory a script may use, whether errors are shown, which timezone to use, how big an upload may be. They're all stored in a plain text file called php.ini. When PHP starts, it reads this file once and follows it.
Inside, every setting is one line: a name, an equals sign, and a value, like memory_limit = 128M. Lines starting with a semicolon (;) are comments — notes for humans that PHP ignores. To switch a setting off, people often just put a ; in front of it.
You don't need to know all the settings. These are the ones you'll touch most often:
display_errors: show error messages on the screen (On) or hide them (Off). Great for learning, dangerous on a real website.error_reporting: which kinds of problems PHP reports.E_ALLmeans "report everything" — always use it while developing.log_errorsanderror_log: write errors to a log file, so you can read them later even when they're hidden from visitors.memory_limit: the most memory one script may use (default128M). It stops one bad script from eating the whole server.max_execution_time: how many seconds a web request may run before PHP stops it (default 30). On the command line there's no limit.upload_max_filesizeandpost_max_size: the biggest file a visitor may upload, and the biggest form they may send (defaults2Mand8M).date.timezone: the timezone for every date and time, likeEurope/London. If it's empty, PHP uses UTC — which is exactly Mia's one-hour bug.
Settings are name = value. Lines starting with ; are comments that PHP ignores.
; Show errors while developing — never on a real websitedisplay_errors = Onerror_reporting = E_ALLlog_errors = On; Most memory one script may usememory_limit = 128M; Biggest upload and biggest formupload_max_filesize = 2Mpost_max_size = 8M[Date]date.timezone = Europe/London
Development vs. production: PHP comes with two ready-made settings files: php.ini-development and php.ini-production. The table below shows the most important difference. On your laptop you want to see every error immediately. On the real server you must never show errors to customers — an error message can reveal file paths, database names or other details an attacker would love. So production hides errors and writes them to a log instead.
| Setting | Development | Production | Why |
|---|---|---|---|
| display_errors | On | Off | Customers must never see error details |
| error_reporting | E_ALL | E_ALL | You still want to know about every problem |
| log_errors | On | On | Hidden errors must be written somewhere |
| memory_limit | 128M | Sized for the app | Stops one runaway script |
| date.timezone | Europe/London | Europe/London | Same everywhere, or times won't match |
The command line and the web can have separate settings: remember from chapter 2 that PHP can run in two ways — in a terminal (CLI) or behind a web server (PHP-FPM). On Linux, each one usually has its own php.ini, for example /etc/php/8.5/cli/php.ini and /etc/php/8.5/fpm/php.ini. Change one, and the other doesn't notice. That's what happened to Mia: she edited the web server's file, but ran her script on the command line.
Which settings file? Two ways PHP runs, two php.ini files
php script.php
terminal (CLI)
Browser request
web, through PHP-FPM
cli/php.ini
read every time you run php
fpm/php.ini
read when PHP-FPM starts — restart after changes
conf.d/*.ini
extra small files, read after php.ini
Finding the right file: never guess. Run php --ini — the line Loaded Configuration File is the file the command line reads. For the web, put <?php phpinfo(); in a page and open it in the browser (then delete it — it shows a lot of private details). Many systems also read extra small files from a conf.d folder; they're listed in the same output, and a setting in one of them can override php.ini.
Where php.ini lives — and why it isn't in your project: php.ini belongs to the PHP installation on a computer, not to your code. That's why you never see it in your editor next to booking.php. It sits in a system folder, and every PHP project on that computer shares it. Think of it like the settings of a car: they come with the car, not with the luggage you put in it. The table below shows where it usually is. On your laptop, your laptop is the "server" — so the file is in one of those places on your own disk. To look inside, open it like any text file: nano (a simple text editor that runs in the terminal) or code (VS Code) followed by the path, as the code box below shows. Editing it needs administrator rights, so use sudo. Because it isn't in the project, teams write down the settings their app needs in the project's README, and later many teams describe the whole setup — PHP version, extensions, php.ini — in a Docker file (that's the Docker course).
| Your system | Command line (CLI) | Web (PHP-FPM) |
|---|---|---|
| Ubuntu / Windows with WSL | /etc/php/8.5/cli/php.ini | /etc/php/8.5/fpm/php.ini |
| macOS, Apple chip (Homebrew) | /opt/homebrew/etc/php/8.5/php.ini | Same file |
| macOS, Intel chip (Homebrew) | /usr/local/etc/php/8.5/php.ini | Same file |
| Windows without WSL | C:\php\php.ini (next to php.exe) | — |
Extra files sit in a conf.d folder next to php.ini. The two templates are in the PHP install folder too (on Ubuntu: /usr/lib/php/8.5/php.ini-development and php.ini-production). Always confirm with php --ini.
Use the path from php --ini. sudo is needed to save changes, because it's a system file. In nano, save with Ctrl+O and quit with Ctrl+X.
# Ubuntu / WSL — the command-line settingssudo nano /etc/php/8.5/cli/php.ini# ...or open it in VS Codecode /etc/php/8.5/cli/php.ini# macOS with Homebrew (Apple chip)code /opt/homebrew/etc/php/8.5/php.ini# Just read it, page by page (press q to quit)less /etc/php/8.5/cli/php.ini
After you change php.ini: the command line reads the file every time you run php, so the change works at once. PHP-FPM reads it only when it starts, so after editing the web file you must restart it (sudo systemctl restart php8.5-fpm on Ubuntu). Forgetting this is the second most common reason a change "doesn't work".
# Which php.ini does the command line read?php --ini# What value does PHP see right now?php -i | grep date.timezone# Try a value for one run onlyphp -d date.timezone=Europe/London -r 'echo date("H:i");'# After editing the web (FPM) php.inisudo systemctl restart php8.5-fpm
Checking and changing settings from code: ini_get('memory_limit') tells you the current value. ini_set() changes some settings for the rest of that one request only — handy for testing, but the real home of a setting is php.ini. On the command line you can also try a value for one run: php -d display_errors=1 script.php.
Environment variables: an environment variable is a named value that lives outside your code, in the system that runs it — like APP_ENV=production or DB_PASSWORD=…. PHP reads them with getenv('APP_ENV'). This is how the same code behaves differently on Mia's laptop and on the server, and it's how secrets like passwords stay out of your code files (Act 20 explains why that matters). Use getenv() rather than $_ENV: with the settings files PHP ships, $_ENV is usually empty.
<?phpecho ini_get('memory_limit'), "\n"; // 128Mecho date_default_timezone_get(), "\n"; // Europe/London// Set outside the code, e.g. in the terminal: export APP_ENV=development$environment = getenv('APP_ENV') ?: 'production';echo "Running in: $environment\n";
getenv() returns false when the variable isn't set, so ?: gives a safe default.
When a setting doesn't work — check in this order: 1) Which file is loaded? (php --ini or phpinfo()) 2) Did you edit that file — CLI or FPM? 3) Is the setting name spelled exactly right? PHP silently ignores names it doesn't know. 4) Does a file in conf.d set it again? 5) Did you restart PHP-FPM? 6) What does PHP see now? (php -i | grep date.timezone or ini_get()).
Key Takeaway
php.ini holds PHP's settings, and PHP reads it when it starts. Development shows every error; production hides them and logs them. The command line and the web server can read different php.ini files, so always check which file is loaded, and restart PHP-FPM after a change. Secrets and per-server values go in environment variables, not in code.
Why This Matters
Many "bugs" at BookBay won't be in the code at all: an upload that fails because a limit is 2 MB, a page that stops after 30 seconds, times that are an hour off, errors that silently disappear. Knowing php.ini — and how to find the file that's really loaded — turns these from mysteries into two-minute fixes.
The development-vs-production split is also a security habit. On Launch Day, BookBay's server will hide errors from Tom's customers and log them for the team, while Mia's laptop keeps showing everything.
Mia edits the right file, and the script finally says 10:00. Then she runs php -m again and notices a short list. "What if I need something that isn't on this list?" Marcus nods. "Then you add an extension. And there's one that makes all PHP much faster." That's the next chapter.
