Alpine linux php fpm

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 

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.

Читайте также:  Install linux driver on mac

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 ] 

Источник

Apache with php-fpm

This material is proposed for merging .

It should be merged with Apache. Everything in one place seems logical (Discuss)

PHP-FPM is the Fast Process Manager for PHP which runs as a service that spawns PHP processes as needed when files files are requested through the FastCGI interface. Passing this off to the PHP-FPM results in interpreting the PHP files much faster than having Apache spawn new processes each time a page is requested. You can read more about it here.

Instructions

Installation

Install required packages

# apk add apache2-proxy php8-fpm

Run and add services to startup

# rc-service php-fpm8 start # rc-update add php-fpm8 # rc-service apache2 start # rc-update add apache2

Configure

Configure Apache

Uncomment the mpm_event module and comment the mpm_prefork module like so:

LoadModule mpm_event_module modules/mod_mpm_event.so #LoadModule mpm_prefork_module modules/mod_mpm_prefork.so

Add the following lines to /etc/apache2/httpd.conf :

 SetHandler "proxy:fcgi://127.0.0.1:9000" 

Comment out the following lines in /etc/apache2/conf.d/php8-module.conf :

#LoadModule php_module modules/mod_php8.so #DirectoryIndex index.php index.html # # SetHandler application/x-httpd-php # 

Configure PHP-FPM

Edit the file /etc/php8/php-fpm.conf to suit your needs.

In the configuration you may need to change the default user and group from nobody to another user such as apache :

user = apache group = apache

Restart apache2 and PHP-FPM after editing the configuration:

Читайте также:  Check mbr or gpt linux

# rc-service php-fpm8 reload && rc-service apache2 reload

See Also

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Lightweight & optimized Multi-Arch Docker Images (x86_64/arm/arm64) for PHP-FPM (PHP 8.0, 8.1, 8.2) with essential extensions on top of latest Alpine Linux. 🐘

License

Apache-2.0, MIT licenses found

Licenses found

joseluisq/alpine-php-fpm

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

Lightweight & optimized Multi-Arch Docker Images ( x86_64 / arm / arm64 ) for PHP-FPM (PHP 8.0, 8.1, 8.2) with essential extensions on top of latest Alpine Linux. 🐘

curl , ftp , hash ( mhash ), libedit , libsodium , mbstring , mysqlnd , openssl , password-argon2 , pdo-sqlite , pear , sqlite3 , zlib

Extension v8.0 v8.1 v8.2
amqp
apcu
bcmath
bz2
exif
gd
gettext
gmp
imagick
imap
intl
mcrypt ? ?
memcache
mongodb
mysqli
oauth
opcache
pcntl
pdo_dblib
pdo_mysql
pdo_pgsql
pdo_sqlsrv ✓ (64-bit only) ✓ (64-bit only) ✓ (64-bit only)
pgsql
phalcon ?
psr
redis
rdkafka
soap
sockets
sqlsrv ✓ (64-bit only) ✓ (64-bit only) ✓ (64-bit only)
ssh2
swoole
sysvmsg
sysvsem
sysvshm
tidy
vips
xsl
yaml
zip
Others
composer v2.5 v2.5 v2.5
Читайте также:  Logging level in linux

(?) It means that this extension is obsolete/unmaintained/discourage or simply is not supported yet.

List all extensions included

If you want to know the whole list of the included extensions then use php -m as follow.

docker run --rm joseluisq/php-fpm:8.2 php -m 

Or use php -i to get a more detailed information.

docker pull joseluisq/php-fpm:8.2 # Or docker pull joseluisq/php-fpm:8.1 # Or docker pull joseluisq/php-fpm:8.0
FROM joseluisq/php-fpm:8.2 # Or FROM joseluisq/php-fpm:8.1 # Or FROM joseluisq/php-fpm:8.0

To give a Docker image a quick try, just execute any of those commands and then navigate to localhost:8088

docker run --rm -p 8088:80 joseluisq/php-fpm:8.2 sh -c "echo ' index.php; php -S [::]:80 -t ." # Or docker run --rm -p 8088:80 joseluisq/php-fpm:8.1 sh -c "echo ' index.php; php -S [::]:80 -t ." # Or docker run --rm -p 8088:80 joseluisq/php-fpm:8.0 sh -c "echo ' index.php; php -S [::]:80 -t ."
  • Default Docker working directory: /var/www/html
  • Additional PHP .ini files to load: /usr/local/etc/php/conf.d
  • Custom PHP .ini file generated (only if ENV_SUBSTITUTION_ENABLE=true ): /usr/local/etc/php/conf.d/default-php.ini

Configurable Environment Variables

PHP-FPM and PHP configurations can be overwritten using environment variables. To do so, just indicate the substitution of values using ENV_SUBSTITUTION_ENABLE=true (since it is disabled by default).

Below are the environment variables with their default values:

Settings replaced into /usr/local/etc/php-fpm.conf file.

Settings replaced into /usr/local/etc/php-fpm.d/www.conf file.

  • PHP_FPM_LISTEN=9000
  • PHP_FPM_USER=www-data
  • PHP_FPM_GROUP=www-data
  • PHP_FPM_LISTEN_OWNER=www-data
  • PHP_FPM_LISTEN_GROUP=www-data

Settings replaced into /usr/local/etc/php/conf.d/default-php.ini file ( php.ini ).

docker-compose examples for Nginx and Apache servers can be found under the ./examples directory.

docker-compose -f examples/nginx/docker-compose.yml up
docker-compose -f examples/apache/docker-compose.yml up

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in current work by you, as defined in the Apache-2.0 license, shall be dual licensed as described below, without any additional terms or conditions.

Feel free to send some pull request or file some issue.

This work is primarily distributed under the terms of both the MIT license and the Apache License (Version 2.0).

About

Lightweight & optimized Multi-Arch Docker Images (x86_64/arm/arm64) for PHP-FPM (PHP 8.0, 8.1, 8.2) with essential extensions on top of latest Alpine Linux. 🐘

Источник

Оцените статью
Adblock
detector