loading

Why My Upload Fails Every New Year

Back in early October, I fixed the permissions on the upload folder for this server. The issue was that image uploads were failing only on the first day of every month. I figured changing the owner and mode for the two year folders would take care of it. At that time, I noted in a post that I would re-test the actual uploads on November 1st. That's because "fixed" is not the same as "it works."

November 1st has passed. It worked. However, when I tested January 2027 using the same method, it failed. It works for one month, but then it stops again two months later. The fix I implemented was only one step short. In this post, I'm detailing what I missed when addressing the uploads that used to fail only on the first of the month, as covered in Monthly First-Day Upload Failures.

It Worked on November 1st

This server hosts three blogs, and each has its own dedicated upload folder. On the morning of November 1st, all three folders were successfully created.

Folder Creation Time Mode Owner
sites/2/2026/11 11-01 09:27:06.236 2775 apache:apache
sites/3/2026/11 11-01 09:31:06.534 2775 apache:apache
2026/11 11-01 09:41:25.128 2775 apache:apache

All three folders have a mode of 2775 and are owned by apache. The leading '2' in 2775 is the setgid bit, which means any new files created inside will inherit the parent's group. I set this up manually in October, and it successfully inherited the setting in November. This was exactly what I expected.

What stands out is that the three timestamps are spread out—9:27, 9:31, and 9:41. They weren't created at midnight, and the three blogs were spaced out by about 14 minutes. If something were creating them all at once at midnight, they wouldn't be staggered like this.

Creating Folders Wasn't the Upload Itself

I pulled up the access logs from that time. There were requests matching the creation time of three different folders, down to the second.

09:27:06  POST /wp-cron.php  200  "WordPress/7.0.8; https://kilho.org"
09:31:06  POST /wp-cron.php  200  "WordPress/7.0.8; https://damyo.net"
09:41:25  POST /wp-cron.php  200  "WordPress/7.0.8; https://wp.demobox.top"

The requests were coming from the server itself, and the User-Agent showed which blog initiated them. The timestamps for these three requests perfectly match the creation times of the three folders. These folders weren't made by someone uploading an image; they were created by a scheduled task.

So, the explanation for the symptom—"uploads only fail on the 1st of the month"—changes. It wasn't that a person tried to upload and failed on the 1st. Instead, the first scheduled task for that month tried to create the folder and failed, and then when a person tried to upload, it failed again because the folder wasn't there. The failure had already happened before anyone touched it. I previously looked into why "WordPress cron wasn't being triggered by visitors," and this time, I found that the cron was actually creating the folders.

There's Another Timestamp Matching Down to the Decimal Point

If you look at the creation times for the year folders, something strange pops out.

uploads/2026        2026-04-01 11:37:23.068697107
uploads/2026/04     2026-04-01 11:37:23.068697107   ← Same down to the nanosecond

sites/2/2026        2026-07-03 19:18:04.762645770
sites/2/2026/07     2026-07-03 19:18:04.763645777   ← A difference of 1 millisecond

The year folder and the first month folder inside it were created almost simultaneously. They weren't created in two separate steps; a single recursive creation process made both levels appear at once. WordPress builds the necessary paths from the top down, which means at that moment, it was capable of creating the year folder. That's not the case right now. This leads to the next point.

January 1, 2027: This is Where It Fails

Since we're heading into November, the next hurdle isn't December 1st; it's January 1st. The difference between changing months and changing years is the number of folders you need to create. December is just one folder, like 2026/12, but January requires two: 2027 and 2027/01.

I didn't wait around; I tested it in advance. I actually tried creating the year folders using the permissions of the user that WordPress runs as (the 'apache' user).

Folder I Tried to Create Result
uploads/2027 Permission denied
uploads/sites/2/2027 Permission denied
uploads/sites/3/2027 Permission denied

All three of my blogs failed. Even using WordPress functions yielded the same result. When I ask it to specify the upload folder for January 2027, it gives me the path, but it's always accompanied by an error.


Path Mode Owner Can Apache Write?
wp-content 755 root:root No
uploads 755 root:root No
uploads/sites 755 root:root No
uploads/sites/2 755 root:root No
uploads/sites/2/2026 2775 apache:apache Yes

