What best practices should be followed when setting permissions for directories in PHP?

When setting permissions for directories in PHP, it is important to follow best practices to ensure the security and integrity of your application. One common approach is to set directory permissions to 755, which allows the owner to read, write, and execute the directory, while allowing others to only read and execute. This helps prevent unauthorized access to sensitive files and directories.

// Set directory permissions to 755
$directory = '/path/to/directory';
chmod($directory, 0755);