In today’s guide we will cover the installation of Nginx Web server with PHP-FPM on Alpine Linux server. Nginx is high performance, open source web server which can also be used as reverser proxy. When hosting a PHP application with Nginx web server, a FastCGI Process Manager is required for loading web pages. FPM is the recommended FastCGI handler to be used with Nginx.

Login to your Alpine Linux Server and make sure it is updated. If converting this steps to container image build process, the commands are to be added to your Dockerfile.

$ sudo apk update
fetch http://nl.alpinelinux.org/alpine/v3.7/community/x86_64/APKINDEX.tar.gz
fetch http://nl.alpinelinux.org/alpine/edge/main/x86_64/APKINDEX.tar.gz
fetch http://nl.alpinelinux.org/alpine/edge/community/x86_64/APKINDEX.tar.gz
v3.7.3-183-gcc9ad2b48d [http://nl.alpinelinux.org/alpine/v3.7/community]
v20200626-2349-g06046a5a3e [http://nl.alpinelinux.org/alpine/edge/main]
v20200626-2353-g8dcf96ab2b [http://nl.alpinelinux.org/alpine/edge/community]
OK: 16383 distinct packages available

Also upgrade list of packages installed.

sudo apk upgrade

Once you’ve update application list index on Alpine Linux you can proceed to install and configure Nginx with PHP-FPM.

Install Nginx on Alpine Linux

Use the apk command line tool to install Nginx web server on Alpine Linux.

$ sudo apk add nginx
(1/3) Installing pcre (8.44-r0)
(2/3) Installing nginx (1.18.0-r3)
Executing nginx-1.18.0-r3.pre-install
(3/3) Installing nginx-openrc (1.18.0-r3)
Executing busybox-1.32.0-r1.trigger
2 errors; 114 MiB in 59 packages

Start nginx service after installation.

$  sudo rc-service nginx start
 * Caching service dependencies ...                                                                                                                         [ ok ]
 * /run/nginx: creating directory
 * /run/nginx: correcting owner
 * Starting nginx ...                                                                                                                                       [ ok ]
alpine:~$

Confirm service status:

$ rc-service nginx status
 * status: started

Set nginx service to be started at system boot.

$ sudo rc-update add nginx default
 * service nginx added to runlevel default

Install curl:

$ sudo apk add curl
(1/5) Installing ca-certificates (20191127-r4)
(2/5) Installing brotli-libs (1.0.7-r5)
(3/5) Installing nghttp2-libs (1.41.0-r0)
(4/5) Installing libcurl (7.71.1-r0)
(5/5) Installing curl (7.71.1-r0)
Executing busybox-1.32.0-r1.trigger
Executing ca-certificates-20191127-r4.trigger
2 errors; 117 MiB in 64 packages

Use curl command to confirm the web server is working.

$ curl -ik localhost
HTTP/1.1 404 Not Found
Server: nginx
Date: Thu, 13 Aug 2020 19:24:32 GMT
Content-Type: text/html
Content-Length: 146
Connection: keep-alive
....

Install PHP-FPM on Alpine Linux

Next instal php packages and include php-fpm extension on Alpine Linux.

sudo apk --update add \
        php7 \
        php7-bcmath \
        php7-ctype \
        php7-curl \
        php7-fpm \
        php7-gd \
        php7-iconv \
        php7-intl \
        php7-json \
        php7-mbstring \
        php7-mcrypt \
        php7-mysqlnd \
        php7-opcache \
        php7-openssl \
        php7-pdo \
        php7-pdo_mysql \
        php7-pdo_pgsql \
        php7-pdo_sqlite \
        php7-phar \
        php7-posix \
        php7-session \
        php7-soap \
        php7-xml \
        php7-zip

Start and enable service.

$ sudo rc-service php-fpm7 start
 * Caching service dependencies ...                                                                                                                         [ ok ]
 * Checking /etc/php7/php-fpm.conf ...
 * /run/php-fpm7: creating directory
 * Starting PHP FastCGI Process Manager ...                                                                                                                 [ ok ]
alpine:~$

PHP and FPM configuration files are available in the following directory.

$ ls /etc/php7/
conf.d        php-fpm.conf  php-fpm.d     php.ini

You can install vim and use it to modify configuration files.

sudo apk add vim

You can now upload PHP web application data and configure Nginx to serve your web content.

Learning materials:

$15.14
$151.37
in stock
Udemy.com
(179492)
$17.47
$174.66
in stock
Udemy.com
(62274)
$15.14
$151.37
in stock
Udemy.com

More on Alpine Linux.

Install Telnet on Alpine Linux

Install MariaDB on Alpine Linux

LEAVE A REPLY

Please enter your comment!
Please enter your name here

5 × 2 =