Skip to content

Using a custom php.ini file for cPanel cron jobs

On ruachost.com, PHP scripts run under different environments depending on how they are executed. This means that scripts run from the command line or via cPanel cron jobs may not use the same php.ini configuration as scripts run through the web server. To ensure consistency, you can specify a custom php.ini file for cron jobs.

  • Apply specific PHP settings (e.g., memory limits, execution time).
  • Enable directives required for cron‑based scripts (e.g., allow_url_fopen).
  • Ensure cron jobs behave the same way as web‑executed scripts.
  • Avoid conflicts between global server settings and application requirements.
  1. Log in to your hosting account via FTP, SFTP, or File Manager.

  2. Navigate to your home directory (e.g., /home/username/config/).

  3. Create or edit a php.ini file with the required directives. Example:

    memory_limit = 256M
    max_execution_time = 120
    allow_url_fopen = On

When setting up a cron job in cPanel → Cron Jobs, specify the path to your custom php.ini file using the -c option:

Terminal window
/usr/local/bin/php -c ${HOME}/config/php.ini ${HOME}/script.php
  • -c → tells PHP to use the specified configuration file.
  • ${HOME}/config/php.ini → path to your custom file.
  • ${HOME}/script.php → the script you want to run.
  1. Save the cron job in cPanel.
  2. Wait for the scheduled run or trigger it manually.
  3. Check logs or script output to confirm the custom settings are applied.

If your script needs to access remote URLs, you must enable the allow_url_fopen directive in your custom php.ini:

allow_url_fopen = On

Without this, the cron job may fail even if the directive is enabled for web‑based PHP scripts.