NGINX + PHP-FPM + FTP: Multiple websites per pool

nginx Aug 09, 2017

In several situations, with some custom users, we need to stretch to the max the resources and the number of websites inside a single server. For that, let’s use the PHP-FPM with by user pool and directory with different users for FTP access.

First we need to start with the Setup of the services.

For this "how to", we will use CentOS 7 as distribuition with the following versions:

  • NGINX, version: 1.13.4 (mainline release)
  • PHP-FPM, version: 7.1.8
  • MariaDB, version: 10.2 (Stable)

NGINX Installation

Create the file nginx.repo inside /etc/yum.repos.d/ to allow the installation of NGINX mainline release. Attention, this will work on a CentOS 6 because we are using variables to define the version of the OS release $releasever.

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

We will do the installation after the MariaDB installation to interact with PHP-FPM configuration.

MariaDB Installation

To install MariaDB 10.2, please create the file MariaDB.repo inside /etc/yum.repos.d/. You can check this information on official MariaDB repositories.

# MariaDB 10.2 CentOS repository list - created 2017-08-27 23:14 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.2/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
  • If you prefer another version, please change 10.2 to 10.1 or 10.0 or even 5.5.

After the file is in place, install MariaDB with:

yum install MariaDB-server MariaDB-client

In this step, you only need to ensure that the version to install is 10.2. If yes, you can accept by typing yes.

As soon as the proccess completes, let's step the default password for the MariaDB Server and remove all the dummy information.

systemctl enable mariadb # this will add the mariadb to startup on boot
systemctl start mariadb

mysql_secure_installation

Enter current password for root (enter for none): <Press Enter>
Set root password? [Y/n] y
New password: <new password here>
Re-enter new password: <new password here>
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y

At this point, your MariaDB Server is installed and configured with a new password for root access. You can try to access by using the following command:

mysql -uroot -p<new password here>

And the expected behaviour:

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 29634
Server version: 10.2.11-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 

After this proccess, we are ready to start the installation of PHP-FPM and NGINX. We are going to start with PHP-FPM to allow you to define the name of PHP sockets to write it down on NGINX site configuration.

To install PHP-FPM, let's use the remi repositories.

First, ensure that epel-release is installed.

yum install -y epel-release
  • This will work in CentOS 7, for version 6, you will need to use the full .rpm file.
sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-$(rpm -E '%{rhel}').noarch.rpm

After epel-release installation, install the remi repository.

yum install http://rpms.famillecollet.com/enterprise/remi-release-$(rpm -E '%{rhel}').rpm

Based on title of this article, we will use the PHP 7.1, so, to avoid using the --enablerepo=remi-php71, let's enable this repo permanently on file.

vi /etc/yum.repos.d/remi-php71.repo

On the block [remi-php71], change the value enabled=0 to enabled=1. This will ensure on future updates or installations, the version of package that will search / install will be the 7.1.

For this example, let's install a few packages needed by some of Frameworks / CMS.

yum install php-pecl-zip php-pecl-igbinary php-intl php-mbstring php-opcache php-common php-pecl-msgpack php-fpm php-pecl-apcu php-gd php-devel php-pear php-pdo php-pecl-memcached php-mysqlnd php-cli php-mcrypt php-pecl-memcache php-nrk-Predis php-xml php-xmlrpc php-pgsql php-pecl-pthreads php-soap php-process
  • This will install a few more packages as dependencies.