Skip to content

Instantly share code, notes, and snippets.

@vanduc1102
Created June 18, 2020 13:53
Show Gist options
  • Save vanduc1102/3b6449a9112442ee28f1e73b9c75bac5 to your computer and use it in GitHub Desktop.
Save vanduc1102/3b6449a9112442ee28f1e73b9c75bac5 to your computer and use it in GitHub Desktop.
PHP .htaccess environment variables
<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
SetEnv DB_NAME test
SetEnv DB_USER root
SetEnv DB_PASSWORD test
SetEnv DB_HOST db
php_value upload_max_filesize 12800M
php_value post_max_size 12800M
php_value memory_limit 2560M
php_value max_execution_time 30000
php_value max_input_time 30000
@vanduc1102
Copy link
Author

vanduc1102 commented Jun 23, 2020

Any apache custom file: custom.conf

Listen 7001
<VirtualHost *:7001>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/site-a
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    SetEnv DB_NAME site-a
</VirtualHost>

Listen 7002
<VirtualHost *:7002>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/site-b
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    SetEnv DB_NAME site-b
</VirtualHost>

Listen 7003
<VirtualHost *:7003>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html/site-c
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

SetEnv DB_USER root
SetEnv DB_PASSWORD test
SetEnv DB_HOST db

can be access via $_SERVER['DB_HOST']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment