This is a short tutorial on how to compile PHP7 from source on Centos 7.
First, why not just install from some binary, like Remi? Simply, because some of the features are no longer supported out of the box (like the php-memcached driver, as being deprecated), but some still need it, so you’ll have to rely on 3rd party forks for some of the stuff you were using before and (for) now are officcially considered deprecated.
I will also assume that you’re not doing this to run it with Apache in deafult config with mod_php mode but to make some speed with it’s php-fpm engine and event mode (for compiling Apache for the best setup, look here).
First, in case you haven’t got the development tools already installed, go for this:
yum groupinstall "Development Tools"
You’ll probably need some more dependencies with it, if you can’t manage, just leave me a comment.
Now let’s install the libraries you’ll need first:
yum --enablerepo=epel install bzip2-devel curl-devel libjpeg-turbo-devel libpng-devel libicu-devel libmcrypt-devel libxml2-devel freetype-devel
Then download the source, untar it, run configure (with most of the build in modules you’ll probabbly ever need), make and install (for some reason I dare not to rely on git here):
wget http://de1.php.net/get/php-7.1.0.tar.gz/from/this/mirror tar xvf mirror cd php-7.1.0/ ./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 --enable-intl --enable-mbstring --with-mcrypt --enable-mysqlnd --with-mysql-sock=/var/lib/mysql/mysql.sock --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --disable-phpdbg --disable-phpdbg-webhelper --enable-opcache --with-openssl --enable-simplexml --enable-xmlreader --enable-xmlwriter --enable-zip --with-zlib --enable-soap --enable-shmop --enable-sockets --enable-sysvmsg --with-openssl-dir=/usr/local/ssl --with-jpeg-dir=/usr/lib64 --with-freetype-dir --with-gettext make make install
Now, set up the initial environment, and do configure what you need:
mkdir /usr/local/php7/etc/conf.d cp php.ini-production /usr/local/php7/etc/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
Finally, let’s create a php7-fpm service:
Next step, we want to create a proper php7-fpm service, so we can start/reload/restart/status it when we want, instead of killing it and infoking the binary.
[Unit] Description=The PHP7 FastCGI Process Manager After=syslog.target network.target [Service] Type=simple PIDFile=/run/php-fpm/php-fpm.pid ExecStart=/usr/local/php7/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php7/etc/php-fpm.conf ExecReload=/bin/kill -USR2 $MAINPID [Install] WantedBy=multi-user.target
systemctl start php7-service
systemctl enable php7-service