How list all available Apache webserver variables
Is it possible to output any or all available apache variables ?
Yes, we can use a perl or php script and cgi and php apache module:
Perl
- create test domain config for apache virtual host e.g. var.mybluelinux.com.conf and enable it in apache configuration
- in
DocumentRoot
for your apache virtual host config file create directorycgi
- create in directory
cgi
file e.g.echo.pl
- copy to
echo.pl
file this perl code:
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "<pre>\n";
foreach $key (sort keys(%ENV)) {
print "$key = $ENV{$key}<p>";
}
print "</pre>\n";
- change permission to
echo.pl
file toexecutable
]$ chmod 755 echo.pl
- enable module
cgi
in your apache configuration and reload configuration
/etc/apache2/mods-enabled]$ ln -s ../mods-available/cgi.load .
/etc/apache2/mods-enabled]$ systemd reload apache2.service
- to your apache virtual host config add this code:
ScriptAlias "/cgi/" "/path-to-your-DocumentRoot-virtual-host/cgi/"
-
create file
.htaccess
in your /path-to-your-DocumentRoot-virtual-host/cgi/ directory (You have to enable .htaccess files in your apache virtual host config) -
copy to
.htacess
file this mod rewrite rules:
RewriteEngine On
RewriteCond %{REQUEST_URI} !echo.pl
RewriteRule .* echo.pl?ua=%{HTTP_USER_AGENT}&https=%{HTTPS} [L]
- And call from web browser any url e.g https://your_virtual_host_domain/cgi/dir/subdir/any-text.html
Example:
When I call from web browser url https://var.mybluelinux.com/cgi/subdir/subsubdir/index.html?my-question&id=45:
CONTEXT_DOCUMENT_ROOT = /var/www/html/var.mybluelinux.com/data/cgi/
CONTEXT_PREFIX = /cgi/
DOCUMENT_ROOT = /var/www/html/var.mybluelinux.com/data
GATEWAY_INTERFACE = CGI/1.1
HTTPS = on
HTTP_ACCEPT = text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
HTTP_ACCEPT_ENCODING = gzip, deflate, br
HTTP_ACCEPT_LANGUAGE = en-US,en;q=0.7,cs;q=0.3
HTTP_CONNECTION = keep-alive
HTTP_COOKIE = _ga=GA1.2.998553010.1519138107; _gid=GA1.2.578630594.1519138107
HTTP_HOST = var.mybluelinux.com
HTTP_UPGRADE_INSECURE_REQUESTS = 1
HTTP_USER_AGENT = Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0
PATH = /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
QUERY_STRING = ua=Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0&https=on
REDIRECT_HTTPS = on
REDIRECT_QUERY_STRING = ua=Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0&https=on
REDIRECT_SSL_TLS_SNI = var.mybluelinux.com
REDIRECT_STATUS = 200
REDIRECT_URL = /cgi/subdir/subsubdir/index.html
REMOTE_ADDR = 212.158.133.35
REMOTE_PORT = 49854
REQUEST_METHOD = GET
REQUEST_SCHEME = https
REQUEST_URI = /cgi/subdir/subsubdir/index.html?my-question&id=45
SCRIPT_FILENAME = /var/www/html/var.mybluelinux.com/data/cgi/echo.pl
SCRIPT_NAME = /cgi/echo.pl
SERVER_ADDR = 84.244.68.54
SERVER_ADMIN = [no address given]
SERVER_NAME = var.mybluelinux.com
SERVER_PORT = 443
SERVER_PROTOCOL = HTTP/1.1
SERVER_SIGNATURE =
Apache/2.4.25 (Debian) Server at var.mybluelinux.com Port 443
SERVER_SOFTWARE = Apache/2.4.25 (Debian)
SSL_TLS_SNI = var.mybluelinux.com
PHP
- create test domain config for apache virtual host e.g. var.mybluelinux.com.conf and enable it in apache configuration
- in
DocumentRoot
for your apache virtual host config file create directoryphp
- create in directory
php
file e.g.echo.php
- copy to
echo.php
file this php code:
<?php
phpinfo(INFO_VARIABLES);
?>
- enable module
php
in your apache configuration and reload configuration
/etc/apache2/mods-enabled]$ ln -s ../mods-enabled/php7.0.load .
/etc/apache2/mods-enabled]$ ln -s ../mods-enabled/php7.0.conf .
/etc/apache2/mods-enabled]$ systemd reload apache2.service
-
create file
.htaccess
in your /path-to-your-DocumentRoot-virtual-host/php/ directory (You have to enable .htaccess files in your apache virtual host config) -
copy to
.htaccess
file this mod rewrite rules:
RewriteEngine On
RewriteCond %{REQUEST_URI} !echo.pl
RewriteRule .* echo.php?ua=%{HTTP_USER_AGENT}&https=%{HTTPS} [L]
- And call from web browser any url e.g https://your_virtual_host_domain/php/dir/subdir/any-text.html
Example:
When I call from web browser url e.g. https://var.mybluelinux.com/php/dir1/subdir1/subsubdir1/my-file.php?myquestion&my-parameter=45
$_REQUEST['ua'] Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0
$_REQUEST['https'] on
$_GET['ua'] Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0
$_GET['https'] on
$_COOKIE['_ga'] GA1.2.998553010.1519138107
$_COOKIE['_gid'] GA1.2.578630594.1519138107
$_SERVER['REDIRECT_HTTPS'] on
$_SERVER['REDIRECT_SSL_TLS_SNI'] var.mybluelinux.com
$_SERVER['REDIRECT_STATUS'] 200
$_SERVER['HTTPS'] on
$_SERVER['SSL_TLS_SNI'] var.mybluelinux.com
$_SERVER['HTTP_HOST'] var.mybluelinux.com
$_SERVER['HTTP_USER_AGENT'] Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0
$_SERVER['HTTP_ACCEPT'] text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
$_SERVER['HTTP_ACCEPT_LANGUAGE'] en-US,en;q=0.7,cs;q=0.3
$_SERVER['HTTP_ACCEPT_ENCODING'] gzip, deflate, br
$_SERVER['HTTP_COOKIE'] _ga=GA1.2.998553010.1519138107; _gid=GA1.2.578630594.1519138107
$_SERVER['HTTP_CONNECTION'] keep-alive
$_SERVER['HTTP_UPGRADE_INSECURE_REQUESTS'] 1
$_SERVER['PATH'] /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
$_SERVER['SERVER_SIGNATURE'] <address>Apache/2.4.25 (Debian) Server at var.mybluelinux.com Port 443</address>
$_SERVER['SERVER_SOFTWARE'] Apache/2.4.25 (Debian)
$_SERVER['SERVER_NAME'] var.mybluelinux.com
$_SERVER['SERVER_ADDR'] 84.244.68.54
$_SERVER['SERVER_PORT'] 443
$_SERVER['REMOTE_ADDR'] 212.158.133.35
$_SERVER['DOCUMENT_ROOT'] /var/www/html/var.mybluelinux.com/data
$_SERVER['REQUEST_SCHEME'] https
$_SERVER['CONTEXT_PREFIX'] no value
$_SERVER['CONTEXT_DOCUMENT_ROOT'] /var/www/html/var.mybluelinux.com/data
$_SERVER['SERVER_ADMIN'] [no address given]
$_SERVER['SCRIPT_FILENAME'] /var/www/html/var.mybluelinux.com/data/php/echo.php
$_SERVER['REMOTE_PORT'] 50049
$_SERVER['REDIRECT_URL'] /php/dir1/subdir1/subsubdir1/my-file.php
$_SERVER['REDIRECT_QUERY_STRING'] ua=Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0&https=on
$_SERVER['GATEWAY_INTERFACE'] CGI/1.1
$_SERVER['SERVER_PROTOCOL'] HTTP/1.1
$_SERVER['REQUEST_METHOD'] GET
$_SERVER['QUERY_STRING'] ua=Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0&https=on
$_SERVER['REQUEST_URI'] /php/dir1/subdir1/subsubdir1/my-file.php?myquestion&my-parameter=45
$_SERVER['SCRIPT_NAME'] /php/echo.php
$_SERVER['PHP_SELF'] /php/echo.php
$_SERVER['REQUEST_TIME_FLOAT'] 1519214657.127
$_SERVER['REQUEST_TIME'] 1519214657