PHPackages                             malc0mn/haproxy-config-builder - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. malc0mn/haproxy-config-builder

ActiveLibrary

malc0mn/haproxy-config-builder
==============================

HAProxy config file builder and processor.

1.3.5(8mo ago)9694↓100%2[3 issues](https://github.com/malc0mn/haproxy-config-builder/issues)MITPHPPHP &gt;=5.4.0

Since Oct 10Pushed 8mo ago1 watchersCompare

[ Source](https://github.com/malc0mn/haproxy-config-builder)[ Packagist](https://packagist.org/packages/malc0mn/haproxy-config-builder)[ Docs](https://github.com/malc0mn/haproxy-config-builder)[ RSS](/packages/malc0mn-haproxy-config-builder/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (42)Used By (0)

HAProxy Config Processor
========================

[](#haproxy-config-processor)

[![Build Status](https://camo.githubusercontent.com/f08f972efc213056a3ddaf22e81036e81585ac4d3d4f6aa17105d583d733753c/68747470733a2f2f7472617669732d63692e6f72672f6d616c63306d6e2f686170726f78792d636f6e6669672d6275696c6465722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/malc0mn/haproxy-config-builder)[![Latest Stable Version](https://camo.githubusercontent.com/6662fd32018bddec40a314b520cce911477148e98fe3b66274f04cb6bf33a168/68747470733a2f2f706f7365722e707567782e6f72672f6d616c63306d6e2f686170726f78792d636f6e6669672d6275696c6465722f762f737461626c65)](https://packagist.org/packages/malc0mn/haproxy-config-builder)[![Total Downloads](https://camo.githubusercontent.com/e018b81d61b21c0109624b0143e4793b2034fcf2fd1dd14553be6a29b99b0f65/68747470733a2f2f706f7365722e707567782e6f72672f6d616c63306d6e2f686170726f78792d636f6e6669672d6275696c6465722f646f776e6c6f616473)](https://packagist.org/packages/malc0mn/haproxy-config-builder)[![Latest Unstable Version](https://camo.githubusercontent.com/c0716136c1c2424628363a8c6ef99ddd4a0adfe24371fce5caa2dce7a742d292/68747470733a2f2f706f7365722e707567782e6f72672f6d616c63306d6e2f686170726f78792d636f6e6669672d6275696c6465722f762f756e737461626c65)](https://packagist.org/packages/malc0mn/haproxy-config-builder)[![License](https://camo.githubusercontent.com/7221f196c18e941a62d81c712491cf0cde92398f796c476afc91a726dd40abe2/68747470733a2f2f706f7365722e707567782e6f72672f6d616c63306d6e2f686170726f78792d636f6e6669672d6275696c6465722f6c6963656e7365)](https://packagist.org/packages/malc0mn/haproxy-config-builder)[![SensioLabsInsight](https://camo.githubusercontent.com/8c71b9c50295369ca60bc2c34c96c09478cd72f2607053a23e6ed1e482da23ab/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f36623563306634662d323864622d343731342d626234372d3966393265643866376662662f6d696e692e706e67)](https://insight.sensiolabs.com/projects/6b5c0f4f-28db-4714-bb47-9f92ed8f7fbf)

Install using composer
----------------------

[](#install-using-composer)

Open a shell, `cd` to your poject and type:

```
composer require malc0mn/haproxy-config-builder
```

or edit composer.json and add:

```
{
    "require": {
        "malc0mn/haproxy-config-builder": "~1.0"
    }
}
```

Usage examples
--------------

[](#usage-examples)

###### Create from scratch

[](#create-from-scratch)

```
require 'vendor/autoload.php';

use HAProxy\Config\Comment;
use HAProxy\Config\Proxy\Backend;
use HAProxy\Config\Proxy\Frontend;
use HAProxy\Config\Proxy\Listen;
use HAProxy\Config\Userlist;
use HAProxy\Config\Config;

$comment = setDaemon()
    ->addGlobal('maxconn', 256)
    ->addDefaults('mode', 'http')
    ->addDefaults('timeout', ['connect', '5000ms'])
    ->addDefaults('timeout', ['client', '50000ms'])
    ->addDefaults('timeout', ['server', '50000ms'])
    ->addUserlist(
        Userlist::create('developers')
            ->addUser('eddy', '$6$mlskxjmqlkcnmlcjsmdl', ['editor', 'admin'])
            ->addGroup('editor', [])
    )
    ->addFrontend(
        Frontend::create('http-in')
            ->bind('*', 80)
            ->addParameter('default_backend', 'servers')
            ->addAcl('login_page', ['url_beg', '/login'])
    )
    ->addBackend(
        Backend::create('servers')
            ->addServer('server1', '127.0.0.1', 8000, ['maxconn', 32])
    )
    ->addListen(
        Listen::create('ssh')
            ->addServer('ssh-host', '*', 22, 'maxconn 3')
    )
;

echo (string)$config;
```

###### Read from file

[](#read-from-file)

```
require 'vendor/autoload.php';

use HAProxy\Config\Config;

$configFromFile = Config::fromFile('/etc/haproxy/haproxy.conf');

var_export($configFromFile);
```

### Output ordering

[](#output-ordering)

#### Keywords ordering within a proxy block

[](#keywords-ordering-within-a-proxy-block)

By default, the builder output will be printed in the same order you have added parameters. This is not always desired, especially when working with ACLs that you want to be present in the output before you set the `use_backend` calls.

To solve this issue, you can use the `setParameterOrder()` method to indicate the desired printing order. An example:

```
