What are the best practices for setting file permissions when working with PHP scripts?

When working with PHP scripts, it is important to set appropriate file permissions to ensure security and prevent unauthorized access. A common best practice is to set the file permissions to 644 for files and 755 for directories. This allows the owner to read and write the file, while others can only read it. Additionally, it is recommended to avoid setting files and directories to 777 as it gives full permissions to everyone, which can be a security risk.

// Set file permissions to 644 for files and 755 for directories
chmod("path/to/file.php", 0644);
chmod("path/to/directory", 0755);