How to set php permissions in apache: 1. Grant permissions to the 0777 file itself; 2. Change the ownership to the Apache user "www-data" and grant the owner write permissions; 3. Add the user to " www-data" group, and then group write permissions.
Recommended: "PHP Video Tutorial"
Specific questions:
How to give Apache permission to write to the home directory?
My server is in /var/www/html I have a php script in /var/www/html/fileio_test/io_test.php
<?php $logging = <<< LOG This is a test LOG; $testfile = fopen('/home/djameson/test.txt', 'a'); fwrite ($testfile, $logging); fclose($testfile); ?>
When I try to run this script, I got
Warning: fopen(/home/djameson/test.txt): failed to open stream: Permission denied in /var/www/html/fileio_test/io_test.php on line 7 Warning: fwrite() expects parameter 1 to be resource, boolean given in /var/www/html/fileio_test/io_test.php on line 8 Warning: fclose() expects parameter 1 to be resource, boolean given in /var/www/html/fileio_test/io_test.php on line 9
How do I get Apache to write to my home directory? The server is running on Fedora 20.
Solution:
Since your files are located in your home directory, I recommend using one of the following methods.
Grant 0777 permissions to the file itself.
chmod 0777 /home/djameson/test.txt
Change ownership to Apache user www-data and grant write permission to the owner.
Sudo chown www-data:www-data /home/djameson/test.txt chmod 0744 /home/djameson/test.txt
Add your user to www-data group or vice versa add www-data user to your group. Then group write permissions.
Sudo usermod -a -G www-data djameson chmod 0764 /home/djameson/test.txt
Note: I assume the Apache username and group name are www-data and www-data respectively. You have to change the server Apache username/group name accordingly.
The above is the detailed content of How to set php permissions in apache. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver Mac version
Visual web development tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

WebStorm Mac version
Useful JavaScript development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment
