Change Directory Permissions

Jyotishgher Astrology
By -
0

 Change Directory Permissions


The error you're encountering indicates that the PHP script doesn't have the necessary permissions to write to the specified directory. This is a common issue when working with file operations on a server. Here's how you can resolve it:

Change Directory Permissions


Steps to Resolve Permission Denied Error

  1. Check Directory Permissions: Let us assume it for me 

    • Ensure that the directory /var/www/html/images/electrical/ exists.
    • The web server (e.g., Apache, Nginx) user (usually www-data or apache) needs write permissions for this directory.
  2. Change Directory Permissions:

    • You can change the permissions of the directory to make it writable. Use the chmod command to set the appropriate permissions.
    • Use chown to change the ownership of the directory to the web server user.
# Navigate to the directory
cd /var/www/html/images

# Ensure the 'electrical' directory exists
mkdir -p electrical

# Change the owner to the web server user (e.g., www-data for Apache on Ubuntu)
sudo chown -R www-data:www-data electrical

# Set the permissions to 755 (rwxr-xr-x) or 775 (rwxrwxr-x) if group write access is needed
sudo chmod -R 755 electrical


To change the owner of a folder from android to apache (or the appropriate web server user) on a Linux system, you can use the chown command. Here's how you can do it:

Change Directory Owner Command

  1. Open a terminal.
  2. Navigate to the directory where the images-this is my case folder is located, if necessary.
  3. Run the chown command to change the ownership.

Assuming apache is the web server user (if you're using Apache HTTP Server), you would use the following command:Suppose i have created a folder to store images with the owner as android

i want to change the owener of the folder images from android to apache in linus command 

I will write it as :SYNTAX-sudo chown -R apache:apache /path/to/images

sudo chown -R apache:apache /var/www/html/images/

Explanation:

  • sudo: Runs the command with superuser privileges.
  • chown: Changes the file owner and group.
  • -R: Applies the change recursively to all files and subdirectories within the specified directory.
  • apache:apache or www-data:www-data: Specifies the new owner and group for the directory.

Verify Ownership

After changing the ownership, you can verify it using the ls -l command:

 Permission Denied Error

#After  Change the owner to the web server user (e.g., www-data for Apache on Ubuntu)
# Set the permissions to 755 (rwxr-xr-x) or 775 (rwxrwxr-x) if group write access is needed sudo chmod -R 755 electrical

Post a Comment

0Comments

Post a Comment (0)