Deploy PHP Apps
PHP is a popular programming language for web development. PHP is served in production server using PHP-FPM daemon run globally for whole server.
PHP environment setup
The default PHP version is 8.3
, which is the default provided from the OS.
To change PHP version used in PHP-FPM to other versions, add this to the deployment system.
features:
- php latest
You can also use a fixed PHP version: php 7.4
, php 8.1
, php 8.2
, php 8.3
.
Unfortunately you can't use custom PHP version other than provided because it's tied to system daemon. We always update the list to the latest supported version or latest major version starting from PHP 7.4.
Support for PHP extensions is varies but you can request a ticket to be included, provided the extension is provided officially by PHP.
When PHP version is changed, it's also changing the php
and composer
version it used.
Alternatively, you can call the alternative php
version using php81
, php80
, php56
, etc.
Composer install
Composer is already installed globally and follows what PHP version you've activated.
To call composer with other PHP version, run php81 $(which composer) install
.
Installed PHP Extensions
PHP are installed as system wide. It's installed as in these commands:
yum install php-{74,81,82,83}-php-{bcmath,cli,common,devel,fpm,gd,imap,intl,mbstring,mysqlnd,opcache,pdo,pecl-mongodb,pecl-redis,pecl-zip,pgsql,process,sodium,soap,xml}
Here's the list of extensions available:
bcmath | bz2 | calendar | Core | ctype | curl |
calendar | date | dom | exif | fileinfo | filter |
gd | gettext | hash | iconv | igbinary | imap |
intl | json | libxml | mbstring | mongodb | msgpack |
mysqli | mysqlnd | openssl | pcntl | pcre | PDO |
pdo_mysql | pdo_pgsql | Phar | pdo_sqlite | pgsql | posix |
random | readline | redis | Reflection | session | shmop |
SimpleXML | soap | sockets | sodium | SPL | sqlite3 |
standard | sysvmsg | sysvsem | sysvshm | tokenizer | xml |
xmlreader | xmlwriter | xsl | Zend OPcache | zip | zlib |
Custom extensions can be added using separate sysdaemon mentioned below.
PHP INI configuration
The PHP INI configuration is useful to tweak the PHP behavior such at upload size limits.
While you can't directly change the PHP INI located in system files, you can create .user.ini
into PHP root folder (check root
in NGINX e.g. ~/public_html/.user.ini
or ~/public_html/public/.user.ini
)
and tweak the config there.
An example of PHP INI configuration is:
upload_max_filesize = 32M
post_max_size = 32M
See the list of available PHP INI configuration in official PHP documentation.
To see default values or if your change has been in effect, use phpinfo()
.
PHP INI refresh on 5 minutes. You have to wait for changes to pick up.
You should place in document root, like public_html/public
if your system is CI4 / Laravel.
Also, you can't change configs with PHP_INI_SYSTEM
level unless you're using method below.
PHP Error Logging
The error logs can be seen in PHP Error Logs
in Check -> Check Logs.
You won't see error details in your website because we use production default settings.
If you want to see the error details directly in website, change this setting in .user.ini
:
display_errors = On
display_startup_errors = On
If you made changes to these parameters but not see any errors in the website yet, then it's maybe overrided in frameworks settings. For example, Laravel uses APP_DEBUG=true
to enable debug mode.
PHP Opcache Settings
The default opcache settings is set to 60 seconds. So if you've changed your PHP file, it won't be updated immediately until next 60 seconds. To disable PHP change, set opcache.validate_freq
to 0 in user INI, like this:
opcache.validate_freq = 0
Note that this settings is different with static file caching.
Restarting PHP
PHP doesn't need restart. Changing PHP files instantly changes the running server code.
The PHP-FPM instance itself is running as ondemand
and goes inactive after 15 minutes of no traffic.
NGINX Setup
NGINX can be configured to serve PHP files. PHP files are served by the PHP-FPM server. This works by writing fastcgi_pass
directive in the NGINX configuration, which points to underlying PHP-FPM server proxy for given host.
The minimum configuration to enable PHP is:
nginx:
fastcgi: on
fastcgi
Options
The fastcgi
option has three options: on
, off
, always
. The difference between three options:
fastcgi
Options off
location ~ \.php$ {
return 404;
fastcgi_pass ....;
}
This essentially disables PHP support in NGINX because it directly return 404 without being forwarded to fastcgi
. This is the default value for fastcgi
.