Permission with the linux server using apache and php - php

I have setup an linux CentOS 7 server to run php and i using apache, but when all done php can't write file even i have set chmod 777 and i have chown apache at the owner of the directory.
If the file exist, i can write the data on it, but if file don't exist
i can create it, it notice me don't have permission (folder is chmod
777).
Thanks for your help.

Related

PHP - chmod(): Operation not permitted

I have files that owned by root and I want to change it permission with php using chmod(). But it gave me an error chmod(): Operation not permitted instead.
if (file_exists($filepath)) {
chmod($filepath, 0755);
}
PHP Error Response
How to use chmod() in php but the files ownership are root ?
Can I achieve this without changing files ownership ?
Application Environment:
PHP 7.1.33
Code Igniter 3 framework
Apache 2.4.6
CentOS Linux release 7.8.2003
Any answer are appreciated, thanks before.
EDIT:
I've run ps aux | grep httpd and it shows only root and apache on the list.
As the files are owned by root and not www-data, apache will not have permissions to change the file's read and write permissions. You would need to set the folder to be owned and writable by www-data.
The command in centOS for doing so is
sudo chown -R apache:apache ./filepath
You would need sudo for the root owner as well as replace filepath with your folder's name

How Do I Give My Apache Server Access to Write to Files?

I am running an apache webserver on a virtual machine on my pc. The vm is running zorin linux. I have written a php script that writes some data to another text file in the same directory. Both files are located in /var/www/html/. I have already verified that the webserver user is www-data, and I have attempted to make that user owner of the /var/www/html directory, as well as everything within that directory. Here is the command that I have used to do this:
sudoo chown -R www-data /var/www/html/*
I have also verified that the www-data user is the owner of this directory and it's contents using
ls -dl /var/www/html/
ls -dl /var/www/html/*
both return that the owner is www-data.
Even after doing all of this, the php file is still unable to write to the file correctly. At this point I am stumped. Any help would be greatly appreciated.

PHP permission error on writing to a file in Linux CentOS

I have installed linux centos 7 on a VmWare in Windows.
There are two users in the linux: root, sample
I have created a laravel project with user "sample" (logged in as sample), but when I try to run the project with user root (logged in as root), it throws a permission error that cannot write to the file (file_put_content()). I have tried
chmod 777 /var/www/html/laravel
Or even I have tried to change the permission of the write-access of the file to root using right-click->properties->permission, but to no avail.
The only possible solution has been to delete the file and re-create it with user root. Now, what is the solution? I though user root is privileged to do anything. But it seems it is not the case. What is the solution? How should change this issue?
Try chmod 777 -R /var/www/html/laravel/ ,-R is recursive

Allow creation of folder on apache2 in Ubuntu Server

I'm creating a site which I'm going to host on an Ubuntu Server. I have a user registration form on my site, which creates a user and a folder for that user (if filled out correctly). The form in handled by PHP and I'm running Apache 2 on the server. When I run the code on my laptop the folder is created, but when I run the same code on the server the folder is not there. I guess that it has something to do with permisssion. How can I tell apache that the code should have write permission in a specific folder called "users" located in /var/www/mysite/public/users/ ???
Try using chmod command that provides folder permission. Something like
chmod 777 -R foldername
If security is not an issue I would suggest:
chmod 775 -R /var/www/
chown -R [your_user]:www-data /var/www/
So both apache2 (www-data) and you can edit folders and files inside /var/www (or /var/www/html if this is your folder).
Notice that this may have issues with git and other tools that capture folder permissions (eg with git you may commit files with 775).

cannot write to certain directory using CentOS distro

I have a script that will generate an image then upload it in a certain directory. The script works fine, however uploading it in the CentOS server, it won't work anymore. By debugging, I have found out that this is a permission denied issue. I am forced to chmod -R 777 certain_directory to make it work.
I am not convince with this, I can't set the directory ownership to www-data I'm used to when I am using Debian. Any workaround for this?
# egrep ^User /etc/httpd/conf/httpd.conf
User apache
So just chown the files to apache...

Categories