Explore information related to fastcgi

Set custom php.ini in FastCGI - How to set it up

This article covers how to set custom php.ini in FastCGI. Basically, FastCGI is the best to manage resources for a high traffic site in shared servers.


To create Custom php.ini with PHP5 under FastCGI:

1. First open .htaccess for the account in question and add the following lines to the bottom of the file:

AddHandler php5-fastcgi .php

Action php5-fastcgi /cgi-bin/php5.fcgi

2. Next, you'll need to source your main server php.ini which is located in /usr/local/lib/. Also note that it needs to have the correct ownership so we'll take care of that too:

cd /home/user/public_html/cgi-bin/

cp -a /usr/local/lib/php.ini .

chown user:user php.ini

3. Next we need to create the wrapper script. Create a file in your current directory (cgi-bin) called php5.fcgi as defined above and add the following:

#!/bin/sh

export PHP_FCGI_CHILDREN=1

export PHP_FCGI_MAX_REQUESTS=10

exec /usr/local/cpanel/cgi-sys/php5

4. Finally, make sure the ownership and permissions are correct on this file:

chown user:user php5.fcgi && chmod 0755 php5.fcgi

Read More



PHP Handlers for your Server - Which is suitable

This article covers the pros and cons of different PHP Handlers. Basically, selecting the proper PHP handler plays a major role in the server's stability and performance. 

Apache does not natively support PHP scripts without a special module. The module that tells Apache how to handle PHP scripts is referred to as a PHP handler. 

Without a properly configured module, Apache will just send you the PHP file as a download since it doesn't know what else to do.


How does each PHP handler work and what are the pros and cons :

1. DSO/Apache Module

This is also referred to as mod_php. This module allows Apache itself to directly parse and display PHP files. PHP scripts parsed by mod_php run as the same user that Apache itself does (rather than the user account that hosts the PHP files.


Pros

i. One of the fastest handlers available.

ii. Works with mod_ruid2 or mpm_itk modules.


Cons

i. Only works with a single version of PHP on cPanel servers (you'll need to use other handers for other versions of PHP if you offer them).

ii. Scripts run as the Apache user rather than the owner of the domain or subdomain. For example, on a cPanel server, if the script creates a file or directory, that file will be owned by the user "nobody" which can cause problems when the account owner goes to backup or remove them.


2. CGI

Stands for Common Gateway Interface. Using this handler, the system will run PHP scripts as the user that owns the domain or subdomain.


Pros

Scripts run as the domain or subdomain user, not as the Apache user.


Cons

i. One of the slowest handers.

ii. Doesn't work well with PHP opcode caching.

iii. Cannot put PHP configuration changes in an .htaccess file.


3. FCGI/FastCGI

FastCGI is a variation of the CGI protocol that provides a number of benefits over the older CGI handler. Using this module, the system will run PHP scripts as the user that owns the domain or subdomain. There are some differences between mod_fastcgi and mod_fcgid, but none that are relevant to the scope of this article.


Pros

i. Scripts run as the domain or subdomain user, not as the Apache user.

ii. Very fast handler.

iii. Works with PHP opcode caching.


Cons

i. This handler uses more memory than most of the others.

ii. Cannot put PHP configuration changes in an .htaccess file.


4. PHP-FPM

FPM stands for FastCGI Process Manager. It is an improved way of implementing FastCGI processing of PHP.  Using this handler, the system will run PHP scripts as the user that owns the domain or subdomain. Each FPM pool can have independent settings.


Pros

i. Scripts run as the domain or subdomain user, not as the Apache user.

ii. One of the fastest PHP handlers.

iii. Works with PHP opcode caching.

iv. Allows for some additional level of flexibility per pool.


Cons

i. This handler can use more memory than any other handler listed here, but that depends on the number of sites using PHP-FPM and the configuration of the FPM pool.

ii. Can be somewhat more complicated to manage.

iii. Cannot put PHP configuration changes in an .htaccess file and some directives can only be changed on a global level.


5. suPHP

This handler was specifically designed to serve PHP scripts as the owner of the domain or subdomain that is executing the PHP script. On cPanel servers, it is also configured to disallow execution of files with unsafe permissions. cPanel their copy of suPHP with the latest security fixes.


Pros

i. Scripts run as the domain or subdomain user, not as the Apache user.

ii. cPanel configures suPHP so that it blocks accessing or executing any files or directories with permissions higher than 755 for security.


Cons

i. Slowest PHP handler in most cases.

ii. PHP Opcode caching has no performance improvement and only wastes memory.

iii. Cannot put PHP configuration changes in an .htaccess file.


6. LSAPI

This handler implements the LiteSpeed Web Server (LSWS) SAPI. This handler requires CloudLiunx or LSWS for the maximum benefits. Using this handler, the system will run PHP scripts as the user that owns the domain or subdomain.


Pros

i. Designed to perform as well or better than PHP-FPM under certain circumstance.

ii. Less memory use than most other handlers.

iii. Scripts run as the domain or subdomain user, not as the Apache user.

iv. No special configuration required.

v. Can read PHP values out of a .htaccess file.


Cons

i. You don't get full benefits without purchasing a third-party commercial product.

ii. Not compatible with mod_ruid2 or mpm_itk (but it shouldn't need them).

Read More



FastCGI Proxying in Nginx - How to implement it

This article covers FastCGI Proxying in Nginx. Basically, FastCGI Proxying in Nginx allows working with a great number of applications, in configurations that are performant and secure. 

FastCGI proxying within Nginx is generally used to translate client requests for an application server that does not or should not handle client requests directly.

Nginx has become one of the most flexible and powerful web server solutions available. 

However, in terms of design, it is first and foremost a proxy server. 

This focus means that Nginx is very performant when working to handle requests with other servers.

Nginx can proxy requests using http, FastCGI, uwsgi, SCGI, or memcached.


How do I know if #FastCGI is enabled?

If the variable is present and correctly set to /phpinfo. php/foobar? foo=bar, then either ISAPI or FastCGI is used. 

Look near the top of the output for Server API; it should be set to either ISAPI (which means ISAPI is being used) or CGI/FastCGI (which means FastCGI is being used, since we already ruled out CGI).


More about Fastcgi_read_timeout?

proxy_read_timeout is applied when nginx proxies via HTTP protocol (for example, if you used nginx to proxy the request to a server such as node.js ). fastcgi_read_timeout is used when nginx speaks to the other service using FastCGI protocol.


More about Keepalive_timeout in nginx?

The keepalive_timeout assigns the timeout for keep-alive connections with the client. 

Simply put, Nginx will close connections with the client after this period of time.


How does Nginx location work?

The location directive within NGINX server block allows to route request to correct location within the file system. 

The directive is used to tell NGINX where to look for a resource by including files and folders while matching a location block against an URL.


How do I start Nginx on Linux?

1. Nginx is a powerful server application that routes network traffic.

2. Nginx runs as a service on your server.

3. systemctl can be used to start and stop the Nginx service.

4. To force close and restart Nginx and related processes: sudo /etc/init.d/nginx restart.


What does #Nginx Rewrite do?

Nginx rewrite rules can be defined within your Nginx configuration file in order to change at least part or all of a URL. 

Usually, this is done for one of two purposes. 

First, if a URL has changed, using a rewrite rule will let the client know that the resource requested is in a different location.


How do I remove nginx welcome page?

If you removed default under /etc/nginx/sites-available and restarted nginx and the welcome page is still showing, then see if there is a default. conf under /etc/nginx/conf. d and delete it and then restart nginx.

Read More



Nginx FastCGI caching

This article will show you how to configure FastCGI cache with Nginx since it can cache the HTML pages generated from a PHP code thereby eliminating the PHP/database requests.

Read More