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.45-r0)
(2/3) Installing nginx (1.27.2-r3)
Executing nginx-1.27.2-r3.pre-install
(3/3) Installing nginx-openrc (1.27.2-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, 30 Oct 2024 22:04:23 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 \
php8.3 \
php8.3-bcmath \
php8.3-ctype \
php8.3-curl \
php8.3-fpm \
php8.3-gd \
php8.3-iconv \
php8.3-intl \
php8.3-json \
php8.3-mbstring \
php8.3-mcrypt \
php8.3-mysqlnd \
php8.3-opcache \
php8.3-openssl \
php8.3-pdo \
php8.3-pdo_mysql \
php8.3-pdo_pgsql \
php8.3-pdo_sqlite \
php8.3-phar \
php8.3-posix \
php8.3-session \
php8.3-soap \
php8.3-xml \
php8.3-zip
Start and enable service.
$ sudo rc-service php-fpm8.3 start
* Caching service dependencies ... [ ok ]
* Checking /etc/php8.3/php-fpm.conf ...
* /run/php-fpm8.3: creating directory
* Starting PHP FastCGI Process Manager ... [ ok ]
alpine:~$
PHP and FPM configuration files are available in the following directory.
$ ls /etc/php8.3/
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.
Explore More with CloudSpinx
Looking to streamline your tech stack? At CloudSpinx, we deliver robust solutions tailored to your needs:
- Hosting Services: Web Hosting, VPS, and Email Hosting
- Development Services: Custom Web & Mobile Apps, UI/UX Design
- Consultancy Services: Cloud, DevOps, Cybersecurity, and Kubernetes Experts
- Managed Services: End-to-end infrastructure support
- Dedicated Servers: Power and control, fully managed
Learn more about how we can support your journey with CloudSpinx – Linux Infra, Containerization, Virtualization, IT services, among many others.