Install Apache DSO mod_php and Zend OpCache with PHP 5.6/7.0/7.1/7.2 on CWP – Centos Web panel

In this tutorial we’ll Enable Apache DSO mod_php and Zend OpCache on CWP, finally cwp is now supporting Apache mod_php (DSO) with OpCache. Apache mod_php is one of the oldest PHP handlers and its major benefits are speed and the ability to use opcode caching. Enabling this handler you will NOT be able to use PHP Selector. After you enabled DSO you can now enable xcache (php 5.xx), apc/apcu and opcache. APACHE DSO module is the perfect choice for high traffic sites.

Under some tests performed with WordPress which is now 30% faster when using with php opcache. and 60% when enabled object cache like memcached and redis.

Lets Begin the Tutorial :-

Step 1 :

Build Latest version of Apache (run this commands one by one) :

yum install apr-devel apr-util-devel apr apr-util libuuid libuuid-devel uuid uuid-devel -y
cd /usr/local/src
rm -rf /usr/local/apache/conf/httpd.conf.bak
mv /usr/local/apache/conf/httpd.conf /usr/local/apache/conf/httpd.conf.bak
rm -rf /usr/local/php/php.d/ioncube.ini
wget http://mirrors.fibergrid.in/apache//httpd/httpd-2.4.37.tar.gz
tar zxvf httpd-2.4.37.tar.gz
cd httpd-2.4.37
./configure --enable-so --prefix=/usr/local/apache --with-mpm=prefork --enable-unique-id --enable-ssl=shared --enable-rewrite --enable-deflate --enable-suexec --with-suexec-docroot=/home --with-suexec-caller=nobody --with-suexec-logfile=/usr/local/apache/logs/suexec_log --enable-asis --enable-filter --with-pcre --with-apr=/usr/bin/apr-1-config --with-apr-util=/usr/bin/apu-1-config --enable-headers --enable-expires --enable-proxy --enable-rewrite --enable-userdir 
make clean
make && make install
cp /usr/local/apache/conf/httpd.conf.bak /usr/local/apache/conf/httpd.conf
mv /usr/local/apache/conf.d/suphp.conf /usr/local/apache/conf.d/suphp.conf.bak
echo "AddType text/javascript .js" >> /usr/local/apache/conf/httpd.conf
echo "AddType text/css .css" >> /usr/local/apache/conf/httpd.conf

Then restart Apache :

service httpd restart

Step 2 :

Installation of php 5.6/7.0/7.1/7.2 choose your preferred version of php and install it via mentioned commands.

PHP 5.6

installation of php 5.6

rm -rf /usr/local/php-5-6
mkdir -p /usr/local/php-5-6
cd /usr/local/php-5-6
wget http://php.net/distributions/php-5.6.40.tar.gz
tar zxvf php-5.6.40.tar.gz
cd php-5.6.40
./configure --with-config-file-path=/usr/local/php --with-config-file-scan-dir=/usr/local/php/php.d --with-zlib --enable-soap --with-mysql-sock=/var/lib/mysql/mysql.sock --with-pspell --enable-wddx --with-tidy --enable-exif --enable-phar --enable-bcmath --enable-calendar --with-curl --with-iconv --with-mysql --with-mysqli --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-mcrypt --with-gettext --with-xsl --with-xmlrpc --with-pdo-mysql=mysqlnd --enable-posix --enable-ftp --with-openssl --enable-mbstring --with-kerberos --with-bz2 --enable-sockets --enable-zip --with-gd --with-jpeg-dir=/usr --with-freetype-dir=/usr --with-png-dir=/usr --enable-gd-native-ttf --with-pcre-regex --with-libdir=lib64 --enable-shmop --enable-intl --with-icu-dir=/usr --with-imap --with-imap-ssl --with-litespeed --with-pgsql=/usr/lib64/pgsql --with-pdo-pgsql --with-apxs2=/usr/local/apache/bin/apxs --enable-opcache 
make && make install

PHP 7.0

installation of php 7.0

rm -rf /usr/local/php-7-0
mkdir -p /usr/local/php-7-0
cd /usr/local/php-7-0
wget http://php.net/distributions/php-7.0.32.tar.gz
tar zxvf php-7.0.32.tar.gz
cd php-7.0.32
./configure --with-config-file-path=/usr/local/php --with-config-file-scan-dir=/usr/local/php/php.d --with-zlib=/usr --enable-mbstring --enable-zip --enable-bcmath --enable-pcntl --enable-ftp --enable-exif --enable-calendar --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-tidy --with-curl --with-mcrypt --with-iconv --with-gmp --with-pspell --with-gd --with-jpeg-dir=/usr --with-freetype-dir=/usr --with-png-dir=/usr --enable-gd-native-ttf --enable-gd-jis-conv --with-zlib-dir=/usr --with-xpm-dir=/usr --with-openssl --with-pdo-mysql=/usr --with-gettext=/usr --with-bz2=/usr --with-mysqli --enable-soap --enable-phar --with-xsl --with-xmlrpc --with-kerberos --enable-posix --enable-sockets --with-pcre-regex --with-libdir=lib64 --with-mysql-sock=/var/lib/mysql/mysql.sock --enable-shmop --enable-intl --with-icu-dir=/usr --with-imap --with-imap-ssl --with-litespeed --with-pgsql=/usr/lib64/pgsql --with-pdo-pgsql --with-apxs2=/usr/local/apache/bin/apxs --enable-opcache 
make && make install

