cURL in Cron PHP

Discussion in 'Installation/Configuration' started by sd12, Jun 4, 2024.

  1. sd12

    sd12 New Member

    Hi
    If i call the script.php in the browser, it works.
    But if the Script is inizialized by Cron:
    Code:
    /usr/bin/php [web_root]/script.php
    I getting this Error:
    Code:
    Fatal error: Uncaught Error: Call to undefined function curl_init() in /web/script.php:92
    The OS is Ubuntu 22
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    If it works in the browser, you only have to enter the URL into the corn command field.
     
  3. sd12

    sd12 New Member

    Thanks for the tip. I would like to do it via PHP not via wget.

    There are 2 reasons for this:
    - I would like to understand why it is currently not working :)
    - The script processes the logfile. This means that with every cron call via wget I (unnecessarily) generate another log entry.
     
  4. till

    till Super Moderator Staff Member ISPConfig Developer

    Curl extension is not installed in the CLI php used to run the script.
     
  5. sd12

    sd12 New Member

    I have in /etc/php/8.1/cli/php.ini
    Code:
    extension=curl
    uncommented.
    If i run as root
    Code:
     /usr/bin/php /var/www/clients/client1/web2/web/phpinfo.php
    i get:
    cURL support => enabled
    but if it runs as a cronjob i get no information about cURL.
    Whitch php.ini is the correct one i need to edit?
     
  6. ztk.me

    ztk.me Well-Known Member HowtoForge Supporter

    Is it a chrooted cronjob? What php version is installed in the chroot?
     
  7. Taleman

    Taleman Well-Known Member HowtoForge Supporter

    Start with this
    https://forum.howtoforge.com/threads/please-read-before-posting.58408/
    and show the report so we know what PHP version are running.

    Then check what PHP version and PHP mode is set for that website.
    Check curl extension is installed for the PHP version that job is running under.
    I think phpinfo() shows what php.ini files it reads, so check that.
     
  8. sd12

    sd12 New Member

    Thanks for your reply.

    It's a cronjob created via ISP Config

    PHP-FPM
    PHP 8.2

    If i run the command as root the phpinfo respond is:
    Code:
    /usr/bin/php /var/www/clients/client1/web2/web/phpinfo.php
    Loaded Configuration File => /etc/php/8.1/cli/php.ini

    If i run the command via Cron the phpinfo respond is:
    Code:
    /usr/bin/php /var/www/clients/client1/web2/web/phpinfo.php
    Loaded Configuration File => Loaded Configuration File => (none)


    Code:
    ##### SERVER #####
    IP-address (as per hostname): ***.***.***.***
    [WARN] could not determine server's ip address by ifconfig
    [INFO] OS version is Ubuntu 22.04.4 LTS
    
    [INFO] uptime:  13:40:52 up  4:26,  1 user,  load average: 0.17, 0.07, 0.01
    
    [INFO] memory:
                   total        used        free      shared  buff/cache   available
    Mem:           1.9Gi       410Mi       665Mi        53Mi       840Mi       1.2Gi
    Swap:             0B          0B          0B
    
    [INFO] systemd failed services status:
      UNIT                  LOAD   ACTIVE SUB    DESCRIPTION
    ● clamav-daemon.service loaded failed failed Clam AntiVirus userspace daemon
    
    LOAD   = Reflects whether the unit definition was properly loaded.
    ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
    SUB    = The low-level unit activation state, values depend on unit type.
    1 loaded units listed.
    
    [INFO] ISPConfig is installed.
    
    ##### ISPCONFIG #####
    ISPConfig version is 3.2.11p2
    
    
    ##### VERSION CHECK #####
    
    [INFO] php (cli) version is 8.1.28
    [INFO] php-cgi (used for cgi php in default vhost!) is version 8.1.28
    
    ##### PORT CHECK #####
    
    [WARN] Port 143 (IMAP server) seems NOT to be listening
    [WARN] Port 993 (IMAP server SSL) seems NOT to be listening
    [WARN] Port 110 (POP3 server) seems NOT to be listening
    [WARN] Port 995 (POP3 server SSL) seems NOT to be listening
    [WARN] Port 465 (SMTP server SSL) seems NOT to be listening
    
    ##### MAIL SERVER CHECK #####
    
    [WARN] I found no "submission" entry in your postfix master.cf
    [INFO] this is not critical, but if you want to offer port 587 for smtp connections you have to enable this.
    [WARN] I found no "smtps" entry in your postfix master.cf
    [INFO] this is not critical, but if you want to offer SSL for smtp (not TLS) connections you have to enable this.
    
    ##### RUNNING SERVER PROCESSES #####
    
    [INFO] I found the following web server(s):
            Unknown process (nginx:) (PID 8928)
    [INFO] I found the following mail server(s):
            Postfix (PID 1595)
    [WARN] I could not determine which pop3 server is running.
    [WARN] I could not determine which imap server is running.
    [INFO] I found the following ftp server(s):
            PureFTP (PID 1012)
    
    ##### LISTENING PORTS #####
    (only           ()
    Local           (Address)
    [localhost]:53          (774/named)
    [localhost]:25          (1595/master)
    [anywhere]:8081         (8928/nginx:)
    [anywhere]:8080         (8928/nginx:)
    ***.***.***.***:53              (622/systemd-resolve)
    ***.***.***.***:443             (8928/nginx:)
    [anywhere]:80           (8928/nginx:)
    [anywhere]:22           (763/sshd:)
    [anywhere]:21           (1012/pure-ftpd)
    [localhost]:953         (774/named)
    [anywhere]:3306         (904/mariadbd)
    [localhost]:11211               (680/memcached)
    ***.***.***.***:53              (774/named)
    *:*:*:*::*:8081         (8928/nginx:)
    *:*:*:*::*:8080         (8928/nginx:)
    *:*:*:*::*:53           (774/named)
    *:*:*:*::*:25           (1595/master)
    *:*:*:*::*:53           (774/named)
    *:*:*:*::*:953          (774/named)
    *:*:*:*::*:80           (8928/nginx:)
    *:*:*:*::*:22           (763/sshd:)
    *:*:*:*::*:21           (1012/pure-ftpd)
    *:*:*:*::*:3306         (904/mariadbd)
    *:*:*:*::**:*:*:*::*53          (774/named)
    
    
    
    
    ##### IPTABLES #####
    Chain INPUT (policy DROP)
    target     prot opt source               destination
    f2b-sshd   tcp  --  [anywhere]/0            [anywhere]/0            multiport dports 22
    ufw-before-logging-input  all  --  [anywhere]/0            [anywhere]/0
    ufw-before-input  all  --  [anywhere]/0            [anywhere]/0
    ufw-after-input  all  --  [anywhere]/0            [anywhere]/0
    ufw-after-logging-input  all  --  [anywhere]/0            [anywhere]/0
    ufw-reject-input  all  --  [anywhere]/0            [anywhere]/0
    ufw-track-input  all  --  [anywhere]/0            [anywhere]/0
    
    Chain FORWARD (policy DROP)
    target     prot opt source               destination
    ufw-before-logging-forward  all  --  [anywhere]/0            [anywhere]/0
    ufw-before-forward  all  --  [anywhere]/0            [anywhere]/0
    ufw-after-forward  all  --  [anywhere]/0            [anywhere]/0
    ufw-after-logging-forward  all  --  [anywhere]/0            [anywhere]/0
    ufw-reject-forward  all  --  [anywhere]/0            [anywhere]/0
    ufw-track-forward  all  --  [anywhere]/0            [anywhere]/0
    
    Chain OUTPUT (policy ACCEPT)
    target     prot opt source               destination
    ufw-before-logging-output  all  --  [anywhere]/0            [anywhere]/0
    ufw-before-output  all  --  [anywhere]/0            [anywhere]/0
    ufw-after-output  all  --  [anywhere]/0            [anywhere]/0
    ufw-after-logging-output  all  --  [anywhere]/0            [anywhere]/0
    ufw-reject-output  all  --  [anywhere]/0            [anywhere]/0
    ufw-track-output  all  --  [anywhere]/0            [anywhere]/0
    
    Chain f2b-sshd (1 references)
    target     prot opt source               destination
    REJECT     all  --  ***.***.***.***       [anywhere]/0            reject-with icmp-port-unreachable
    RETURN     all  --  [anywhere]/0            [anywhere]/0
    
    Chain ufw-after-forward (1 references)
    target     prot opt source               destination
    
    Chain ufw-after-input (1 references)
    target     prot opt source               destination
    ufw-skip-to-policy-input  udp  --  [anywhere]/0            [anywhere]/0            udp dpt:137
    ufw-skip-to-policy-input  udp  --  [anywhere]/0            [anywhere]/0            udp dpt:138
    ufw-skip-to-policy-input  tcp  --  [anywhere]/0            [anywhere]/0            tcp dpt:139
    ufw-skip-to-policy-input  tcp  --  [anywhere]/0            [anywhere]/0            tcp dpt:445
    ufw-skip-to-policy-input  udp  --  [anywhere]/0            [anywhere]/0            udp dpt:67
    ufw-skip-to-policy-input  udp  --  [anywhere]/0            [anywhere]/0            udp dpt:68
    ufw-skip-to-policy-input  all  --  [anywhere]/0            [anywhere]/0            ADDRTYPE match dst-type BROADCAST
    
    Chain ufw-after-logging-forward (1 references)
    target     prot opt source               destination
    LOG        all  --  [anywhere]/0            [anywhere]/0            limit: avg 3/min burst 10 LOG flags 0 level 4 prefix "[UFW BLOCK] "
    
    Chain ufw-after-logging-input (1 references)
    target     prot opt source               destination
    LOG        all  --  [anywhere]/0            [anywhere]/0            limit: avg 3/min burst 10 LOG flags 0 level 4 prefix "[UFW BLOCK] "
    
    Chain ufw-after-logging-output (1 references)
    target     prot opt source               destination
    
    Chain ufw-after-output (1 references)
    target     prot opt source               destination
    
    Chain ufw-before-forward (1 references)
    target     prot opt source               destination
    ACCEPT     all  --  [anywhere]/0            [anywhere]/0            ctstate RELATED,ESTABLISHED
    ACCEPT     icmp --  [anywhere]/0            [anywhere]/0            icmptype 3
    ACCEPT     icmp --  [anywhere]/0            [anywhere]/0            icmptype 11
    ACCEPT     icmp --  [anywhere]/0            [anywhere]/0            icmptype 12
    ACCEPT     icmp --  [anywhere]/0            [anywhere]/0            icmptype 8
    ufw-user-forward  all  --  [anywhere]/0            [anywhere]/0
    
    Chain ufw-before-input (1 references)
    target     prot opt source               destination
    ACCEPT     all  --  [anywhere]/0            [anywhere]/0
    ACCEPT     all  --  [anywhere]/0            [anywhere]/0            ctstate RELATED,ESTABLISHED
    ufw-logging-deny  all  --  [anywhere]/0            [anywhere]/0            ctstate INVALID
    DROP       all  --  [anywhere]/0            [anywhere]/0            ctstate INVALID
    ACCEPT     icmp --  [anywhere]/0            [anywhere]/0            icmptype 3
    ACCEPT     icmp --  [anywhere]/0            [anywhere]/0            icmptype 11
    ACCEPT     icmp --  [anywhere]/0            [anywhere]/0            icmptype 12
    ACCEPT     icmp --  [anywhere]/0            [anywhere]/0            icmptype 8
    ACCEPT     udp  --  [anywhere]/0            [anywhere]/0            udp spt:67 dpt:68
    ufw-not-local  all  --  [anywhere]/0            [anywhere]/0
    ACCEPT     udp  --  [anywhere]/0            ***.***.***.***          udp dpt:5353
    ACCEPT     udp  --  [anywhere]/0            ***.***.***.***      udp dpt:1900
    ufw-user-input  all  --  [anywhere]/0            [anywhere]/0
    
    Chain ufw-before-logging-forward (1 references)
    target     prot opt source               destination
    
    Chain ufw-before-logging-input (1 references)
    target     prot opt source               destination
    
    Chain ufw-before-logging-output (1 references)
    target     prot opt source               destination
    
    Chain ufw-before-output (1 references)
    target     prot opt source               destination
    ACCEPT     all  --  [anywhere]/0            [anywhere]/0
    ACCEPT     all  --  [anywhere]/0            [anywhere]/0            ctstate RELATED,ESTABLISHED
    ufw-user-output  all  --  [anywhere]/0            [anywhere]/0
    
    Chain ufw-logging-allow (0 references)
    target     prot opt source               destination
    LOG        all  --  [anywhere]/0            [anywhere]/0            limit: avg 3/min burst 10 LOG flags 0 level 4 prefix "[UFW ALLOW] "
    
    Chain ufw-logging-deny (2 references)
    target     prot opt source               destination
    RETURN     all  --  [anywhere]/0            [anywhere]/0            ctstate INVALID limit: avg 3/min burst 10
    LOG        all  --  [anywhere]/0            [anywhere]/0            limit: avg 3/min burst 10 LOG flags 0 level 4 prefix "[UFW BLOCK] "
    
    Chain ufw-not-local (1 references)
    target     prot opt source               destination
    RETURN     all  --  [anywhere]/0            [anywhere]/0            ADDRTYPE match dst-type LOCAL
    RETURN     all  --  [anywhere]/0            [anywhere]/0            ADDRTYPE match dst-type MULTICAST
    RETURN     all  --  [anywhere]/0            [anywhere]/0            ADDRTYPE match dst-type BROADCAST
    ufw-logging-deny  all  --  [anywhere]/0            [anywhere]/0            limit: avg 3/min burst 10
    DROP       all  --  [anywhere]/0            [anywhere]/0
    
    Chain ufw-reject-forward (1 references)
    target     prot opt source               destination
    
    Chain ufw-reject-input (1 references)
    target     prot opt source               destination
    
    Chain ufw-reject-output (1 references)
    target     prot opt source               destination
    
    Chain ufw-skip-to-policy-forward (0 references)
    target     prot opt source               destination
    DROP       all  --  [anywhere]/0            [anywhere]/0
    
    Chain ufw-skip-to-policy-input (7 references)
    target     prot opt source               destination
    DROP       all  --  [anywhere]/0            [anywhere]/0
    
    Chain ufw-skip-to-policy-output (0 references)
    target     prot opt source               destination
    ACCEPT     all  --  [anywhere]/0            [anywhere]/0
    
    Chain ufw-track-forward (1 references)
    target     prot opt source               destination
    
    Chain ufw-track-input (1 references)
    target     prot opt source               destination
    
    Chain ufw-track-output (1 references)
    target     prot opt source               destination
    ACCEPT     tcp  --  [anywhere]/0            [anywhere]/0            ctstate NEW
    ACCEPT     udp  --  [anywhere]/0            [anywhere]/0            ctstate NEW
    
    Chain ufw-user-forward (1 references)
    target     prot opt source               destination
    
    Chain ufw-user-input (1 references)
    target     prot opt source               destination
    ACCEPT     tcp  --  [anywhere]/0            [anywhere]/0            tcp dpt:20
    ACCEPT     tcp  --  [anywhere]/0            [anywhere]/0            tcp dpt:21
    ACCEPT     tcp  --  [anywhere]/0            [anywhere]/0            tcp dpt:22
    ACCEPT     tcp  --  [anywhere]/0            [anywhere]/0            tcp dpt:80
    ACCEPT     tcp  --  [anywhere]/0            [anywhere]/0            tcp dpt:443
    ACCEPT     tcp  --  [anywhere]/0            [anywhere]/0            multiport dports 40110:40210
    ACCEPT     tcp  --  [anywhere]/0            [anywhere]/0            tcp dpt:8080
    ACCEPT     tcp  --  [anywhere]/0            [anywhere]/0            tcp dpt:8081
    
    Chain ufw-user-limit (0 references)
    target     prot opt source               destination
    LOG        all  --  [anywhere]/0            [anywhere]/0            limit: avg 3/min burst 5 LOG flags 0 level 4 prefix "[UFW LIMIT BLOCK] "
    REJECT     all  --  [anywhere]/0            [anywhere]/0            reject-with icmp-port-unreachable
    
    Chain ufw-user-limit-accept (0 references)
    target     prot opt source               destination
    ACCEPT     all  --  [anywhere]/0            [anywhere]/0
    
    Chain ufw-user-logging-forward (0 references)
    target     prot opt source               destination
    
    Chain ufw-user-logging-input (0 references)
    target     prot opt source               destination
    
    Chain ufw-user-logging-output (0 references)
    target     prot opt source               destination
    
    Chain ufw-user-output (1 references)
    target     prot opt source               destination
    
    
    
    
    ##### LET'S ENCRYPT #####
    acme.sh is installed in /root/.acme.sh/acme.sh
    
     
  9. ztk.me

    ztk.me Well-Known Member HowtoForge Supporter

    but is it FULL or chrooted using jailkit
     
  10. till

    till Super Moderator Staff Member ISPConfig Developer

    If it's chrooted, then you could create a chrooted shell user in ISPConfig, login with this shell user and test then, as it will see the same environment as your chrooted cronjob.
     
    ztk.me likes this.
  11. sd12

    sd12 New Member

    In the Cron Job Section i have no Option to set this.

    In the website Config under Options all "chroot" are disabled or empty.
     

    Attached Files:

  12. ztk.me

    ztk.me Well-Known Member HowtoForge Supporter

    well, what is logged if you use this code then? assuming you did not disable ini_set, which imho one should but that's another topic
    Code:
    <?php
    ini_set('display_errors', '1');
    ini_set('display_startup_errors', '1');
    error_reporting(E_ALL);
    
    echo phpversion()."\n";
    
    print_r(get_loaded_extensions());
     
  13. sd12

    sd12 New Member

    Code:
    8.1.28
    Array
    (
        [0] => Core
        [1] => date
        [2] => libxml
        [3] => openssl
        [4] => pcre
        [5] => zlib
        [6] => filter
        [7] => hash
        [8] => json
        [9] => pcntl
        [10] => Reflection
        [11] => SPL
        [12] => session
        [13] => standard
        [14] => sodium
    )
    
     
  14. ztk.me

    ztk.me Well-Known Member HowtoForge Supporter

  15. sd12

    sd12 New Member

    The solution was to select under Clients / Limits / Cron Job Limits -> Max. Allowed Cronjob types to “Full Cron”.
     
  16. till

    till Super Moderator Staff Member ISPConfig Developer

    That's just a workaround, by using the global PHP installation. But if you do not have the security requirement to run it separated in a jail, then that's fine. The solution would have been to add the PHP curl extension to the jail and enable it there.
     
    ztk.me likes this.

Share This Page