PHP
How to install multiple PHP versions on the same server
One server, several sites, different PHP versions. Here is how to install PHP 8.2, 8.3, and 8.4 side by side and point each site at the version it needs.
How to install PHP on Ubuntu
A modern PHP install means more than one apt package — you need PHP-FPM and the right set of extensions for your application. Here is how to install PHP on Ubuntu and wire it into Nginx.
Important PHP config options
The default php.ini is built to be safe, not to run a real website. These are the settings that actually matter in production and what to set them to.
PHP file upload exceeds upload_max_filesize
When a file upload silently fails or is empty, PHP itself is usually rejecting it because it is larger than upload_max_filesize or post_max_size. This is the PHP-side companion to the nginx 413 error.
PHP Warning: Undefined array key
PHP 8 turned accessing a missing array key into a warning instead of a silent notice. The fix is to check the key exists or provide a default before reading it.
PHP Fatal error: Allowed memory size exhausted
This fatal error means a PHP script tried to use more memory than the configured limit. Raise the limit, but first ask why the script needs that much.
PHP: Call to a member function on null
This error means you called a method on a variable that turned out to be null. The variable you expected to hold an object was empty, often a database lookup that found nothing.
PHP Fatal error: Class "X" not found
This fatal error means PHP could not load a class you referenced. Almost always a namespace mismatch, a wrong file name, or an autoloader that needs regenerating.
Composer out of memory (allowed memory size exhausted)
Composer can run out of memory while resolving dependencies, especially on small VPSes. The real fix is usually swap space, not a bigger memory limit.
PHP Maximum execution time of N seconds exceeded
This fatal error means a PHP script ran longer than the allowed time limit and was killed. Raise the limit for legitimately long work, but the real fix is usually to make the script faster or move it to a queue.
Enable JIT in PHP 8.x OPcache
Using OPcache can greatly improve [PHP performance](/php-performance). By enabling Just In Time (JIT) compiling in OPcache you can improve it even more.
How to run PHP files
You cannot execute PHP files directly on your computer without any additional tools. You need a (local) webserver that can run the PHP files.