Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

curiosity's avatar

mkdir on Laravel production - permission denied

Hi,

I have a scheduled command that sometimes creates a new directory, however on a server it doesn't actually work unless I were to run it manually with sudo.

It would return an error that it does not have permissions to mkdir() from the statement like File::makeDirectory($myImageFolder, 0755, true)

My question is, what's the best way to handle this scenario?

0 likes
3 replies
jryd's avatar

You are getting this error as the user trying to create the folder does not have permission to create a folder in that directory.

You should ensure that the user your web application runs as has sufficient privileges to write files to your project.

hajrovica's avatar

yep as @jryd mentioned, bascially this is not laravel issue but server issue. Contact you server admin to give your web server user proper permissions on specific folder where do you want to create files.

if you do have access to terminal you could do something like sudo chmod -R 755 path/to/folder but again that could leave ownership issues

curiosity's avatar
curiosity
OP
Best Answer
Level 1

It seems like the problem was being caused because the folder in which directories was being made, was made by root

Therefore, when forge tried to create a directory, it didn't have permissions to make the directory.

The solution was to use sudo chown forge:forge folderName -R and once that was done, everything began to work like a charm and File::makeDirectory($examplePath, 0755, true) worked in scheduled commands and in tinker

Thanks to everyone who helped :) @hajrovica @jryd

Please or to participate in this conversation.