PHP 7.1

installation of php 7.1

rm -rf /usr/local/php-7-1
mkdir -p /usr/local/php-7-1
cd /usr/local/php-7-1
wget http://php.net/distributions/php-7.1.30.tar.gz
tar zxvf php-7.1.30.tar.gz
cd php-7.1.30
./configure --with-config-file-path=/usr/local/php --with-config-file-scan-dir=/usr/local/php/php.d --with-zlib=/usr --enable-mbstring --enable-zip --enable-bcmath --enable-pcntl --enable-ftp --enable-exif --enable-calendar --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-tidy --with-curl --with-mcrypt --with-iconv --with-gmp --with-pspell --with-gd --with-jpeg-dir=/usr --with-freetype-dir=/usr --with-png-dir=/usr --enable-gd-native-ttf --enable-gd-jis-conv --with-zlib-dir=/usr --with-xpm-dir=/usr --with-openssl --with-pdo-mysql=/usr --with-gettext=/usr --with-bz2=/usr --with-mysqli --enable-soap --enable-phar --with-xsl --with-xmlrpc --with-kerberos --enable-posix --enable-sockets --with-pcre-regex --with-libdir=lib64 --with-mysql-sock=/var/lib/mysql/mysql.sock --enable-shmop --enable-intl --with-icu-dir=/usr --with-imap --with-imap-ssl --with-litespeed --with-pgsql=/usr/lib64/pgsql --with-pdo-pgsql --with-apxs2=/usr/local/apache/bin/apxs --enable-opcache 
make && make install

PHP 7.2

installation of php 7.2

rm -rf /usr/local/php-7-2
mkdir -p /usr/local/php-7-2
cd /usr/local/php-7-2
wget http://php.net/distributions/php-7.2.19.tar.gz
tar zxvf php-7.2.19.tar.gz
cd php-7.2.19
./configure --with-config-file-path=/usr/local/php --with-config-file-scan-dir=/usr/local/php/php.d --with-zlib=/usr --enable-mbstring --enable-zip --enable-bcmath --enable-pcntl --enable-ftp --enable-exif --enable-calendar --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-tidy --with-curl --with-iconv --with-gmp --with-pspell --with-gd --with-jpeg-dir=/usr --with-freetype-dir=/usr --with-png-dir=/usr --enable-gd-native-ttf --enable-gd-jis-conv --with-zlib-dir=/usr --with-xpm-dir=/usr --with-openssl --with-pdo-mysql=/usr --with-gettext=/usr --with-bz2=/usr --with-mysqli --enable-soap --enable-phar --with-xsl --with-xmlrpc --with-kerberos --enable-posix --enable-sockets --with-pcre-regex --with-libdir=lib64 --with-mysql-sock=/var/lib/mysql/mysql.sock --enable-shmop --enable-intl --with-icu-dir=/usr --with-imap --with-imap-ssl --with-litespeed --with-pgsql=/usr/lib64/pgsql --with-pdo-pgsql --with-apxs2=/usr/local/apache/bin/apxs --enable-opcache 
make && make install

Step 3

Fixing the website/user account permission :

When using Apache DSO you need to give permission 777 to all files and folders and change the user and group to nobody and enable php opcache :

rm -rf /usr/local/php/php.d/opcache.ini
touch /usr/local/php/php.d/opcache.ini
echo "zend_extension=opcache.so" > /usr/local/php/php.d/opcache.ini
service httpd restart
find /home/*/public_html/ -type d -exec chmod 777 {} \; 
find /home/*/public_html/ -type f -exec chmod 777 {} \; 
chown -R nobody:nobody /home/*/public_html

you need to run this commands every time when you add domain/subdomain and User account :

find /home/*/public_html/ -type d -exec chmod 777 {} \; 
find /home/*/public_html/ -type f -exec chmod 777 {} \; 
chown -R nobody:nobody /home/*/public_html

Step 4

Restart apache server and check php version via command :

service httpd restart
php -v

Navigate to CWP dashboard >> PHP Settings >> PHP info

Revert back to suPHP :

To revert to suphp you can simply run this below commands one by one :

rm -rf /usr/local/php/php.d/opcache.ini
yum remove cwp-httpd -y && yum install cwp-httpd -y
yum remove cwp-suphp -y && yum install cwp-suphp -y
yum remove cwp-php -y && yum install cwp-php -y
Back to top button