I have set up a Ubuntu LAMP server, and everything is working fine, however, I have a PHP script that allows the user to upload files to a directory within the www directory. The files saved via PHP are chmod 644.
How can I change the setting so that the files saved on the server are chmod 755 by default?
Educate yourself as to what a umask is.
Use the umask() function.
Related
I am using a php script from github to capture screenshot of a website. Its working fine in localhost. But not working after uploading the same code to my server (linux hosting). I tried uploading to multiple servers. None of them worked. No error codes are coming.
In the documentation, it says:
Make the bin executable chmod +x /var/www/html/screen/bin/phantomjs,
Make your folder writable
I am not sure what does that mean, so i set file permissions of whole files and folder to 777. Still not working
How did i upload to my server.
I uploaded the whole code to the server. Changed file permissions of all directories and files to 777 using FileZilla. I have attached a screenshot of
it.
I think it is still permissions issue, You need to set the proper permissions using putty.
1. Login using putty
2. Open root directory
3. Set permissions file and folder using this command
===> chmod -R 777 folder name
I am trying to upload a file through cpanel or wordpress admin panel, but cpanel shows permission denied and wordpress requires ftp access (probably for the same reason). What may be the cause of this?
The public_html directory contains files that were copied from public folder of another server via rsync to /home/somename and then I ran cp command to move these files to public_html. And now, all this is happening. Before cp, there was previous version of website that was working fine.
I'm using Centos 6.3 with Apache
Likely ownership issues.
For Centos 6 the default group for Apache is apache
Go to your webroot, and set the permissions to chown -R apache:apache *
Then make sure to set the permissions 0755
You may be better served by creating a new group and adding both yourself and apache to it. Then assigning the permissions to apache:<your new group>
I installed LAMP in my CENTOS and it all looks fine. In my www/html/ folder I placed my script and they all work fine, they can write/read everything. However everytime I create a folder and I put files inside it they cannot write, for example, if I use file_put_contents with PHP it does not work due the permission denied error.
Everytime it happens I need to chmod 777 to that folder and all the files inside. It's a great time loss.
Is there someway I configure the CENTOS so everytime I create a folder or upload a file it automatically will have read/write permission?
If you want new created folder/file to automatically have 777 permission, you must set umask to 000.
Ref: Setting the umask of the Apache user
when I 7zip a folder with php files on a PC and send it to my Mac, I can extract everything properly etc. But as soon as I turn on the localhost and want to open them in my browser, I get
"You don't have permission to access the requested object"
Even if I change permissions to read, write and execute for everyone, I cannot access the files in my browser.
What do I need to do?
Thanks
Dennis
Maybe in your Apache HTTPD config file/.htaccess there is a restriction.
Also, look the chmod of your file, even if the directory is chmod'ed 777.
Try testing on a new hello world php script in your project directory, you will see if you can execute it.
Make sure that the apache can read the files. For testing porpose you could run chmod 644 filename and also chmod 755 dirname.
If you played with the server configuration make sure that the server configuration allows the clients access to that path.
I just setup a LAMP development server and am still trouble-shooting some things. The server is installed on one computer and I use a Windows laptop to write my code and test the site via the web browser.
My file uploading script works in that JPEG image files are successfully uploaded to the server, but when I try to view the images in the web browser, permission is denied.
I check the permissions on the file via the server and they are 600. I can fix the issue by chmod 777 theimage.jpg, but this doesn't seem like a good solution at all.
Does the solution have something to do with Apache configuration? Or is there something else I should be doing.
Thank-you,
Mike
Update
To clarify, I am able to upload a JPEG file to /var/www/test/images, but am unable to view the image in the web browser after it has been uploaded. My script works on the production server (I am using Dreamhost). This leads me to believe that the issue is with the development server that I have just setup. Any feedback is greatly appreciated, even if it is just resources that I should read for better understanding the server setup.
You need to change the permissions on the folder containing the file, not just the file itself. Use sudo chmod and sudo chown on the directory that contains the file you want to access, then check to make sure the permissions where changed with the ls -rl command. The permissions used with chmod should be r and w and the directory should read -rw-r--r-- when the ls -rl command is used if the permissions have been changed correctly. Also, if you are still unclear about the specifics of how chmod and chown work check out this link and this link.
EDIT:
Type this:
sudo chmod -R 666 /var/www/test/images
Or this:
sudo chmod a=rw /var/www/test/images
... to do what you want to do. For more explanation see my latest comment entry below.
I'd say you probably are running PHP under a different uid than Apache.
You can:
Configure apache/PHP so that they run under the same uid
Upon file upload, use PHP tochange the permissions with the chmod function or change the umask associated with the PHP process so that the file gets the correct permissions in the first place
Access the images through PHP (readfile) -- not recommended for performance issues