Home > Article > Backend Development > Solution to crontab being unable to execute php_php tips
This article analyzes the solution to the problem that crontab cannot execute php. Share it with everyone for your reference, the details are as follows:
When using crontab to run PHP programs, everyone has their own way of debugging. I also have a method. Let’s take a look at how I solved the problem that crontab cannot execute the php program.
1. Does the php file have execution permissions
-rwxr-xr-x 1 zwh ftpgroup 494 10-20 16:42 del_redis.php
If there is no X, it means that there is no execution permission, and of course it cannot be executed. If you don't know whether the group to which the user you are logging in has permissions, just add permissions to all groups. Here’s how:
The solution is as follows:
1. Write logs in the PHP program (for example: the error_log() function). This is also necessary because crontab is executed regularly. If there is no log, how do you know the results of program execution. In this way, we can view the execution status of crontab through log.
2. You can also directly output the execution results to a file in crontab. Then check the execution status in this file. For example:
4. PHP relative path problem
Because of the fixed mindset, this problem is also the easiest to ignore.
The solution is as follows:
Readers who are interested in more PHP-related content can check out the special topics of this site: "Introduction to PHP Basic Syntax Tutorial" and "Introduction to PHP Object-Oriented Programming Tutorial"
I hope this article will be helpful to everyone in PHP programming.