THU.JUN.18
2026
23:34:29
← back to modules MODULE · 01 · PHP
0 / 10 chapters complete · 0%

PHP Config — php.ini

Five settings to flip on your dev box. The other ~1895 defaults are fine. Touch only what matters.
Turn on error display. Set up an error log. Bump upload + memory limits. Set your timezone. Restart Apache. Done.

Where it lives

Sneaky gotcha: Ubuntu installs TWO php.ini files, one for Apache and one for CLI:

/etc/php/8.3/apache2/php.ini   # used by browser requests
/etc/php/8.3/cli/php.ini       # used by terminal scripts

We care about the Apache one. Swap 8.3 for your version (check with ls /etc/php/).

sudo nano /etc/php/8.3/apache2/php.ini

Use Ctrl+W to search (nano's "where is" command) since the ~1900 lines aren't alphabetical.

Setting 1: see your errors

By default, errors are hidden. You get the dreaded "white screen of death." Flip them on for dev:

display_errors = On
display_startup_errors = On
error_reporting = E_ALL

This single change saves you hours. Always-off in production, always-on in dev.

Setting 2: log errors too

log_errors = On
error_log = /var/log/php_errors.log
Create the log file with the right permissions:
sudo touch /var/log/php_errors.log
sudo chown www-data:adm /var/log/php_errors.log
sudo chmod 640 /var/log/php_errors.log

Setting 3: real upload limits

Defaults are 2 MB — useless for any real file. Bump both (post_max_size must be ≥ upload_max_filesize):

upload_max_filesize = 64M
post_max_size = 64M

Setting 4: more memory per script

memory_limit = 512M

Default 128 MB trips up Composer, image processing, big data imports. 512 is comfy for dev.

Setting 5: your timezone

date.timezone = "Asia/Kuala_Lumpur"

Without this, every date() call throws a warning and assumes UTC. Your timestamps drift forever.

Pick yours from php.net/timezones.

Apply changes

The Apache module reads php.ini at startup. So restart Apache (not PHP):

sudo systemctl restart apache2

Build: Did My Config Actually Apply?

Goal: prove the new settings took effect. Easy to edit the wrong php.ini and not realize.

  1. Create /home/erictey/server/config-check.php
  2. Drop this in:
    <?php
    echo "<h1>PHP config check</h1>";
    echo "<p>Loaded ini: " . php_ini_loaded_file() . "</p>";
    echo "<p>Memory limit: " . ini_get('memory_limit') . "</p>";
    echo "<p>Upload max: " . ini_get('upload_max_filesize') . "</p>";
    echo "<p>Display errors: " . ini_get('display_errors') . "</p>";
    echo "<p>Timezone: " . date_default_timezone_get() . "</p>";
    echo "<p>Current time: " . date('Y-m-d H:i:s') . "</p>";
    ?>
  3. Visit http://192.168.0.19/config-check.php
  4. Verify: Memory limit shows 512M, Upload max shows 64M, timezone shows yours, time looks right

If the values still show the OLD defaults — you edited the wrong php.ini. Check the "Loaded ini" line at the top to see which file PHP is actually reading.

Stretch: trigger a deliberate error to test display_errors. Add echo $undefined_var; at the end. You should see a "Warning: undefined variable" message right on the page.

Install one more extension you'll need later: sudo apt install php-zip -y && sudo systemctl restart apache2. Then check it loaded with php -m | grep -i zip.