Alternative to CHMOD 777 for writing in directories/folders

Hi,

I have a PHP script that create a file on a specific directory, it works on localhost, but when I upload it to my server, I would need to set the folder to chmod 777 for the PHP script to be able to write on that directory.

Considering that CHMOD 777 is not the best practice, how can I make that directory writable by the PHP script, without changing the chmod of the folder?

If found this resource (Permission settings - #8 by figueroa34), but I am not sure if it’s the right solution, and I am a bit confused if www-data is a universal user or if it should be replaced by the user that I created, under which the script is hosted.

Thank you!

With php-fpm Hestia runs by default on the user:user so chmod 777 should not be needed.

That’s what I thought, but the PHP script was not writing in the directory to create/update a file, and it was not even giving any errors.