Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

247
Views
How to add environment variables to the apache user when executing a cron job / Yii2 controller in Amazon Linux 2?

I have developed a console controller in Yii2 for pulling in data and sending emails. My goal is to automate this task with crontab, which I have done using the yii2tech-crontab library. The issue I am experiencing is that the environment variables that I have set inside Apache configuration (inside our ssl.conf) do not apply when running things as the Apache user (say cron), but do work inside any of our website code.

What makes this a bit harder is that the apache user does not have a home directory (so I can't create a .profile), and I am unable to locate any sort of global apache user specific configuration.

One option would be to set these variables inside /etc/environment, however since these are sensitive credentials, I'd rather them not be accessible to other users.

I was able to add these environment variables to my current shell by creating a /etc/apache-environment file that was owned and grouped to apache, and then updating my cron entry to 0 8 * * * . /etc/apache-environment; php yii cron/task but php does not seem to pickup any of these credentials.

I have also tried setting php's variables_order to just load in environment (in case it was getting cleared) but that didn't change anything.

Are there any other options out there? Thanks for any feedback or help!

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!