Home  >  Article  >  Backend Development  >  Why Does PHP\'s mkdir Function Return \"Permission Denied\" and How Can I Fix It?

Why Does PHP\'s mkdir Function Return \"Permission Denied\" and How Can I Fix It?

Susan Sarandon
Susan SarandonOriginal
2024-10-25 03:11:29597browse

Why Does PHP's mkdir Function Return

Permission Denied When Using PHP mkdir Function

When using PHP's mkdir function to create a directory, you may encounter a "Permission denied" error. This error indicates that the PHP process, typically running under Apache, does not have the necessary permissions to create the directory.

Solution: Correct File Ownership and Permissions

To resolve this issue, adjust the file ownership and permissions on the parent directory where you intend to create the new subdirectory.

In Ubuntu, follow these steps:

  1. Set File Ownership: Ensure that all files within the web server's document root have ownership set to the Apache group and user (typically "www-data" in Ubuntu). Run the following command:
sudo chown -R www-data:www-data /path/to/webserver/www
  1. Grant Write Permissions to Group: Enable all members of the "www-data" group to have read and write access to the same directory by using the following command:
sudo chmod -R g+rw /path/to/webserver/www

After making these changes, the PHP mkdir function should operate correctly without prompting permission errors.

The above is the detailed content of Why Does PHP\'s mkdir Function Return \"Permission Denied\" and How Can I Fix It?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn