Install PHP 7.1 php-fpm from source
Lets install the requirements.
On CentOS, run
1 2 |
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.
1 |
show variables like '%socket%; |
Download and install PHP 7.1 from source
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
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
1 2 3 |
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
1 |
/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
1 |
vi /usr/serverok/php-7.1.12/etc/php-fpm.d/www.conf |
Find
1 |
listen = 127.0.0.1:9000 |
Replace with
1 |
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
1 2 3 4 5 6 |
[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
1 |
vi /usr/serverok/php-7.1.12/etc/php-fpm.conf |
Find
1 |
;pid = run/php-fpm.pid |
Add below
1 |
pid = /run/php-fpm/php-fpm.pid |
Find
1 |
;error_log = log/php-fpm.log |
Add below
1 |
error_log = /var/log/php-fpm/error.log |
Save and exit.
Now lets create file /usr/lib/systemd/system/php-fpm.service
1 |
vi /usr/lib/systemd/system/php-fpm.service |
Add following content
1 2 3 4 5 6 7 8 9 10 11 12 13 |
[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
1 |
systemctl enable php-fpm |
Now you will be able to use systemctl to start/stop/restart php-fpm
1 2 3 |
systemctl start php-fpm systemctl stop php-fpm systemctl restart php-fpm |