What I fixed in October is on the very last line. Since you opened the year folder, you can create the month folder inside it. That's why November 1st was successful. However, what's needed to create the year folder itself is the section above it, and that section is closed.

In October, I approached this differently. Since one blog had been fine for seven months even though the top level was closed, I figured there was no need to open the top level. That observation was correct because all seven months fell within the same year. There were no instances crossing into a new year within those seven months, leaving an unverified assumption in place.

How I Measured It

When creating the folder, I read the creation time recorded by the file system down to the nanosecond. It was the creation time, not the modification time. These can be different, and this difference was a clue when tracking the issue in October.

I used live access logs. The records from the morning of November 1st are in the currently used file, not in a rotated archive. At first, I checked the rotated file but found nothing. Since the logs rotate at midnight on the 1st, the morning of the 1st is in the new file.

I included permission testing to avoid guesswork. While I could have just looked at the mode and owner and said, "It won't work," that's different from actually running an mkdir command with the permissions of the user who is actually running it. Since the php-fpm pool runs under Apache, I tested it as Apache. Command-line tools run as different users, so the results could vary.

What These Numbers Don't Tell You

I don't know why the year folder could be created the very first time it was made. Having the same nanosecond timestamp only means it was created recursively all at once; it doesn't tell you what the permissions were at that moment. There's no evidence to show whether someone later changed the parent folder to root ownership with 755 permissions, or if it was set up that way from the start and created via a different path.

Saying it will actually fail on January 1st is based on the current permissions. If you fix it in the meantime, it won't fail. This post isn't a prediction; it's a measurement of the current state.

While I confirmed that Cron was creating the folder based on the timing, I couldn't pinpoint which function in which scheduled task was requesting that path. There are no monthly cycles listed in the task schedule, only hourly, daily, and weekly ones. It looks like one of them is causing this by requesting the upload path, but to specify it, I'd have to wait for the first request of that month.

I Haven't Fixed It Yet

If you want to fix this now, you have two options. You can open the parent folder so Apache can access it, which will trigger recursive creation on January 1st and solve the issue. However, the folder you'd have to open is at the very top level of the upload directory, meaning it covers a very broad scope. The other option is to manually create the 2027 folder in advance at the end of the year. This is similar to the action we took in October, but then you'll have to do the same thing again in January 2028.

Whether one of these options is the right move depends entirely on how you plan to use this server, so I haven't decided yet. I'm leaving it as is for now. Once I decide, I'll update this post.

What I'm Going to Test Next

On December 1st, I'm going to check one more time to see if the three folders for 2026/12 are created automatically. Since it's within the same year, this should succeed. If it doesn't, then the explanation in this post is incorrect.

On January 1st, 2027, I'll check the year folders for three different blogs. If I haven't fixed the permissions by then, the folders shouldn't exist, and the actual upload should fail. If the outcome differs from my prediction, it means there's another way the folders are being created besides going through the parent folder.

Frequently Asked Questions

Why did it work in November but break again?

What worked in November was because I added one more month folder inside an already open year folder. January requires creating the entire year folder from scratch, and the permissions needed for that are one level higher up. That higher level is currently closed. The action we took in October only solved one of these two scenarios, and at that time, no cases spanning across years were in the measurement period, so the other issue didn't show up.

Why is there a difference between December 1st and January 1st?

The number of folders that need to be created is different. In December, it's just adding one more folder inside the already open 2026 folder. In January, it's creating the entire 2027 folder inside a closed area. Even though changing the month and changing the year might seem like the same thing, the directory depth is different. The fact that there were no issues for seven months was because all those seven months were within the same calendar year.

How did you hide the fact that Cron created the folders?

I hid it visually. I read the creation times of the three folders down to the nanosecond and found requests that arrived in the same second from the access logs on the same morning. All three were scheduled tasks sent by the server to itself, and the User-Agent indicated which blog sent it, which allowed me to match the folders to the blogs. However, that's beside the point; I couldn't hide which function within that request was calling for the path.