Welcome Guest, Not a member yet? Register   Sign In
PHP Spark not picking up environment variable (undefined constant ENVIRONMENT)
#1

(This post was last modified: 06-09-2024, 07:51 PM by kenjis.)

Hi,
I am using php spark to bootstrap the tables/database seeding in my codeigniter 4 app, but spark is not recognizing the "ENVIRONMENT" environment variable set by docker-compose.yml. To clarify, my CI4 app is picking up the environment variables, just not spark.
Here is the stack trace from the docker container when I run: php spark
Code:
Fatal error: Uncaught Error: Undefined constant "ENVIRONMENT" in /var/www/html/Tooths/system/Common.php:777
Stack trace:
#0 /var/www/html/Tooths/system/Debug/Exceptions.php(458): log_message('warning', '[DEPRECATED] {m...', Array)
#1 /var/www/html/Tooths/system/Debug/Exceptions.php(216): CodeIgniter\Debug\Exceptions->handleDeprecationError('Creation of dyn...', '/var/www/html/T...', 218)
#2 /var/www/html/Tooths/app/Config/App.php(218): CodeIgniter\Debug\Exceptions->errorHandler(8192, 'Creation of dyn...', '/var/www/html/T...', 218)
#3 /var/www/html/Tooths/system/Config/Factories.php(235): Config\App->__construct()
#4 /var/www/html/Tooths/system/Config/Factories.php(169): CodeIgniter\Config\Factories::createInstance('config', 'Config\\App', Array)
#5 /var/www/html/Tooths/system/Config/Factories.php(188): CodeIgniter\Config\Factories::__callStatic('config', Array)
#6 /var/www/html/Tooths/system/Common.php(207): CodeIgniter\Config\Factories::get('config', 'Config\\App')
#7 /var/www/html/Tooths/system/Config/Services.php(564): config('Config\\App')
#8 /var/www/html/Tooths/system/Config/BaseService.php(311): CodeIgniter\Config\Services::incomingrequest(NULL, false)
#9 /var/www/html/Tooths/system/Config/Services.php(526): CodeIgniter\Config\BaseService::__callStatic('incomingrequest', Array)
#10 /var/www/html/Tooths/system/Config/BaseService.php(311): CodeIgniter\Config\Services::request(NULL, false)
#11 /var/www/html/Tooths/system/Config/BaseService.php(250): CodeIgniter\Config\BaseService::__callStatic('request', Array)
#12 /var/www/html/Tooths/system/Config/Services.php(522): CodeIgniter\Config\BaseService::getSharedInstance('request', NULL)
#13 /var/www/html/Tooths/system/Config/BaseService.php(311): CodeIgniter\Config\Services::request()
#14 /var/www/html/Tooths/system/Debug/Exceptions.php(129): CodeIgniter\Config\BaseService::__callStatic('request', Array)
#15 /var/www/html/Tooths/system/Debug/Exceptions.php(252): CodeIgniter\Debug\Exceptions->exceptionHandler(Object(ErrorException))
#16 [internal function]: CodeIgniter\Debug\Exceptions->shutdownHandler()
#17 {main}
  thrown in /var/www/html/Tooths/system/Common.php on line 777

Not sure if relevant, but I also found the following output in the logs:

Code:
This "system/bootstrap.php" is no longer used. If you are seeing this error message,
the upgrade is not complete. Please refer to the upgrade guide and complete the upgrade.
See https://codeigniter4.github.io/userguide/installation/upgrade_450.html
Reply
#2

As the error message says, complete the upgrade.
Upgrade the "spark" file.
See https://codeigniter4.github.io/userguide...-and-spark
Reply
#3

(This post was last modified: 06-09-2024, 10:08 PM by davei94.)

I upgraded to CI 4.5.1, but I'm still getting an error when the docker compose container runs
Code:
tooths-backend-1  | Could not open input file: spark
but when I ssh into a fresh container of the image, and cd to /var/www/html, when I run "php spark" I get
Code:
CodeIgniter v4.5.1 Command Line Tool - Server Time: 2024-06-10 04:00:45 UTC+00:00

When I run "php spark migrate"
I get the same output. No mention of tables migrated.

The environment variables are defined in the docker compose script, and that includes my database credentials. so I can understand why php spark migrate is not working on the fresh container, but the error still stands - why can't I open input file 'spark'?
In my Dockerfile I COPY spark to /var/www/html/spark, then RUN chown -R www-data:www-data /var/www/html , and then RUN chmod +x /var/www/html/spark

Solved the issue by copying spark into my app directory, and changing the paths
require FCPATH . 'app/Config/Paths.php'
and
require 'system/Boot.php'
Reply




Theme © iAndrew 2016 - Forum software by © MyBB