Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php apache permissions - best practices [closed]

I have a codeigniter application which creates folders using php. The owner of any folders created via php is 'apache', however if I want to upload a folder via ftp the owner is my ftp username.

I had an issue with php (apache) not being able to modify a file inside a folder that was uploaded via ftp because of permissions. In the meantime I have added my ftpuser to the apache group and apache to the ftpuser group but was wondering if there is a better way?

like image 397
the-a-train Avatar asked Dec 31 '25 18:12

the-a-train


2 Answers

Generally what I do is chgrp any directory php will write to the group apache runs as (www on my server, could be apache on yours), chmod g+s . This will make any file created in that directory also owned by the web server group. If the default umask allows group write, this will solve your problem.

like image 111
ccandreva Avatar answered Jan 02 '26 11:01

ccandreva


The best practice is to only allow users to read/write files that they should.

In my web-apps, I have a data directory for the website, which I store all my dynamically generated data from the app.

Then I only give permission for the app to write to that directory, and nothing else.

like image 45
Petah Avatar answered Jan 02 '26 09:01

Petah