PHP is a general purpose scripting language that is used mainly for web development, it is pragmatic, easy to learn and use, it is constantly evolving with a wide community of developers who are in charge of enriching this popular programming language with new features, therefore it is constantly evolving.
PHP 8.0 introduced modern features such as: Union Types, Named arguments, Match expressions, Just In Time Compilation.
PHP-FPM should be integrated with a web server such as Apache or NGINX, PHP-FPM serves dynamic content while the web server takes care of static content also acts as reverse proxy for PHP-FPM service.
Today we are going to install PHP 8.0 on Alpine Linux.
Reading you must check:
- How to Compile PHP 8.0 in Debian 10?
- How to install PHP 7.4 in Ubuntu 20.04?
- How To Compile PHP From The Source Code
- PHP New Features
- How to install NGINX on Alpine Linux?
- How to install Apache on Ubuntu 20.04?
PHP-FPM introduces the concept of pools, each pool can receive connections on a TPC/IP socket (IP:Port) or UNIX socket, and can run under a different user and group. Each pool has its configuration file.
Verify you have the community repository active.
Proceed with the installation:
# apk add php8 php8-fpm fetch https://ams.edge.kernel.org/alpine/v3.14/main/x86_64/APKINDEX.tar.gz fetch https://ams.edge.kernel.org/alpine/v3.14/community/x86_64/APKINDEX.tar.gz (1/3) Installing php8-common (8.0.9-r0) (2/3) Installing php8 (8.0.9-r0) (3/3) Installing php8-fpm (8.0.9-r0) Executing busybox-1.33.1-r3.trigger OK: 303 MiB in 77 packages
Once the process is finished you can explore the default settings, here is a sample of the directory structure:
# tree /etc/php8/ /etc/php8/ ├── conf.d ├── php-fpm.conf ├── php-fpm.d │ └── www.conf └── php.ini 2 directories, 3 files
You can find out the value of the listen directive by running the command:
# grep 'listen =' -R /etc/php8/ /etc/php8/php-fpm.d/www.conf:listen = 127.0.0.1:9000
Make simbolic link
The community repository provides 2 versions of PHP: 7.4, 8.0 so we must create a symbolic link to the corresponding version
# ln -s /usr/bin/php8 /usr/bin/php
Show installed version
php -v PHP 8.0.9 (cli) (built: Jul 30 2021 03:43:07) ( NTS ) Copyright (c) The PHP Group Zend Engine v4.0.9, Copyright (c) Zend Technologies
Show installed modules
php -m [PHP Modules] Core date filter hash json libxml pcre readline Reflection SPL standard zlib [Zend Modules]
You can lists all modules available for installing with:
# apk search php8 php8-imap-8.0.9-r0 php8-ftp-8.0.9-r0 php8-pspell-8.0.9-r0 php8-phar-8.0.9-r0 ...
To install additional modules, for example curl and mysqli run:
# apk add php8-curl php8-mysqli (1/4) Installing php8-curl (8.0.9-r0) (2/4) Installing php8-openssl (8.0.9-r0) (3/4) Installing php8-mysqlnd (8.0.9-r0) (4/4) Installing php8-mysqli (8.0.9-r0) OK: 304 MiB in 81 packages
Manage the php-fpm8 service
In this part we will learn how to start, stop or restart the php-fpm8 service, using the OpenRC initialization system. OpenRC is the default init system in distributions like Gentoo and Alpine Linux.
# rc-service php-fpm8 status * status: stopped
# rc-service php-fpm8 start * Caching service dependencies ... [ ok ] * Checking /etc/php8/php-fpm.conf ... * /run/php-fpm8: creating directory * Starting PHP FastCGI Process Manager ... [ ok ]
Now you can check if the service started successfully:
rc-service php-fpm8 status * status: started
Start with the Operating System
Start automatically after a system reboot with:
# rc-update add php-fpm8 default * service php-fpm8 added to runlevel default
Reload the configurations
Every time you make a change to the configuration files, first verify the changes with:
# php-fpm8 -t [31-Jul-2021 23:17:01] NOTICE: configuration file /etc/php8/php-fpm.conf test is successful
the reload the configurations:
# rc-service php-fpm8 reload * Reloading PHP FastCGI Process Manager ... [ ok ]
# rc-service php-fpm8 restart * Stopping PHP FastCGI Process Manager ... [ ok ] * Checking /etc/php8/php-fpm.conf ... * Starting PHP FastCGI Process Manager ... [ ok ]
# rc-service php-fpm8 stop * Stopping PHP FastCGI Process Manager ... [ ok ]
To integrate PHP-FPM and NGINX see: How to install NGINX on Alpine Linux?