Is it ok to assume /tmp folder writable by PHP/Apache on any unix system?
I'm making a script and want to save cache in the tmp folder and want to know whether that can cause problems.
It should be OK. /tmp is made for everyone to use. But be careful, it also means that anyone can read your files if you don't set specific permissions!
If you are unsure, make your installation script check the /tmp folder and make it possible for the user to configure another temp location. This is probably the best bet anyway because different users have different needs. Consider for example a user with load-balanced servers; she might want to use a folder which is shared between all her hosts.
You can not rely on /tmp folder as in some variations of linux, it is auto cleaned after some time, it would be best for your application to have a local tmp folder inside the app, which you manage yourself.
Related
I am trying to install Joomla 3.2 using the host provided by my university. So, I have available one mysql database with the username and pass and the ftp username and pass to transfer data, only. That is, no Cpanel installed or ssh available.
If I extract the file Joomla_3.2.0-Stable-Full_Package.zip and ftp the contents on the website, the owner of these files/folders is user "ftp_username". I can continue to install Joomla only if I set-up the ftp layer.
This works, except I get from time to time messages like --> JFTP: :rename: Bad response Rename failed More specifically I get this message when using kunena.
Moreover, I read online that the FTP layer shouldn't be used normally. Also, the tmp/cache/logs create permission problems.
If I remove the ftp layer (by editing the configuration.php) then I cannot modify anything since Joomla cannot modify the files (owned by ftp_username). Of course, I could change all permissions to 777, but that would be suicide...
I found a post explaining a bit the situation I'm here! Especially the advice on using "chmod 4770" is feasible but I don't know about how secure it is (haven't tried it).
Anyone has an idea how I can make this work?
cross-posted here
Thanks in advance
I found a way to bypass this problem. Not worth it if you have an alternative provider!
I installed joomla with ftp layer
I installed Extplorer plugin
Used plugin to upload Joomla_3.2.0-Stable-Full_Package.zip on the server. Now the file is owned by the apache user.
Deleted all the (joomla installation) files on the server except the zip file
Uploaded a php script to unzip the file using php (http://php.net/manual/en/ziparchive.open.php). The installation folders/files are now owned by apache user
Reinstall Joomla without the ftp layer.
I guess I could have used some php uploader script instead of steps 1-4, but I already had Joomla installed with the ftp layer.
That's it. Up and working. If you have an alternative provider, don't bother.
It seems to me that the hosting option provided by the university may be too restrictive to work for pretty much any CMS. You need to be able to chmod and potentially chown all your files in bulk so as to avoid insanity.
There may be an FTP program out there that will chmod your files as you are uploading them. If your group is www-data or whatever group apache needs, then you can 775 your folders and 664 your files; you should be good to go.
I have a CMS which i made with PHP and i want to add some self updating features to it.
A self updating system can be a complex and tedious thing, i know that, but that's a whole different story. The bottom line is is that i end up creating new PHP files, editting existing ones with new code and probably deleting some PHP files when an update happends.
I know how to read, write and delete files in PHP, but this almost always gives me problems on a Linux server when i don't chmod the folder with an FTP client first to 0777.
I also know PHP has chmod and chown functions. But most of the times these functions don't work for me either. Mainly because all the PHP files are uploaded through FTP which gives the rights to write to files and folders to the FTP group (or something like that).
I also have a Wordpress blog installed on a Linux server, but for some reason this Wordpress site has no trouble updating itself. I assume it does the same things i said; create, update and delete certain files. But none of the Wordpress sites i ever worked with complained that it couldn't update itself because of the folder/file permissions.
So i'm guessing Wordpress uses a smart way to change folder permissions when needed. I just couldn't figure out how.
So basically my question is, what is the best way to give PHP permissions to chmod files and folders on a Linux system? How does a system like Wordpress handle this?
You can set the folder to 0777 which would give PHP the capability to create files inside of it. You can also chown the folder to www-data or whatever your copy of PHP runs as...
I'm a bit baffled here. But it might just be my lack of experience.
I have setup PHP DSO (mod_php) and my server runs smoothly and stable. The issue is, though, that in order to run php with includes and everything, I had to set all user account files (/home/*/public_html/*) owner to nobody:nobody.
This introduces two questions for me:
- Is this really necessary? I'd rather have them user:user
- What about FTP? If I upload files using FTP, they're owned by user:user so they can't be included in another php file (throws errors). Files that are owned by nobody:nobody can't be modified through ftp..
FYI: I also have SuEXEC enabled. Should I disable this?
FYI2: I know I could set all permissions to 777, but that's just wrong.
Thanks a lot!
Ordinary "nobody" should only read executing files, and write/own only files that can be changed by php. Most files owner should be your ftp user.
Bad practice to keep php rights to change executable files.
Also if "nobody" has rights to run as root it provides php (and therefore users) all his rights.
I am working on a web app that needs read/write access to an SQLite database file. As I understand it, the parent folder needs to be set to 777 in order to be able to open the database with PHP (source).
What are the recommended file permissions for the .db file itself? Bear in mind that I need to be able to overwrite the file with PHP as well.
Furthermore, are there any security risks with the database if its parent is 777? The folder is created by PHP. I'm just trying to make sure I can get work done without creating security risks.
Thanks!
You should have Apache (the web server) own the folder.
Or maybe create a group like www-dev consisting of MySQL and Apache and then set the folder group to www-dev and the permissions to 770 .
Just don't make the folder public with 777 - specially on a shared server.
After years of using chmod 777 to solve PHP write permission woes, I want to know the proper way of solving the problem.
I have a website on my server owned by user1 in group user1. There is a folder in this website called uploads.
Normally to get writing with PHP to work, I have to chmod this folder to 777. But I obviously recognise this is dangerous and incorrect, and I want to setup the permissions properly to minimise risk.
From my limited knowledge, I see two options,
I chown the uploads folder so that it's owned by apache. This way, I can just use the default permissions and apache can happily write to the folder.
I add a second group to apache of user1. I then give write permission to the owner and group on uploads, which should allow apache to write to uploads?
My question is, what is the best approach? Is it one of the above or something completely different?
If the best solution is #1, how can user1 also write to uploads over SFTP as that solution will not let them?
In my current company, we set the apache group to the group that owns the folder, so you just need to do chmod 770 on the folder to give permissions to that particular group to do funny stuff on that folder.
However you still to remember to protect your application from malicious user, as the PHP script being run, if sufficiently insecure, can still do damage to the folder.
If it's your own server, the best way is to set the folder to the group apache uses, e.g. with chgrp www-data on debian (might be different on other systems). You usually have to do this as root or at least as a user who has access to his own and www-data group. If your user has access to www-data group, this might be a cool feature for you since its easy then to read and maybe write/move the files.
In this case, use 770 as the file permission and ensure that files created by php get this permission (either explicitly after creating with chmod or with umask before creation. See php manual for both.)
If you are working on a shared hosting environment, the only clean solution I know is mod_suexec, but I don't know many hosters that enable it. If this is not available I know only the way you do know, working with 777. Often, your home directory in shared environments have a longer random string in the path name so that others should not find your directory and therefore can't access your files. But this is not real security.. ;-)
Good luck
Michel