• Home
  • About Us
  • Contact
  • Privacy Policy

LinuxAdmin.io

  • Home
  • Tutorials
    • System Administration
    • Linux Tutorials
    • Web Hosting
    • WordPress
    • Virtualization
    • Troubleshooting
    • OpenStack

PHP-FPM With PHP7 From Source

PHP-FPM

PHP 7 has great performance benefits and combining that with Nginx when using php-fpm you can get seriously impressive load times! Compiling from source offers more control over where packages are installed and what modules are enabled. If you would like to read more about php-fpm, you can visit the project page 

Download the dependencies and software

yum install -y git gcc gcc-c++ libxml2-devel pkgconfig openssl-devel bzip2-devel curl-devel libpng-devel libjpeg-devel libXpm-devel freetype-devel gmp-devel libmcrypt-devel mariadb-devel aspell-devel recode-devel autoconf bison re2c libicu-devel

Get PHP 7

wget -O /usr/src/php-7.0.18.tar.gz http://php.net/get/php-7.0.18.tar.gz/from/this/mirror

Go to the directory which you downloaded PHP7 and uncompress the package:

cd /usr/src ; tar xfvz php-7.0.18.tar.gz

Go into the PHP7 directory

cd php-7.0.18

Configure and install  PHP

./configure --prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7/etc --with-config-file-scan-dir=/usr/local/php7/etc/conf.d --enable-bcmath --with-bz2 --with-curl --enable-filter --enable-fpm --with-gd --enable-gd-native-ttf --with-freetype-dir --with-jpeg-dir --with-png-dir --enable-intl --enable-mbstring --with-mcrypt --enable-mysqlnd --with-mysql-sock=/var/lib/mysql/mysql.sock --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pdo-sqlite --disable-phpdbg --disable-phpdbg-webhelper --enable-opcache --with-openssl --enable-simplexml --with-sqlite3 --enable-xmlreader --enable-xmlwriter --enable-zip --with-zlib

Install the software:

make && make install

 

Copy needed files for php-fpm

Create a conf.d directory:

mkdir /usr/local/php7/etc/conf.d
cp php.ini-production /usr/local/php7/lib/php.ini
cp sapi/fpm/www.conf /usr/local/php7/etc/php-fpm.d/www.conf
cp sapi/fpm/php-fpm.conf /usr/local/php7/etc/php-fpm.conf

edit /usr/local/php7/etc/conf.d/modules.ini and add:

zend_extension=opcache.so

edit /usr/local/php7/etc/php–fpm.d/www.conf and update the configuration, I used the following 

user = nobody
group = nobody

listen.owner = nginx
listen.group = nginx

Create a symlink for php-fpm to the standard path:

ln –s /usr/local/php7/sbin/php–fpm /usr/sbin/php–fpm

Start up services:

Create a systemctl file, edit /usr/lib/systemd/system/php–fpm.service and add the following:

[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
 
[Service]
Type=simple
PIDFile=/run/php-fpm/php-fpm.pid
ExecStart=/usr/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php7/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
 
[Install]
WantedBy=multi-user.target

Create a run directory for php-fpm:

mkdir /run/php–fpm

Start php-fpm on CentOS 7:

systemctl start php-fpm

Ensure it will start on boot:

systemctl start php-fpm

Thats it for setting up and starting it. You can create a test file in a document root to ensure its working insert the following code:

<?PHP
phpinfo();
?>

Accessing that page in a browser should display the PHP info page. If you are going to be setting this up with nginx. Please review Nginx Compile From Source on CentOS as well as Setup and Optimize Zend Opcache

Apr 28, 2017LinuxAdmin.io
0 0 vote
Article Rating
Nginx Compile From Source On CentOSMySQL Replication Master Slave Setup
You Might Also Like
 
SELinux Introduction In CentOS 7
 
How To Setup SSH Key Authentication
Subscribe
Notify of
guest
guest
2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Naitik Patel
Naitik Patel
4 years ago

I’m getting error while starting service
php-fpm.service: Unit not found.

0
Reply
LinuxAdmin.io
Author
LinuxAdmin.io
4 years ago
Reply to  Naitik Patel

I would do a systemctl and see if you can find a target with php

0
Reply
5 years ago 2 Comments Apache, Linux Tutorials, Nginx, PHP, Web Hosting centos, linux6,069
Recent Posts
  • Laravel Installation Guide For CentOS
  • Openstack Services Explanation And Overview
  • OSSEC Intrusion Detection Installation On Centos 7
  • Configure ProFTPd for SFTP on CentOS
  • How To Check And Repair MyISAM Tables In MySQL
Most Commented
Hot Clone Linux Server with Rsync
Hot Clone A CentOS Server With Rsync
14 Comments
ngx_cache_purge module
Install The ngx_cache_purge Module In Nginx
8 Comments
piwik-nginx
Piwik Analytics on Nginx
8 Comments
Tags
linuxcentosLinux Performance Tuningsysadminkvmnetworkingmemcachedanalyticssystemd
About

We love Linux and are dedicated to creating Linux administration tutorials for System Administrators since 2016.

Most Viewed
Default Gateway
How To Configure A Default Gateway on CentOS
62,987 views
Zend Opcache
Setup and Optimize Zend OpCache
46,714 views
Install ffmpeg
FFMpeg Install On CentOS 7
20,909 views
Archives
Email subscription

Sign up for our newsletter to receive the latest news and event postings.

2018 © LinuxAdmin.io
wpDiscuz