DownloadApacheConf.PHP
ApacheConf.PHP - ????????? ????? ??????? ??? ?????? ? ??????? ???????????? Apache2.
???????? ??? ApacheConf.PHP ??????????????? ?? ???????? ???????? Apache License Version 2.0.
??????????
-
PHP5 >= 5.5, PHP7;
-
Apache2 >= 2.4.
??????????: ?????? ? ??????? ???????? ?????? ?? ???????????, ?? ? ?????? ????????.
??? ?????????????
?????????? ???? Conf.php ? ???????????? ????? `Nemiro\Apache\Conf `.
# ?????????? ???? Conf.php (??????? ?????????? ???? ? ?????)
require_once 'Apache/Conf.php';
# ??????? ??????? ?????? Conf - ApacheConf
use Nemiro\Apache\Conf as ApacheConf;
???????? ????? ????????????
# ??????? ????????? ?????? Conf ? ????????? ???? ? ????? ????????????,
# ??????? ??????? ????????? ? ?????????
$conf = new ApacheConf('/etc/apache2/sites-available/example.org.conf');
# ?????????????? ???????:
# $conf = ApacheConf::CreateFromFile('/etc/apache2/sites-available/example.org.conf');
# ???????? ? ??????? ?????????? ?????? ? ???????? ????????? ??????????
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']);
???????? ???????????? ?? ??????
# ????????? ?????? ? ??????? ????????????
$str = '<VirtualHost 127.0.0.1:80>
DocumentRoot /home/example.org/www
ServerName example.org
<Location />
AuthType Basic
AuthUserFile users.pwd
Require valid-user
</Location>
</VirtualHost>';
# ????????? ??????
$conf = ApacheConf::CreateFromString($str);
# ???????? ? ??????? ?????????? ?????? ? ???????? ????????? ??????????
var_dump($conf['VirtualHost']);
var_dump($conf['VirtualHost']->ParametersAsString());
var_dump($conf['VirtualHost']['ServerName']->ParametersAsString());
# ???????? ?????? ??????? Location
$location = $conf['VirtualHost']['Location'][0];
# ???????
var_dump($location);
?????????? ?????
# ????????? ????
$conf = ApacheConf::CreateFromFile('/etc/apache2/sites-available/example.org.conf');
# ?????? ? ???????? ???????
# ---------------------------------------------------------------------------------------
# ?????? ?????????
$conf['VirtualHost']['ServerName']->Parameters = array('example.org', 'www.example.org');
$conf['VirtualHost']['DocumentRoot']->Parameters = array('/home/example.org/www');
# ??????? ????? ?????? Directory
$new_directory = ApacheConf::CreateDirective('Directory');
$new_directory->AddDirective('AllowOverride', 'All');
$new_directory->AddDirective('Allow', array('from', 'all'));
$new_directory->AddDirective('Require', array('all', 'granted'));
# ????????? ????????? ?????? Directory ? ?????? VirtualHost
$new_directory->AddTo($conf['VirtualHost']);
# ---------------------------------------------------------------------------------------
# ?????????? ????????? ? ???????? ????
$conf->Save();
# ??? ????? ??????? ??? ?????, ? ??????? ????? ????????? ??????
# $conf->Save('newFileName.conf');
????????? ???????????? ? ???? ?????? ?? ???????? ?????????? ??????
# ????????? ????
$conf = new ApacheConf::CreateFromFile('/etc/apache2/sites-available/example.org.conf');
# ?????? ? ???????? ???????
# ---------------------------------------------------------------------------------------
# ????????? ??????????
$conf['VirtualHost']['ServerName']->Parameters = array('example.org', 'www.example.org');
$conf['VirtualHost']['DocumentRoot']->Parameters = array('/home/example.org/www');
# ???????? ????? ?????? Directory
$new_directory = ApacheConf::CreateDirective('Directory');
$new_directory->AddDirective('AllowOverride', 'All');
$new_directory->AddDirective('Allow', array('from', 'all'));
$new_directory->AddDirective('Require', array('all', 'granted'));
# ????????? ????????? ?????? Directory ? ?????? VirtualHost
$new_directory->AddTo($conf['VirtualHost']);
# ---------------------------------------------------------------------------------------
# ???????? ???????????? ? ???? ??????
$string = $conf->GetAsString();
# ??????? ??????
var_dump($string);
???????? ???????????? ? ????
# ??????? ?????? ????????? ?????? Conf
$conf = new ApacheConf();
# ??????? ?????? VirtualHost
$virtualHost = ApacheConf::CreateDirective('VirtualHost', '192.168.100.39:8080');
$virtualHost->AddDirective('DocumentRoot', '/home/example.org/www');
$virtualHost->AddDirective('ServerName', 'example.org');
# ????????? ?????? ? conf
$conf->Add($virtualHost);
# ??????? ????? ??????????
$directory = ApacheConf::CreateDirective('Directory');
$directory->AddDirective('AllowOverride', 'All');
$directory->AddDirective('Allow', array('from', 'all'));
$directory->AddDirective('Require', array('all', 'granted'));
# ????????? ?????????? ? ?????? VirtualHost
$directory->AddTo($virtualHost);
# ???????? ???????????? ? ???? ??????
$string = $conf->GetAsString();
# ??????? ??????
var_dump($string);
# ??? ????? ????????? ???????????? ? ????
# $conf->Save('newFileName.conf');
|