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
View Comments (2)
I'm getting error while starting service
php-fpm.service: Unit not found.
I would do a systemctl and see if you can find a target with php