PHP
Summary - Deployment
Build a full deployment pipeline with Docker, PHP-FPM, Nginx and CI.
Production checklist
Production checklist: ini_set('display_errors', '0') hides errors from the screen, ini_set('log_errors', '1') turns logging on, error_log($msg) writes the message to a file.
Version check uses PHP_VERSION_ID >= 80300; this numeric constant packs major.minor.patch into one integer. PHP_SAPI gives the runtime mode (cli, fpm).
The OPcache settings opcache.enable and opcache.memory_consumption are set in php.ini; opcache_get_status reads the state, opcache_reset clears the cache.
Exercise Write a production check
Write a PHP production check script: call ini_set('display_errors', '0') and ini_set('log_errors', '1'). Fill a $cfg array with ini_get('display_errors') and ini_get('log_errors') and print each as KEY=value. If PHP_VERSION_ID >= 80300 print version=ok. Print sapi= with PHP_SAPI. If opcache_get_status and opcache_reset exist, print opcache=ready.
Show example solution
'other') . "\n";.
Example solution:
<?php
// Production check
ini_set('display_errors', '0');
ini_set('log_errors', '1');
error_log("check started");
$cfg = [];
$cfg['display_errors'] = ini_get('display_errors');
$cfg['log_errors'] = ini_get('log_errors');
foreach ($cfg as $key => $val) {
echo $key . "=" . $val . "\n";
}
if (PHP_VERSION_ID >= 80300) {
echo "version=ok\n";
}
echo "sapi=" . PHP_SAPI . "\n";
$opcache_enable = function_exists('opcache_get_status') && function_exists('opcache_reset');
if ($opcache_enable) {
echo "opcache=ready\n";
}
$ver = phpversion();
echo "php=" . (str_starts_with($ver, '8.') ? '8.x' : 'other') . "\n";
Test yourself
-
Which ini_set call hides errors from the screen in production?
- ini_set('log_errors', '1')
- ini_set('error_log', '/var/log/php')
- ini_set('display_errors', '0')
- ini_set('memory_limit', '256M')
Show answer
ini_set('display_errors', '0') — Correct. ini_set('display_errors', '0') stops errors from being printed to the screen.
-
Complete the version check
<?php
if (____ >= 80300) {
echo "php: ok\n";
}
Show answer
<?php
if (PHP_VERSION_ID >= 80300) {
echo "php: ok\n";
}
-
Match the production checklist
- display_errors=0
- Hides errors
- log_errors=1
- Turns logging on
- opcache.enable
- Bytecode cache
- PHP_VERSION_ID
- Version check
Next lesson: Challenge - Generators and closures