Most of the yum repositories don’t include PHP7.0.X on current releases for the time being. So if you need PHP7.0.X, you need to compile and build it for your self. I decided to put all required packages to the compilation, so most probably you wouldn’t need additional packages, just a quick tip, if you need additional packages you can install via pecl or pear tools.

Which PHP configure options should I use before compiling?

If you ever need to get the list of modules installed in your current PHP, type the following command via console:

php -m

So, take a list of your current configuration and check the configure list below in order to have a compatible compilation to your existing older version of PHP.

Advice: First of all, you should consider removing PHP packages from your server before compiling PHP, but be aware your codes will be visible till you install the compiled version to your server, consider shutting down your apache server for a while.

yum erase php*

Before downloading the code, install “Development Tools” by typing:

yum groupinstall "Development Tools"

and install other related header files:

yum install wget httpd-devel libtool-ltdl-devel libxml2-devel \
bzip2-devel net-snmp-devel openssl-devel pcre-devel \
curl-devel gd-devel mysql-devel libxslt-devel \
postgresql-devel gmp-devel systemd-devel

Download & install libmcrypt

cd /usr/src
wget http://downloads.sourceforge.net/project\
/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
tar zxvf libmcrypt-2.5.8.tar.gz 
cd libmcrypt-2.5.8
./configure -libdir=/usr/lib64
make
make install

 

Download & extract PHP 7.0.4 release:

wget http://php.net/get/php-7.0.4.tar.gz/from/this/mirror
mv mirror /usr/src/php-7.0.4.tar.gz
cd /usr/src/
tar zxvf /usr/src/php-7.0.4.tar.gz 
cd php-7.0.4
./configure \
 --with-apxs2 \
 --with-curl=/usr/local/lib \
 --with-config-file-path=/etc \
 --with-config-file-scan-dir=/etc/php.d \
 --with-pic \
 --with-gd \
 --with-gettext \
 --with-jpeg-dir=/usr/local/lib \
 --with-freetype-dir=/usr/local/lib \
 --enable-sockets \
 --with-kerberos \
 --with-openssl \
 --with-mhash \
 --with-mcrypt=/usr/local/lib \
 --with-mysqli=/usr/bin/mysql_config \
 --with-pdo-mysql=/usr \
 --with-pdo-pgsql=/usr \
 --with-pcre-regex=/usr \
 --with-pear \
 --with-gmp \
 --with-pgsql \
 --with-png-dir=/usr/local/lib \
 --with-xsl \
 --with-zlib \
 --with-zlib-dir=/usr/local/lib \
 --with-iconv \
 --with-libxml-dir=/usr \
 --enable-bcmath \
 --enable-calendar \
 --enable-exif \
 --enable-ftp \
 --enable-gd-native-ttf \
 --enable-soap \
 --enable-sockets \
 --enable-mbstring \
 --enable-zip \
 --enable-wddx \
 --enable-shmop \
 --with-libdir=lib64 \
 --disable-debug \
 --with-bz2 \
 --enable-gd-native-ttf \
 --enable-xml \
 --with-snmp=/usr \
 --enable-json \
 --with-fpm-user=apache\
 --with-fpm-group=apache\
 --enable-fpm \
 --with-fpm-systemd

Make & Install by typing:

make
make install
cp php.ini-production /etc/php.ini

Run the following to enable systemd service for PHP:

cat <<< '
[Unit]
Description=The PHP FastCGI Process Manager - VeriTeknik
After=syslog.target network.target

[Service]
Type=notify
PIDFile=/var/run/php-fpm.pid
ExecStart=/usr/local/sbin/php-fpm --nodaemonize \
--fpm-config /etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID

[Install]
WantedBy=multi-user.target
' > /usr/lib/systemd/system/php-fpm.service
systemctl enable php-fpm

Get rid of obsolete settings:

sed -i 's#;date.timezone =.*#  date.timezone = "Europe/Istanbul"#' /etc/php.ini
sed -i 's#upload_max_filesize =.*#upload_max_filesize = 200M#' /etc/php.ini
sed -i 's#post_max_size =.*#post_max_size = 200M#' /etc/php.ini
cat <<< ' include=/etc/php-fpm.d/*.conf [global] pid = \ 
/run/php-fpm/php-fpm.pid error_log = /var/log/php-fpm/error.log \
daemonize = no ' > /etc/php-fpm.conf
mkdir /etc/php-fpm.d

 

You need to create the appropriate user account the fpm process will run on, as a sample, we use plugged as a user:

useradd plugged
chmod 755 /home/plugged

create the php-fpm process config for the specific site:

cat <<< '
[www]
listen = 127.0.0.1:9001
 
listen.allowed_clients = 127.0.0.1
listen.owner = plugged
listen.group = plugged
user = plugged
group = plugged
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35

slowlog = /var/log/php-fpm/www-slow.log
 
catch_workers_output = yes
 
php_admin_value[error_log] = /home/plugged/logs/mphp_error.log
php_admin_flag[log_errors] = on
php_value[session.save_handler] = files
php_value[session.save_path] = /home/plugged/session
' > /etc/php-fpm.d/plugged.conf

mkdir /run/php-fpm/
mkdir /var/log/php-fpm/
touch /var/log/php-fpm/error.log
mkdir {/home/plugged/logs/,/home/plugged/session}
chown -R plugged:plugged /home/plugged
systemctl start php-fpm
sed -i 's/DirectoryIndex index.html.*/  DirectoryIndex index.html index.html.var index.php/' /etc/httpd/conf/httpd.conf

please let us know if you find any mistake

Leave a Reply

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