Environment Variables are used to set up the PHP application and the application runs smoothly. The issue that I'm facing is when I'm trying to reference the application's database connection file and run it from CLI.
Apache Set Up:
<VirtualHost *:80>
DocumentRoot /var/www/html
ServerName server.hostname.com
SetEnv HOSTNAME 'hostname'
SetEnv USERNAME 'username'
SetEnv DB_PASSWORD 'password'
SetEnv DB_NAME 'databaseName'
</VirtualHost>
The environment variables store all the connection-related data and the connection is referencing that.
Connection:
<?php
$username = $_SERVER['USERNAME'];
$password = $_SERVER['DB_PASSWORD'];
$hostname = $_SERVER['HOSTNAME'];
$database = $_SERVER['DB_NAME'];
error_reporting(0);
$mysqli = new mysqli($hostname, $username, $password, $database);
But, when I run it from CLI, it doesn't pick up the environment variables and it also doesn't let me run the cronjobs that are set up on the server because of the same reason.