Apache+php-fpm the right way

The simplest, and probably the correct, way to configure php-fpm with apache in Centos 6/7 is by using SetHandler and ProxySet directives.

The snippet bellow show a simple Virtual Host example, just change lines 2 3 and 6 and you are good to go.

<VirtualHost *:80>
    ServerAdmin [email protected]
    Servername example.com
    Options +Indexes
    DirectoryIndex index.php                                                                                                                    
    DocumentRoot /var/www/html
    # Register php-fpm as the handler for (.*).php files.
    <FilesMatch \.php$>
         SetHandler "proxy:fcgi://localhost:9000"
    # Configure the proxy
    <Proxy fcgi://localhost:9000>
        ProxySet connectiontimeout=5 timeout=240

    # If the php file doesn't exist, disable the proxy handler
    # so we can gracefully fail.
    RewriteCond %{REQUEST_FILENAME} \.php$
    RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI} !-f
    RewriteRule (.*) - [H=text/html]

Continue reading “Apache+php-fpm the right way”

Setting Enviroment Variables for PHP-FPM with Apache

Once in a while you may want to be able to pass information from the apache server to the php-fpm process, a way of doing it is by using environment variables, you can set them either in .htaccess files or in your virtual host configuration files.
You can set one variable per line as the following in your file of choice:


Continue reading “Setting Enviroment Variables for PHP-FPM with Apache”

Apache Reverse Proxy Example

The Simplest reverse proxy configuration possible is the code below, with this configuration your server will proxy all requests from example.com
to subdomain.example.com,

<VirtualHost *:80>
    ServerAdmin [email protected]
    ProxyRequests off
    ServerName example.com
    ProxyPreserveHost On
    <Location />
        ProxyPass http://subdomain.example.com/
        ProxyPassReverse http://subdomain.example.com/
        Order allow,deny
        Allow from all

Continue reading “Apache Reverse Proxy Example”

Apache auto-create Virtual-Hosts*

In this guide we’ll create a generic apache config file to ‘automatically’ create virtual hosts for a specific domain in your server

Sometimes you have a development server with one primary domain, and some sub-domains with your projects and/or stuff that still need to be validated

Firstly you will need to disable SELinux or configure the folders appropriately ( not covered in this guide ).
Continue reading “Apache auto-create Virtual-Hosts*”