I can't upload files to a web page through code igniter - php

I'm new in the use of code igniter, however I have been having a problem while trying to upload files to a certain directory.
You see, I've tested the page in localhost, and I have no problem in uploading files in that situation, however, whenever I try to run that on server I keep getting the message that:"the directory doesn't appear to be writable". If I change the directory privileges to 777, fixes the problem, however that is a bad practice while developing a web page, and I would like it to keep the privileges in 775 at the least.
I have also found out that the executing 'whoami' I get the username 'wwwrun' so, is it possible to change the configuration of code igniter so that it runs with an user that owns that directory?
I really hope you can help me with this problem since, I haven't found a clear solution since I don't know where to begin...

you change the permssion before code igniter uploads, the folder should be owned by wwwrun and maybe in the wwwrun group, Maybe in the coders group ?
When its chowned to wwwrun having permission 700 or 750 will be fine

Related

Strange error with folder permissions (mkdir)

I am running a nginx server and php5, but I am not able to get mkdir in php working. I always get a permission denied error.
The user, who is running nginx is www in group www, the same applies for php and my folder where I want to create a new one is also hold by www.
It only works when I set the folder permissions to 777, with 775 I can't get it working.
The curious thing is, when I try to create a folder in the terminal as www user it works without any issues.
Any help would be really appreciated, because I have been struggling with this error for 2 days.
That's probably because problem with PHP module configuration. You have to set correct user there, too.
Check this documentation.

What is the most secure way to create upload directories?

I have an image upload script. I ran into some trouble with permission errors so for the last little while the upload directory has had permissions 0777. Dangerous, I know.
For some reason, it was the only permission that would allow the files to upload. I have now realised that the reason a safer permission didn't work was because of the owner of the directory.
I've been creating my upload directories using FTP. I thought this would be okay. But from what I understand FTP and HTTP aren't in the same group?
I've started creating the directories using PHPs mkdir() allows me to set a safer permission that works with my script.
But before I possibly get into another bad habit. Can someone please confirm that this is the correct way to do it? Is there a better way?
The owner of the directory should be the user which runs your PHP script - on Ubuntu this would be www-data. Shortly, creating folders with PHP mkdir() is okay. Then you should set permissions. 0700 is the most secure but if other user needs to read from or write to this directory, you should add this user to the main group of user which runs your PHP script and set permissions to 0750 or 0770 respectively. On Ubuntu this group is also www-data.

assign permission to the directly using root level access in php

I am developing an application which is having 2 servers. The first one is Web Server, where I save my PHP files and another one is File Server where I am storing all the files uploaded by the user.
I want to assign the write permission to directory at runtime so that I can upload the file and after uploading the file I need to change its permission to its previous state.
When I tried chomod(FILE_PATH, 0755). It shows me an error. Assign write permission as root. I have the administrator level credentials of File Server.
What I want is to "Grant permission 777 to the directory by logging in as root at runtime"
Kindly help if there is any code sample available. Thanks in Advance.
You do NOT want to have your server logging in as root. Let me say that again. You really do NOT want your webserver to be logged on as root. If you did that, anyone that got control of PHP could do anything at all on the server. It is seriously unadvisable.
What you want to do is change the owner of the folder to either be the webserver, or assign it into the same group so that the webserver can happily change your folder options and the like.
You can use sudo chown username somedir to change the owner. This article might also help clear up permissions for you.
Edit: Try this blog post for a fairly good broad-ranging article on linux permissions.

Am I wrong to make directory executable?

I am writing a file upload using Zend_Form_Element_File(). I created a directory called users in the public directory. When I load the file, I got an error saying page is not found. I check the directory and saw that the permission is drwxr-xr-x. So I change the permission to drwxrw-rw- and load the page again. The page loads properly. But when I upload a file, it produces an error again. So I finally change the permission to drwxrwxrwx and everything runs properly.
My question is that am I doing the usual way that others are doing? I found it strange to make a directory executable.
Can someone explain whether I'm doing it correct? I am just learning Zend framework.
Directories must be executable if a program should be able to "enter" it. Entering a directory basically means accessing any file/directory below that directory.
Having "read" access to a folder allows you to list its contents - what "write" access does is pretty obvious.
However, for security reasons you should check if drwxrwx--- (770) is not sufficient; often your user and the webserver share a common group. If that's the case, there's no need to give any access to "world".
It would be even better to run your scripts as the same user as you - by using fastcgi that wouldn't be too hard, but if you are on shared hosting you usually do not have the necessary access to do this.
Typically when you set permissions on the directory it is so they cascade down to the files within via extended ACLS in the majority of cases. The issue that I see immediately is that you have granted world access which is a bad idea. The only user that needs permissions to the directory (700 at max) is going to be your web server. So I would revert security to be 700 asap.

PHP > mkdir path issues

I'm currently working on a website admin panel,
I added a form that adds clients to the database, what I want to do now, is to create folders for them via PHP.
So I tried to do that using the function: mkdir(),
The problem is, that when I tested the function on my "Xampp" server, it all worked just as i wanted it to.
But when I moved the file to the real host that I will use via FTP, and It just wont work the same..
ill try to explain whats wrong..:
mkdir('folderName'); //this will create a folder that i cant access through the FTP
mkdir('folderName', 0777); //creates a folder that i can access, but cant open other folders in it and cant change chmod permissions
I also need to create some nested folders for example:
mkdir('folderName/anotherFolder',0777,true); //this works on the host but again, the folders are not letting me change chmod permissions and cant create folders in them
in my xampp server i could create a few folders in a given path for example:
mkdir('folderName');
mkdir('folderName/one');
mkdir('folderName/two');
the above examples arent working on my host..
So yea sorry for writing so much, I just thought that you guys need to know those things..
Anyways, thanks in advance!
Try chgrp as well as chmod.
Other than that, the best solution in such ostensible FS situations is to do it via FTP. Major frameworks do this (including Joomla and Wordpress).
Probably you are not the owner of files/directories created by PHP script.

Categories