This guide explains the process of enabling Apache DSO mod_php and Zend OpCache on CentOS Web Panel (CWP). Using Apache mod_php (DSO) significantly enhances performance, especially for high-traffic sites.
Additionally, enabling OpCache further boosts the speed of PHP applications by caching precompiled scripts. However, note that enabling DSO disables PHP Selector functionality in CWP.
Key Benefits
- Performance: Apache mod_php combined with OpCache can enhance WordPress performance by 30% and up to 60% with additional caching mechanisms like Memcached and Redis.
- Compatibility: Apache mod_php supports opcode caching, providing a robust choice for high-traffic websites.
Step-by-Step Installation
Step 1: Build the Latest Version of Apache
1. Run the following commands to install the required dependencies and build Apache with the desired configuration:
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
2. Restart Apache:
service httpd restart
Step 2: Install PHP Versions (5.6/7.0/7.1/7.2)
Choose your preferred PHP version and follow the respective installation steps:
For 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 --enable-opcache
make && make install
For PHP 7.0, 7.1, or 7.2:
Follow similar commands, replacing the version numbers with your desired PHP version (e.g., 7.0.32, 7.1.30, 7.2.19).
Step 3: Configure Permissions and Enable OpCache
Set appropriate permissions and configure 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
Repeat these commands whenever adding new domains, subdomains, or user accounts.
Step 4: Verify Installation
Restart Apache and verify PHP installation:
service httpd restart
php -v
You can also check the PHP version and configuration in the CWP dashboard: Navigate to CWP Dashboard > PHP Settings > PHP Info.
Reverting to suPHP
If needed, you can revert back to suPHP using the following commands:
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
That’s It!
By following this guide, you can successfully enable Apache DSO mod_php and Zend OpCache, optimizing performance for PHP-based applications.
You May Also Like
- How to Update Nginx to the Latest Official Version on CentOS 8 (EL8) / CWP
- How to Reset the Root Password in MariaDB 10.5/10.4 and MySQL 8.0
- Boost Your Website Rankings Without SEO Experience – The Ultimate Guide
- How to read the parts of a website address (URL)
- How to Configure Amazon SES DKIM on Namecheap DNS