Bidhan Khatri
Posted on April 25, 2020
First Install Development Tools on CentOS 7.
yum group install "Development Tools"
Download the latest stable PHP version 7.3.13 source code from its website.
cd /usr/src/
wget https://www.php.net/distributions/php-7.3.13.tar.gz
tar xvf php-7.3.13.tar.gz
cd php-7.3.13
“configure” is a script designed to aid a program to be run on a wide number of different computers. This will automatically use your system variables to configure and ready the source for your VPS. When it is done it will generate a file called Makefile with all the info in it so define your required parameters while configuring it.
./configure --prefix=/usr/local/php7313 --with-config-file-path=/usr/local/php7313/etc --with-config-file-scan-dir=/usr/local/php7313/etc/conf.d --includedir=/usr/include/php7313 --with-libdir=lib64 --disable-debug --with-pic --disable-rpath --without-pear --with-bz2 --with-freetype-dir=/usr --with-png-dir=/usr --with-xpm-dir=/usr --without-gdbm --with-gettext --with-gmp --with-iconv --with-jpeg-dir=/usr --with-openssl=yes --with-pcre-regex --with-zlib --with-layout=GNU --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --enable-exif --enable-sockets --enable-shmop --enable-calendar --with-libxml-dir=/usr --enable-xml --enable-mbstring --enable-mbregex --with-gd=shared --enable-bcmath --with-xmlrpc=shared --enable-wddx=shared --with-xsl=shared,/usr --with-curl=/usr --with-tidy=shared,/usr --with-icu-dir=/usr --enable-json --enable-dom --enable-fileinfo --enable-posix --enable-intl --enable-zip --enable-pdo --enable-xmlreader --enable-xmlwriter --enable-soap --with-pear --with-ldap=/usr --with-mysqli -with-pdo-mysql --with-pdo-sqlite --with-gd
You may face multiple errors during compilation. Resolve the Dependencies first.
configure: error: libxml2 not found. Please check your libxml2 installation.
yum install -y libxml2-devel
configure: error: Cannot find OpenSSL’s
yum install openssl-devel
configure: error: Please reinstall the BZip2 distribution
yum install -y bzip2-devel
checking for cURL 7.15.5 or greater… configure: error: cURL version 7.15.5 or later is required to compile php with cURL support.
yum install -y curl-devel
configure: error: jpeglib.h not found.
yum install -y libjpeg-devel
configure: error: png.h not found.
yum install -y libpng-devel
configure: error: xpm.h not found.
yum install libXpm-devel
configure: error: freetype-config not found.
yum install -y freetype-devel
configure: error: Unable to locate gmp.h
yum install gmp-devel
configure: error: Unable to detect ICU prefix or /usr/bin/icu-config failed. Please verify ICU install prefix and make sure icu-config works.
yum install libicu-devel
configure: error: Cannot find ldap.h
yum install openldap openldap-devel
configure: error: Cannot find libtidy
yum install libtidy-devel
configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
yum install -y libxslt-devel
configure: error: Please reinstall the libzip distribution
cd /usr/src/
(Download, compile and install )
wget https://nih.at/libzip/libzip-1.2.0.tar.gz
tar -zxvf libzip-1.2.0.tar.gz
cd libzip-1.2.0
./configure
make
make install
cd /usr/src/php-7.3.13
Continue Configuration process again.
configure: error: off_t undefined; check your library configuration
# Add below line in /etc/ld.so.conf file.
vim /etc/ld.so.conf
/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64
(Now update the configuration )
# ldconfig -v
/usr/local/include/zip.h:59:21: fatal error: zipconf.h: No such file or directory
cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h
Finally, Build part has been completed.
Build complete.
Don't forget to run 'make test'.
You are now ready to compile the source. To compile it run the below command. This will compile the source output a lot of rubbish to your console. Just go ahead and let it finish. It will take time if you won’t mention “-j” option. Increase the number according to your VPS CPU core available. This will reduce the compiling time.
make -j4
When it is done, you should be ready to install it. Make will now follow the instructions in the Makefile to install the compiled package.
make install
( PHP Installation part has been completed. )
Now Configure PHP and PHP-FPM file.
First copy **php.ini **file from its source folder. It also might be on the PHP installed folder.
cp /opt/src/php-7.3.13/etc/php.ini-development /usr/local/php7313/etc/php.ini
Create SymLink:
ln -s /usr/local/php7313/bin/php /usr/local/bin/php73
ln -s /usr/local/php7313/bin/pecl /usr/local/bin/pecl73
ln -s /usr/local/php7313/bin/php-config /usr/local/bin/php-config73
PHP-FPM Config Files:
cd /usr/local/php7313/etc/php-fpm.d/
mv www.conf.default www.conf
mv /usr/local/php7313/etc/php-fpm.conf.default /usr/local/php7313/etc/php-fpm.conf
vim /usr/local/php7313/etc/php-fpm.d/www.conf
[www]
listen = /usr/local/php7313/var/run/php7313-fpm.sock
listen.mode = 0666
user = nginx
group = nginx
listen.owner = nginx
listen.group = nginx
pm = dynamic
pm.max_children = 128
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 10000
rlimit_files = 1024
slowlog = log/$pool.log.slow
cat /usr/local/7313/etc/php-fpm.conf | grep -v ";"
[global]
include=/usr/local/php7313/etc/php-fpm.d/*.conf
PHP-FPM Systemd Service setup:
copy php-fpm service file from the source folder.
cp /usr/src/php-7.3.16/sapi/fpm/php-fpm.service /usr/lib/systemd/system/php73-fpm.service
vim /usr/lib/systemd/system/php73-fpm.service
[Unit]
Description=The PHP FastCGI Process Manager
After=network.target
[Service]
Type=simple
PIDFile=/usr/local/php7313/var/run/php7313-fpm.pid
ExecStart=/usr/local/php7313/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php7313/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
ln -s /usr/local/php7313/sbin/php-fpm /usr/sbin/php73-fpm
systemctl start php73-fpm
Now Install MongoDB Package:
PECL is a repository for PHP Extensions, providing a directory of all known extensions and hosting facilities for downloading and development of PHP extensions.
pecl73 install mongodb
Now add “extension=mongodb.so” line on php.ini file.
vim /usr/local/php7313/etc/php.ini
extension=mongodb.so
php73 -m | grep mongodb
mongodb
systemctl restart php73-fpm
Install OCI8 Package:
Visit below website and download two packages “instantclient-basic” and “instantclient-devl” according to your system architecture.
https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html
cd /usr/src
wget https://download.oracle.com/otn_software/linux/instantclient/195000/oracle-instantclient19.5-basic-19.5.0.0.0-1.x86_64.rpm
wget https://download.oracle.com/otn_software/linux/instantclient/195000/oracle-instantclient19.5-devel-19.5.0.0.0-1.x86_64.rpm
yum localinstall oracle-instantclient19.5-basic-19.5.0.0.0-1.x86_64.rpm
yum localinstall oracle-instantclient19.5-devel-19.5.0.0.0-1.x86_64.rpm
pecl73 install oci8
( Type below mentioned path during installation. )
instant,/usr/lib/oracle/19.5/client64/lib
Now again add extension on php.ini file.
vim /usr/local/php7313/etc/php.ini
extension=oci8.so
systemctl restart php73-fpm
Now Install Nginx and Configure:
yum install nginx
vim /etc/nginx/conf.d/abc.com.np.conf
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name bdn.com.np www.abc.com.np;
root /var/www/abc.com.np;
index index.html;
location ~* \.php$ {
fastcgi_pass unix:/usr/local/php7313/var/run/php7313-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
}
mkdir -p /var/www/abc.com.np
vim /var/www/abc.com.np/index.php
<?php
phpinfo();
?>
nginx -t
systemctl restart nginx
Now check for the PHP Version and the installed Extension. They should be listed there.
Posted on April 25, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.