permission for var/www/html directory - php

I installed ubuntu server 14.04 then (apache,php and mysql).
I uploaded my website to /var/www/html and nuzip it and linked it to database.
When I request my ip in the browser i get the home page, but when click on any url in the site it returns 404 not found error - not from my website- but from the server.
I searched but problem not solved
this is what i tryed
chmod -R g+w /var/www/html
chown -R $user:$user /var/www/html/
chown -R www-data:www-data /var/www/html/
but non of this works.
any idea ?

If you are using Laravel, please keep in mind that you have to separate "public" folder and the app itself.
First of all, go to /var/www and create folder called "app".
Put everything in here excluding public folder.
Contents of public folder goes to /var/www/html.
Now, edit routes in /var/www/html/index.php
From __DIR__.'/../bootstrap/app.php to ../app/bootstrap/app.php
Do the same with other routes in here.
Don't forget to change the permissions. The easiest way would be to set it to 777 for the whole /var/www using sudo chmod -R 777 /var/www
Good luck.

I solved the problem by running this command
a2enmod rewrite
then restart apache server.
Thanks to everybody tryed to help me :)

Related

apache/php symlink 403 permission forbidden

I have my project sitting in: dev/php/project.
My system apache2 server folder is: /var/www/html/.
And my goal is to reach this address: localhost/project/file.php.
So I have created symlink in /var/www/html folder like so:
sudo ln -s dev/php/project /var/www/html/project
and after this if I try to open localhost/project url. I get 403 forbidden error. I searched alot and saw that others have had same issues. So I tried to follow how to fix guides and none of them helped.
All of the guides say that I should chmod the symlink, but when I try to excecute this command:
sudo chmod 0755 -R /var/www/html/*
or directly:
sudo chmod 0755 -R /var/www/html/project
I get:
chmod: cannot operate on dangling symlink '/var/www/html/project'
I have also tried to use other chmod modules ( dont know how to call them correctly, sorry) like 777, x+o, and everything I came across . I also tried to create symlink with one php file but the outcome was the same.
Can someone please help me understand what the problem is? I cant move forward because of this issue. I am ready to quickly respond to answers, questions.

can't upload file to wordpress

I move my wordpress website to my vps with Cpanel, after move every thing is working well, but my media option can't upload file to my library, I try to set permission for uploads folder and subfolders to 755,775 even 777 but media uploader get me this error :
The uploaded file could not be moved to wp-content/uploads/2016/10.
I try to solve my problem with set group and owner with terminal linux to my user,
> sudo chown -R username:group directory
> sudo chgrp -R username:group directory
but my problem not solved.
Edited :
I try to install "SuPHP" and my problem solved...
for more information see :
https://documentation.cpanel.net/display/EA/Apache+Module%3A+SuPHP
thanks smoqadam
I try to this :
chown -R nobody /home/<username>/public_html/wp-content/uploads/
and everything is OK...
First, I would strongly recommend not setting your permissions to 777. This is a serious security concern. The user wp-user does not exist by default on Ubuntu and is likely left over from the host you exported your site from. All your web files should be owned by www-data. Assuming your web root remains /var/www/html (the default on the WP one-click image) you can fix the ownership with:
chown -Rf www-data:www-data /var/www/html
If that doesn't work you can update the perminssions of the upload folder using the following command
chmod -R 755 /var/www/html/wp-content/uploads
Try this:
sudo chown -R www-data:www-data <path_to_your_web_root>
(If that still doesn't work, make sure the uploads folder etc. are not at 777 permission - you can use this for that purpose:
sudo chmod -R 755 <path_to_your_web_root> )
)

How to set root access for all files put inside my Apache2 root directory?

I am learning PHP at the moment on Linux. I have an Apache2 server running locally. Whenever I tried to save a PHP file into the root directory of Apache2 server ( /var/www/html/), I was told that permission denined.
So, I searched around and found that by default, the admininstartor do not have the root access unless explicitly request for it (like sudo su). I have also seen some posts which ask me to use gksu nautilus. However, my linux 14.04 LTS Ubuntu doesn't comes with it. (I know I can use apt-get gksu but at the moment, downloading it from internet is not an option).
Is there anyway that I can change the permission to my Apache2 server root directoy so that I can use any text editor to save/edit to that directory directly. Only the ways that do not need downloading stuffs from internet are feasiable for me at the moment.
For linux open the terminal with root login then go to the root folder and run the following command chmod 777 following is the example :-
To change all the directories to 777 (-rwxr-rwxr-rwxr):
find /opt/lampp/htdocs -type d -exec chmod 777 {} \;
To change all the files to 644 (-rwxr-rwxr--rwxr--):
find /opt/lampp/htdocs -type f -exec chmod 777 {} \;
If this will not work then try the following :-
Create a new group
groupadd webadmin
Add your users to the group
usermod -a -G webadmin user1
usermod -a -G webadmin user2
Change ownership of the sites directory
chown root:webadmin /var/www/html/
Change permissions of the sites directory
chmod 2775 /var/www/html/ -R
Now anybody can read the files (including the apache user) but only root and webadmin can modify their contents.
Hope this will help you in solving your problem.
You can set the DocumentRoot in your /etc/apache2/httpd.conf file to a place where Apache has write access. For example, you could set it to /tmp/www if you made a directory there. (If you still don't have access, you can always give everyone read access by running chmod a+r /tmp/www, but you should probably be fine.)
Obviously leaving your Apache Document Root as /tmp/www is a bad idea, so you can change it to something like /home/chris once you've got it working.
One important note: after you make a change like this, you must restart the Apache server. This can be done by running apachectl restart; ironically, you might have to have administrator rights in order to execute this (or even edit the config file in the first place), so make sure you prefix your edit & restart with sudo just in case.

Unable to create directory wp-content/uploads/2014/07. Is its parent directory writable by the server?

Hi anyone can help me for this issue , I have developed a site and it is hosted on my development server but now my client wants to move it to his own production server, and my client doesn't have access to his cpanel for this server. I only have the ftp access, so I have added his database in my own development server, while in development I used my amazon s3 for storing the images , when I push to production I loss the amazon plugin . I can't able to install the plugin , so I moved to upload once again to those images through WordPress, now I face this error while uploading an image : Unable to create directory wp-content/uploads/2014/07. Is its parent directory writable by the server? , and change the ftp file permission access to 755 and changed the uploads file permission to 777 , Still I am not able to upload the images, can some one help me for this issue.
This is a problem of the Apache permissions. I had this problem and i broke my mind for many days to understand what was happening.
The correct way (USE IT):
(the solution that i used, and worked)
You need to give Rewrite permissions to the Apache.
For Ubuntu:
Run via ssh: chown -R www-data:www-data /var/www/the/wordpress/directory
For Centos:
Run via ssh: chown -R apache.apache /var/www/the/wordpress/directory
The Wrong Way (I don't recommend it, but works...)
You can change the permissions to 777 in all the paths that Wordpress need to change. wp-content/plugins recursively on folders to solve install/update problems, and wp-content/uploads recursively on folders to solve upload media problems.
Never use it because you are giving permissions to anyone change your files. A open way for the crackers that don't like you.
run these command to provide proper file permissions
Add existing 'ubuntu' user to 'www-data' group
sudo usermod -a -G www-data ubuntu;
Set the ownership of the files/directories
sudo chown -R www-data:www-data /var/www/html/;
Set group ownership inheritance
sudo chmod g+s /var/www/html/;
Set the permissions of the files/directories
sudo find /var/www/html/ -type d -exec chmod 755 {} ;
sudo find /var/www/html/ -type f -exec chmod 644 {} ;
Give write permissions to the group (for editing files via FTP)
sudo chmod -R g+w /var/www/html/;

Allow creation of folder on apache2 in Ubuntu Server

I'm creating a site which I'm going to host on an Ubuntu Server. I have a user registration form on my site, which creates a user and a folder for that user (if filled out correctly). The form in handled by PHP and I'm running Apache 2 on the server. When I run the code on my laptop the folder is created, but when I run the same code on the server the folder is not there. I guess that it has something to do with permisssion. How can I tell apache that the code should have write permission in a specific folder called "users" located in /var/www/mysite/public/users/ ???
Try using chmod command that provides folder permission. Something like
chmod 777 -R foldername
If security is not an issue I would suggest:
chmod 775 -R /var/www/
chown -R [your_user]:www-data /var/www/
So both apache2 (www-data) and you can edit folders and files inside /var/www (or /var/www/html if this is your folder).
Notice that this may have issues with git and other tools that capture folder permissions (eg with git you may commit files with 775).

Categories