PHPackages                             aleksey.nemiro/apacheconf.php - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. aleksey.nemiro/apacheconf.php

AbandonedArchivedLibrary[Parsing &amp; Serialization](/categories/parsing)

aleksey.nemiro/apacheconf.php
=============================

This is a set of classes for working with configuration files of the Apache2 web server.

1.0(10y ago)4492[2 issues](https://github.com/phperry/ApacheConf.PHP/issues)Apache License 2.0PHPPHP &gt;=5.5,&gt;=7.0

Since Feb 21Pushed 10y ago1 watchersCompare

[ Source](https://github.com/phperry/ApacheConf.PHP)[ Packagist](https://packagist.org/packages/aleksey.nemiro/apacheconf.php)[ Docs](https://github.com/alekseynemiro/ApacheConf.PHP)[ RSS](/packages/alekseynemiro-apacheconfphp/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

### ApacheConf.PHP [![Latest Stable Version](https://camo.githubusercontent.com/f5dc4897d1c7b3a100fcad05cb77e3b0f8a54e68e713a08f84e0c507e78d8d98/68747470733a2f2f706f7365722e707567782e6f72672f616c656b7365792e6e656d69726f2f617061636865636f6e662e7068702f762f737461626c65)](https://packagist.org/packages/aleksey.nemiro/apacheconf.php) [![Total Downloads](https://camo.githubusercontent.com/9a3f27592cd16f3fdbf3905f402d686f5486f309348ab4e9f9e28ed4b921adfb/68747470733a2f2f706f7365722e707567782e6f72672f616c656b7365792e6e656d69726f2f617061636865636f6e662e7068702f646f776e6c6f616473)](https://packagist.org/packages/aleksey.nemiro/apacheconf.php) [![License](https://camo.githubusercontent.com/87bf4c5902037a3f1787e225b25cab15e451eb7a3010481a4a3a79d07d6a9f23/68747470733a2f2f706f7365722e707567782e6f72672f616c656b7365792e6e656d69726f2f617061636865636f6e662e7068702f6c6963656e7365)](https://packagist.org/packages/aleksey.nemiro/apacheconf.php)

[](#apacheconfphp---)

This is a set of classes for working with configuration files of the **Apache2** web server.

Code licensed under **Apache License Version 2.0**.

### Requirements

[](#requirements)

- PHP5 &gt;= 5.5, PHP7;
- Apache2 &gt;= 2.4.

**NOTE:** Working with the earlier versions were not tested, but it is possible that everything is working.

### How to use?

[](#how-to-use)

Include **Conf.php** file and import the class `Nemiro\Apache\Conf`.

```
# include the class file (use own path of the file location)
require_once 'Apache/Conf.php';

# import class
use Nemiro\Apache\Conf as ApacheConf;
```

#### Load config from file

[](#load-config-from-file)

```
# create instance and load config from file
$conf = new ApacheConf('/etc/apache2/sites-available/example.org.conf');
# or
# $conf = ApacheConf::CreateFromFile('/etc/apache2/sites-available/example.org.conf');

# get values
var_dump($conf['VirtualHost']);
var_dump($conf['VirtualHost']->ParametersAsString());
var_dump($conf['VirtualHost']['DocumentRoot']->ParametersAsString());
var_dump($conf['VirtualHost']['ServerName']->ParametersAsString());
var_dump($conf['VirtualHost']['Alias']);
```

#### Load config from string

[](#load-config-from-string)

```
# config data
$str = '
	DocumentRoot /home/example.org/www
  ServerName example.org

	  AuthType Basic
		AuthUserFile users.pwd
		Require valid-user

';

# parse string
$conf = ApacheConf::CreateFromString($str);

# get values
var_dump($conf['VirtualHost']);
var_dump($conf['VirtualHost']->ParametersAsString());
var_dump($conf['VirtualHost']['ServerName']->ParametersAsString());

# get location
$location = $conf['VirtualHost']['Location'][0];
var_dump($location);
```

#### Save to file

[](#save-to-file)

```
# load from file
$conf = ApacheConf::CreateFromFile('/etc/apache2/sites-available/example.org.conf');

# set values
$conf['VirtualHost']['ServerName']->Parameters = array('example.org', 'www.example.org');
$conf['VirtualHost']['DocumentRoot']->Parameters = array('/home/example.org/www');

# create a new directive
$new_directory = ApacheConf::CreateDirective('Directory');
$new_directory->AddDirective('AllowOverride', 'All');
$new_directory->AddDirective('Allow', array('from', 'all'));
$new_directory->AddDirective('Require', array('all', 'granted'));

# add the new Directory section to the VirtualHost section
$new_directory->AddTo($conf['VirtualHost']);

# save
$conf->Save();

# or save as...
# $conf->Save('newFileName.conf');
```

#### Get string from current instance

[](#get-string-from-current-instance)

```
# load from file
$conf = new ApacheConf::CreateFromFile('/etc/apache2/sites-available/example.org.conf');

# set values
$conf['VirtualHost']['ServerName']->Parameters = array('example.org', 'www.example.org');
$conf['VirtualHost']['DocumentRoot']->Parameters = array('/home/example.org/www');

# create a new directive
$new_directory = ApacheConf::CreateDirective('Directory');
$new_directory->AddDirective('AllowOverride', 'All');
$new_directory->AddDirective('Allow', array('from', 'all'));
$new_directory->AddDirective('Require', array('all', 'granted'));

# add the new Directory section to the VirtualHost section
$new_directory->AddTo($conf['VirtualHost']);

# get as string
$string = $conf->GetAsString();

# show string
var_dump($string);
```

#### Create a new config

[](#create-a-new-config)

```
# create an instance
$conf = new ApacheConf();

# create VirtualHost
$virtualHost = ApacheConf::CreateDirective('VirtualHost', '192.168.100.39:8080');
$virtualHost->AddDirective('DocumentRoot', '/home/example.org/www');
$virtualHost->AddDirective('ServerName', 'example.org');

# add to conf
$conf->Add($virtualHost);

# create directory
$directory = ApacheConf::CreateDirective('Directory');
$directory->AddDirective('AllowOverride', 'All');
$directory->AddDirective('Allow', array('from', 'all'));
$directory->AddDirective('Require', array('all', 'granted'));

# add the new Directory section to the VirtualHost section
$directory->AddTo($virtualHost);

# get as string
$string = $conf->GetAsString();

# show string
var_dump($string);

# or save
# $conf->Save('newFileName.conf');
```

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance10

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3784d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c2475fd956b57400794960b56d5f8d44e106b5373e425c6ed2b2975d4756ce19?d=identicon)[aleksey.nemiro](/maintainers/aleksey.nemiro)

---

Top Contributors

[![alekseynemiro](https://avatars.githubusercontent.com/u/6204692?v=4)](https://github.com/alekseynemiro "alekseynemiro (3 commits)")

---

Tags

phpconfigparserapache2conf

### Embed Badge

![Health badge](/badges/alekseynemiro-apacheconfphp/health.svg)

```
[![Health](https://phpackages.com/badges/alekseynemiro-apacheconfphp/health.svg)](https://phpackages.com/packages/alekseynemiro-apacheconfphp)
```

###  Alternatives

[doctrine/lexer

PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.

11.2k942.7M159](/packages/doctrine-lexer)[romanpitak/nginx-config-processor

Nginx configuration files processor.

6935.9k1](/packages/romanpitak-nginx-config-processor)[simplehtmldom/simplehtmldom

A fast, simple and reliable HTML document parser for PHP.

1931.4M15](/packages/simplehtmldom-simplehtmldom)[corveda/php-sandbox

A PHP library that can be used to run PHP code in a sandboxed environment

23796.2k2](/packages/corveda-php-sandbox)[leonelquinteros/php-toml

PHP parser for TOML language ( https://github.com/toml-lang/toml )

286.9k](/packages/leonelquinteros-php-toml)[php-collective/toml

A TOML parser and encoder for PHP with AST access and collected parse errors

131.5k1](/packages/php-collective-toml)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
