Install PHP 7.1 php-fpm from source

Lets install the requirements.

On CentOS, run

yum -y install libxml2-devel libcurl-devel libmcrypt-devel openssl-devel
yum -y install libjpeg-turbo-devel libpng-devel freetype-devel libtidy-devel

Before you can install, you need to check MySQL socket location. To do this, run following command in MySQL command prompt.

show variables like '%socket%;

Find MySQL socket

Download and install PHP 7.1 from source

mkdir /usr/local/src
cd /usr/local/src
wget http://php.net/get/php-7.1.12.tar.gz/from/this/mirror -O php-7.1.12.tar.gz
tar xf php-7.1.12.tar.gz
cd php-7.1.12
make clean
./configure --prefix=/usr/serverok/php-7.1.12 \
--with-config-file-path=/usr/serverok/php-7.1.12/etc \
--with-mysql-sock=/var/lib/mysql/mysql.sock \
--with-pdo-mysql \
--with-mysqli \
--enable-cgi \
--with-zlib \
--with-gettext \
--enable-ftp \
--enable-calendar \
--enable-bcmath \
--enable-sockets \
--with-curl \
--with-gd \
--with-jpeg-dir=/usr/local \
--enable-mbstring \
--with-freetype-dir=/usr/local \
--with-mhash=/usr/local --enable-exif \
--with-mcrypt=/usr \
--with-tidy \
--with-openssl \
--enable-zip \
--enable-fpm
make && make install

Copy the configuration files

cp /usr/serverok/php-7.1.12/etc/php-fpm.conf.default /usr/serverok/php-7.1.12/etc/php-fpm.conf
cp /usr/serverok/php-7.1.12/etc/php-fpm.d/www.conf.default /usr/serverok/php-7.1.12/etc/php-fpm.d/www.conf
cp /usr/local/src/php-7.1.12/php.ini-development /usr/serverok/php-7.1.12/etc/php.ini

Now you will be able to start php-fpm by running

/usr/serverok/php-7.1.12/bin/php

By default php-fpm will run using tcp port 9000, it is better to change it to use unix socket, for this

vi /usr/serverok/php-7.1.12/etc/php-fpm.d/www.conf

Find

listen = 127.0.0.1:9000

Replace with

listen = /var/run/php-fpm/proxy.sock

php-fpm user

You need to configure the user account used to run php-fpm, if you don’t use proper account, you may get permission errors.

The account you use vary depending on OS, Web server. For example, nginx use account nginx. Apache on Ubuntu/Debian use www-data. Apache on CentOS use nobody.

Here is what i have on a server running Nginx web server

[root@vps154294 ~]# cat /usr/serverok/php-7.1.12/etc/php-fpm.d/www.conf | grep nginx
user = nginx
group = nginx
listen.owner = nginx
listen.group = nginx
[root@vps154294 ~]# 

Systemd Service

To easily manage php-fpm, lets create a php-fpm.service file.

Before we do this, edit

vi /usr/serverok/php-7.1.12/etc/php-fpm.conf

Find

;pid = run/php-fpm.pid

Add below

pid = /run/php-fpm/php-fpm.pid

Find

;error_log = log/php-fpm.log

Add below

error_log = /var/log/php-fpm/error.log

Save and exit.

Now lets create file /usr/lib/systemd/system/php-fpm.service

vi /usr/lib/systemd/system/php-fpm.service

Add following content

[Unit]
Description=PHP FastCGI process manager
After=syslog.target network.target

[Service]
PIDFile=/run/php-fpm/php-fpm.pid
ExecStartPre=/bin/mkdir --parents /run/php-fpm
ExecStart=/usr/serverok/php-7.1.12/sbin/php-fpm --nodaemonize
ExecReload=/bin/kill -USR2 $MAINPID
Type=simple

[Install]
WantedBy=multi-user.target

Enable php-fpm with

systemctl enable php-fpm

Now you will be able to use systemctl to start/stop/restart php-fpm

systemctl start php-fpm
systemctl stop php-fpm
systemctl restart php-fpm

systemctl status php-fpm

Need help with Linux Server or WordPress? We can help!

Leave a Reply

Your email address will not be published. Required fields are marked *