Permission Denied cPanel or PHP file upload - php

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>

Related

PHP can't create file, permission denied

I am trying to run some PHP applications on CentOS powered server with apache and MySQL. My apps have to create files on server, but it always says that permission is denied to create a file.
Files are located in /var/www/html. I even tried setting 777 permission to html folder and html/*. I changed apache user and group to myuser, that exists, and restarted apache. I changed the ownership of html folder and all files inside to myuser. I even tried changing document root to /home/myuser/public_html
I tried this code to test write permission. File location is /var/www/html/index.php and /home/myuser/public_html/index.php
$handle = fopen("a.txt", "w");
fwrite($handle, "test");
fclose($handle);
I am just more than amazed by this problem. The same configuration works on my another Ubuntu server.
Some geniuses must be here, help me.
You need to allow you server user to do write operation on your directory, User the below command, If it is a multilevel directory use -R flag.
sudo chown www-data my-dir
Instead of manually giving permission you can try chmod($handle, 0777) within your code.

PHP will not run unless 644?

I am sub-contracted through a large data center that uses shared servers and cPanel. I create websites for their hosting clients.
Their configuration is off. When I upload files to the server through cPanel directories are given 775 permissions and PHP files are given 664 permissions.
Every time I upload an application I have to recursively change the file permissions of the PHP files from 664 to 644 or no PHP will execute and results in a 500 error.
This is particularly painful because as a sub-contractor I have to ask for temporary shell access every time I need to do this.
Obviously the problem is that the PHP files are being executed by the group, and 664 permissions do not allow execution.
I'm not too familiar with cPanel, and I'm unsure what is causing this problem. Is this a problem with the server, or with cPanel? How can I change the default upload permissions for cPanel?
for cpanel, both owner and group have to be the username of the cPanel user.
In a typical cPanel configuration, the root directory for the accounts is home. Depending on the size of the server, it could be home2/ or home3, etc.
chown -R username:username /home/username/public_html/path_to_files

Need to reset the file permission in plesk

I use the plesk panel to upload and download the files from the server , currently the httpdocs folder permission is being set to rwx r-x --- and when i try to access the folder then it does not allows me to access the folder from the FTP as well as from the plesk.
From the plesk though i get an error following error:
Unable to change directory to /httpdocs: filemng: opendir failed: Permission denied
System error 13: Permission denied
i need to change the folder permission for the httpdocs so that i can access the files in it.
i have tried to refer the KB parallel http://kb.sp.parallels.com/en/1528
but was confused in the sense that how could i change the permission. i am using windows PC , please guide me on this , thanks a lot.
I had the same problem, after i tried to install Magento from the Plesk application manager. I searched and got this link http://kb.odin.com/en/124519and did it exactly as the article instructed. domain.tld - it means the particular domain name with its extension, such as .com, .org, .net. Everything worked, in ftp and file manager i was able to access the files and folders.
Resolution
Run the commands below with superuser privileges to download the archived shell script.
Unzip it and execute, providing the needed domain name as an argument:
~# wget http://kb.sp.parallels.com/Attachments/23464/Attachments/recover_plesk_directories.zip
~# unzip recover_plesk_directories.zip
~# sh recover_plesk_directories.sh domain.tld
domain.tld = yourdomainname.com/org/net... whatever, i hope i had been more clear....
For each domain you shall run the command 'sh recover_plesk_directories.sh domain.tld' separately.
Login on server as root via ssh connection and restore default permissions for virtual host directories with help of following command:
/usr/local/psa/bin/repair --restore-vhosts-permissions

Permission with Apache on CENTOS

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

Configuration issue with apache over ftp

I have two folders where I can store my website (CentOS VPS):
/var/www/html/index.html
/home/admin/public_html/index.html
I can either store my web application in the first path, but I don't have FTP access to this folder. I can't see it at all when accessing my FTP with the admin account that I received from my service provider.
Or I can use the /home/admin/public_html. For this, I tried to:
change the Root directory in the httpd.conf file;
restart apache;
But this totally does not work!!
It continues to redirect me to the Apache is functioning normally message (from the /var/www/html/ path. why is this happening ?
Even if there is no direct solution, please help me into a direction to get this issue solved so I can continue with my actual work.
At work, I'm using Putty to connect through SSH, at home I use the Mac OSX terminal to access the VPS.
EDIT:
I called my service provider and he mentioned that it's better to leave the default folder (which is var/www/html).
In order to access the file from the client :
I created a link to /var/www from the public_html folder;
Gave permission rights to the www folder recursively;
Connected through SFTP instead of FTP to get access to the folder (normal FTP won't display the folder).
This appears to work rather well.
I suspect Apache doesn't have permission to access /home/admin/public_html. You would need at a minimum to give group read access to /home/admin and /home/admin/public_html to whatever group apache processes run as. Usually it's apache, httpd, or www group--check your /etc/passwd file).
If it's say, the 'apache' group:
chown :apache /home/admin/admin;
chmod g-w /home/admin/admin;
chown -R :apache /home/admin/public_html
If apache must write this directory
chown -R g+w /home/admin/public_html
Then set the group sticky bit (SGID bit) so on any directory from /home/admin/public_html on down (only directories). This will ensure any file created in them will have the same group ownership as the directory. Here's how you do that
find /home/admin/public_html -type d -print | while read i; do SAVEIFS=$IFS; IFS=$(echo -en "\n\b");chmod g+s $i; IFS=$SAVEIFS; done
In case someone else has this issue, have a look at /etc/apache2/sites-enabled
This is where Apache keeps all virtual hosts (This is used to host more than one website on a single ip address.) If you see a 000-default file here, this is usually mapped as the default entry or the site you get when you type in the servers ip address and usually points to /var/www.
PS
Have a look at http://www.virtualmin.com/ It's a opensource cpanel alternative that will provide you with a easy to use web based GUI for common web server related tasks including security, mail, databases and antivirus.
could be selinux related? Look for permission denied in your apache log and have a look in the selinux logs -- /var/log/secure on centos by my memory

Categories