- How to Install PHP7 fpm in Alpine Linux
- Installing PHP7 modules
- Searching All Available PHP7 Modules
- Conclusion
- How to install PHP, PHP-FPM in Alpine Linux?
- Install
- Make simbolic link
- Show installed version
- Show installed modules
- Manage the php-fpm8 service
- Check status
- Start
- Start with the Operating System
- Reload the configurations
- Restart
- Stop
How to Install PHP7 fpm in Alpine Linux
To install PHP7 fpm on your Alpine Linux, and you need to use the following apk command:
# apk add php7 php7-fpm php7-opcache
/ # apk add php7 php7-fpm php7-opcache fetch http://dl-cdn.alpinelinux.org/alpine/v3.10/main/x86_64/APKINDEX.tar.gz fetch http://dl-cdn.alpinelinux.org/alpine/v3.10/community/x86_64/APKINDEX.tar.gz (1/8) Installing php7-common (7.3.9-r0) (2/8) Installing argon2-libs (20171227-r2) (3/8) Installing libedit (20190324.3.1-r0) (4/8) Installing pcre2 (10.33-r0) (5/8) Installing libxml2 (2.9.9-r2) (6/8) Installing php7 (7.3.9-r0) (7/8) Installing php7-fpm (7.3.9-r0) (8/8) Installing php7-opcache (7.3.9-r0) Executing busybox-1.30.1-r2.trigger OK: 35 MiB in 36 packages
Once php7-fpm is installed on your system, and you need to restart Nginx and php7-fpm service with the following command:
# rc-service nginx restart # rc-service php-fpm7 start
Installing PHP7 modules
If you want to install other php7 modules on your Alpine Linux, such as: php7-gd, php7-mysqli, php7-zlib or php7-curl, just issuing the following command:
# apk add php7-gd php7-mysqli php7-zlib php7-curl
/ # apk add php7-gd php7-mysqli php7-zlib php7-curl (1/24) Installing ca-certificates (20190108-r0) (2/24) Installing nghttp2-libs (1.39.2-r0) (3/24) Installing libcurl (7.66.0-r0) (4/24) Installing php7-curl (7.3.9-r0) (5/24) Installing libxau (1.0.9-r0) (6/24) Installing libbsd (0.9.1-r0) (7/24) Installing libxdmcp (1.1.3-r0) (8/24) Installing libxcb (1.13.1-r0) (9/24) Installing libx11 (1.6.8-r1) (10/24) Installing libxext (1.3.4-r0) (11/24) Installing libice (1.0.9-r3) (12/24) Installing libuuid (2.33.2-r0) (13/24) Installing libsm (1.2.3-r0) (14/24) Installing libxt (1.1.5-r2) (15/24) Installing libxpm (3.5.12-r0) (16/24) Installing libbz2 (1.0.6-r7) (17/24) Installing libpng (1.6.37-r1) (18/24) Installing freetype (2.10.0-r0) (19/24) Installing libjpeg-turbo (2.0.2-r0) (20/24) Installing libwebp (1.0.2-r0) (21/24) Installing php7-gd (7.3.9-r0) (22/24) Installing php7-openssl (7.3.9-r0) (23/24) Installing php7-mysqlnd (7.3.9-r0) (24/24) Installing php7-mysqli (7.3.9-r0) Executing busybox-1.30.1-r2.trigger Executing ca-certificates-20190108-r0.trigger OK: 45 MiB in 60 packages
Searching All Available PHP7 Modules
If you want to search all available php7 moduels in your Alpine Linux, you can use apk search command with a pattern, such as: php7. type:
/ # apk search php7 php7-intl-7.3.9-r0 php7-openssl-7.3.9-r0 php7-dba-7.3.9-r0 php7-sqlite3-7.3.9-r0 php7-pear-7.3.9-r0 php7-tokenizer-7.3.9-r0 php7-phpdbg-7.3.9-r0 php7-pecl-imagick-dev-3.4.4-r1 cacti-php7-1.2.3-r0 php7-pecl-protobuf-3.8.0-r1 xapian-bindings-php7-1.4.11-r2 php7-litespeed-7.3.9-r0 php7-gmp-7.3.9-r0 php7-phalcon-3.4.3-r2 php7-pdo_mysql-7.3.9-r0 php7-sodium-7.3.9-r0 php7-pcntl-7.3.9-r0 php7-common-7.3.9-r0 php7-pecl-oauth-2.0.3-r2 php7-xsl-7.3.9-r0 php7-7.3.9-r0 php7-fpm-7.3.9-r0 php7-pecl-mailparse-3.0.3-r1 php7-pecl-gmagick-2.0.5_rc1-r5 php7-pecl-imagick-3.4.4-r1 php7-mysqlnd-7.3.9-r0 php7-enchant-7.3.9-r0 php7-pspell-7.3.9-r0 php7-pecl-ast-1.0.1-r1 php7-pecl-redis-4.3.0-r2 php7-snmp-7.3.9-r0 php7-doc-7.3.9-r0 php7-fileinfo-7.3.9-r0 php7-mbstring-7.3.9-r0 php7-pecl-lzf-1.6.7-r1 php7-pecl-amqp-1.9.4-r1 php7-pecl-yaml-2.0.4-r1 php7-pecl-timezonedb-2019.1-r3 php7-dev-7.3.9-r0 php7-pear-mail_mime-1.10.2-r1 php7-xmlrpc-7.3.9-r0 php7-embed-7.3.9-r0 php7-xmlreader-7.3.9-r0 php7-pear-mdb2_driver_mysql-1.5.0b4-r0 php7-pdo_sqlite-7.3.9-r0 php7-pear-auth_sasl2-0.2.0-r1 php7-exif-7.3.9-r0 php7-pecl-msgpack-2.0.3-r2 php7-recode-7.3.9-r0 php7-opcache-7.3.9-r0 php7-ldap-7.3.9-r0 php7-posix-7.3.9-r0 php7-pear-net_socket-1.2.2-r0 php7-session-7.3.9-r0 php7-gd-7.3.9-r0 php7-pecl-xdebug-2.7.2-r1 php7-gettext-7.3.9-r0 php7-pecl-couchbase-2.6.1-r1 php7-json-7.3.9-r0 php7-xml-7.3.9-r0 php7-iconv-7.3.9-r0 php7-sysvshm-7.3.9-r0 php7-curl-7.3.9-r0 php7-shmop-7.3.9-r0 php7-odbc-7.3.9-r0 php7-phar-7.3.9-r0 php7-pdo_pgsql-7.3.9-r0 php7-imap-7.3.9-r0 php7-pecl-apcu-5.1.17-r1 php7-pear-mdb2_driver_pgsql-1.5.0b4-r0 php7-pdo_dblib-7.3.9-r0 php7-pgsql-7.3.9-r0 php7-pdo_odbc-7.3.9-r0 php7-pecl-igbinary-3.0.1-r1 php7-zip-7.3.9-r0 php7-apache2-7.3.9-r0 php7-cgi-7.3.9-r0 php7-ctype-7.3.9-r0 php7-pecl-mcrypt-1.0.2-r1 php7-wddx-7.3.9-r0 php7-pear-net_smtp-1.8.1-r0 php7-bcmath-7.3.9-r0 php7-calendar-7.3.9-r0 php7-tidy-7.3.9-r0 php7-dom-7.3.9-r0 php7-sockets-7.3.9-r0 php7-pecl-zmq-1.1.3-r6 php7-pecl-event-2.5.3-r0 php7-pecl-vips-1.0.9-r2 php7-pecl-memcached-3.1.3-r2 php7-brotli-0.7.0-r1 unit-php7-1.8.0-r3 php7-soap-7.3.9-r0 php7-sysvmsg-7.3.9-r0 php7-pecl-ssh2-1.1.2-r5 php7-ftp-7.3.9-r0 php7-sysvsem-7.3.9-r0 php7-pear-net_idna2-0.2.0-r1 php7-pdo-7.3.9-r0 php7-pear-auth_sasl-1.1.0-r1 php7-bz2-7.3.9-r0 php7-mysqli-7.3.9-r0 php7-pear-net_smtp-doc-1.8.1-r0 php7-pear-net_sieve-1.4.4-r0 php7-simplexml-7.3.9-r0 php7-xmlwriter-7.3.9-r0 / #
Conclusion
You should know that how to install php7 fpm and other php7 modules in your Alpine Linux.
How to install PHP, PHP-FPM in Alpine Linux?
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.
Install
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.
https://ams.edge.kernel.org/alpine/v3.14/community
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.
Check status
# rc-service php-fpm8 status * status: stopped
Start
# 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 ]
Restart
# rc-service php-fpm8 restart * Stopping PHP FastCGI Process Manager . [ ok ] * Checking /etc/php8/php-fpm.conf . * Starting PHP FastCGI Process Manager . [ ok ]
Stop
# rc-service php-fpm8 stop * Stopping PHP FastCGI Process Manager . [ ok ]