90% OFF ALL NEW PLANS TO HELP MORE BUSINESSES MOVE ONLINE

Using FastCGI + OPcache

Note: FastCGI is deprecated on our servers. We do not recommend using FastCGI anymore. Instead, you should use PHP-FPM. PHP-FPM is supported on most shared hosting servers and on all VPS plans. More details on how to enable FPM are available in our PHP version and handler article.

* The FastCGI technology is supported on select VPS plans. If you are not sure about your plan, you can ask SureSupport if FastCGI is available for your account.

To properly enable FastCGI+OPcache, in the instructions below, you need to replace:

AttentionUSERNAME with your actual hosting account username (you can find your username listed in the upper left corner of your Control Panel)

 

FastCGI is a way to accelerate frequently accessed pages on the site. FastCGI works in a way that a single process can handle many requests before being terminated. This reduces the overhead of starting a new PHP process every time there is a new page request. It also allows OPcache to work - it caches precompiled script bytecode, thus PHP does not need to compile bytecode again and again of the same PHP scripts. FastCGI with OPcache is the fastest solution for processing a lot of requests and boosting your website's overall performance.

For accounts with FastCGI support, you can enable the technology for your main website www.domain.com in three simple steps:

Step 1)

Create the file /home/USERNAME/www/www/.ht-fcgi-php-wrapper through the File Manager in your hosting Control Panel. Please make sure the file has executable permissions (we recommend that you set its permissions to 775). The file should contain the following code:

#!/bin/bash

# memory limit in kbytes
ulimit -v 573440

# do not lower this limit or you may start getting sporadic 500 server errors
export PHP_FCGI_MAX_REQUESTS=10000

# disable PHP child process management
export PHP_FCGI_CHILDREN=0

exec /usr/local/bin/php74.cgi -c /home/USERNAME/php.ini

In this first step, it is important to note that you choose the PHP version on which the code will be running by specifying the path to the CGI script (i.e. php74.cgi). This is done in the last line of the above-mentioned piece of code.

You can choose from the following options, depending on the preferred PHP version:

PHP 7.4 (recommended):

exec /usr/local/bin/php74.cgi -c /home/USERNAME/php.ini

PHP 7.3:

exec /usr/local/bin/php73.cgi -c /home/USERNAME/php.ini

PHP 7.2:

exec /usr/local/bin/php72.cgi -c /home/USERNAME/php.ini

PHP 7.1:

exec /usr/local/bin/php71.cgi -c /home/USERNAME/php.ini

PHP 5.6:

exec /usr/local/bin/php56.cgi -c /home/USERNAME/php.ini

PHP 5.3 (obsolete):

exec /usr/local/bin/php53.cgi -c /home/USERNAME/php.ini

 

Step 2)

Create /home/USERNAME/www/www/.htaccess and add the following code to it, or add the code to your existing .htaccess file:

<IfModule mod_fcgid.c>
<FilesMatch "\.php$">
AddHandler fcgid-script .php
FcgidWrapper /home/USERNAME/www/www/.ht-fcgi-php-wrapper .php
</FilesMatch>
</IfModule>

In steps 1 and 2, make sure to replace USERNAME with your hosting account username, which is listed under the information panel in the upper left corner of your hosting Control Panel. Also, check your .htaccess file for other AddHandler directives and comment/delete them.

Step 3)

Enable OPcache by adding the following piece of code to your global php.ini file via the PHP Settings -> Advanced Mode section in your hosting Control Panel:

;Enabling OPcache
[opcache]
zend_extension = opcache.so
opcache.enable = 1
opcache.memory_consumption = 128
opcache.max_accelerated_files = 10000
opcache.revalidate_freq = 60

 

If you want to enable FastCGI for a subdomain (example.domain.com), you need to create the file /home/USERNAME/www/example/.ht-fcgi-php-wrapper and create or edit the file /home/USERNAME/www/example/.htaccess. The path to .ht-fcgi-php-wrapper specified in your .htaccess file should also be correct.

In case you are experiencing any difficulties with FastCGI, you can contact our support team for assistance.