search
HomeBackend DevelopmentPHP ProblemHow to set php permissions in apache

How to set php permissions in apache

Sep 12, 2020 am 10:46 AM
apachephp

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.

How to set php permissions in apache

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(&#39;/home/djameson/test.txt&#39;, &#39;a&#39;); 
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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

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

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

Dreamweaver Mac version

Visual web development tools

MantisBT

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

WebStorm Mac version

Useful JavaScript development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment