Attention

Note: FastCGI is deprecated on our servers. We do not recommend using FastCGI anymore. Instead, you should use FPM with OPcache. FPM can be easily enabled through the PHP Settings section of the Control Panel. Information is available in our PHP Version article.

If you are already running FastCGI, information on how to transition to FPM with OPcache is available in our Transitioning from FastCGI to FPM article.

 

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 /home/USERNAME/www/www/.ht-fcgi-php-wrapper file through the "File Manager" section 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/www/www/php.ini

Note: If the /home/USERNAME/www/www/php.ini file does not exist, you should create it using the hosting Control Panel -> "File Manager" section and add the default content of php.ini files on our servers to it for compatibility reasons.

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 8.2:

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

PHP 8.1 (recommended):

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

PHP 8.0:

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

PHP 7.4:

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

PHP 7.3 (obsolete):

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

PHP 7.2 (obsolete):

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

PHP 7.1 (obsolete):

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

PHP 5.6 (obsolete):

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

PHP 5.3 (obsolete):

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

Note: 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.

Step 2)

Create an /home/USERNAME/www/www/.htaccess file 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>

Note: 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 the main php.ini file for your website via the "PHP Settings" 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

 

Note: If you want to enable FastCGI for a subdomain (example.domain.com), you need to create the /home/USERNAME/www/example/.ht-fcgi-php-wrapper file, update the last line in it to use the subdomain's php.ini file (e.g. /home/USERNAME/www/example/php.ini), 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.