简体   繁体   English

创建网站及其使用apache2服务器的文件时,在/ var / www / html中的权限被拒绝

[英]Permission denied inside /var/www/html when creating a website and it's files with the apache2 server

原子内部的屏幕截图 UPDATE** The screenshot is within atom, but when I navigate to the directory using the file explorer, and right click, the option to rename or create a new folder are restricted and I cannot click on them. 更新**屏幕快照位于原子内部,但是当我使用文件资源管理器导航到目录并单击鼠标右键时,重命名或创建新文件夹的选项受到限制,我无法单击它们。

I just finished setting up the LAMP stack on my fresh UBUNTU 18.04 installation. 我刚刚在新安装的UBUNTU 18.04上完成了LAMP堆栈的设置。 I have everything working, the default /var/www/html/index.html page from Apache2 is being served on localhost, no port forwarding or any unique domain name, i just wanna run this on my network from my computer for now. 我一切正常,Apache2的默认/var/www/html/index.html页面在localhost上提供,没有端口转发或任何唯一的域名,我现在想在我的计算机上的网络上运行它。

If there is a simple way to create multiple websites and easily choose which folder to serve than that's fine, but I want to serve just one website for now. 如果有一种简单的方法可以创建多个网站并轻松选择要提供的文件夹,那很好,但是我现在只想提供一个网站。

When I go to my /var/www/html folder and try to edit the index.html file it says permission denied. 当我转到/ var / www / html文件夹并尝试编辑index.html文件时,显示权限被拒绝。 What do I need to do in order to work inside this directory for the remaining time that I am building the website. 在构建网站的剩余时间内,我需要做什么才能在此目录中工作。 I am signed in as the root user on my system. 我已以系统上的root用户身份登录。

Also, if I do change permissions to allow me to work in this directory, what does it mean for people trying to access my server if it was available to the public. 另外,如果我确实更改了允许我在此目录中工作的权限,那么对于尝试访问我的服务器(如果公众可用)的人们来说意味着什么。 (RIGHT NOW JUST ON LOCALHOST). (现在就在本地主机上)。

Lemme know if you need more info or explanation thanks! 我知道您是否需要更多信息或解释,谢谢!

sudo chown -R $USER:$USER /var/www

this works, it changes the owner to my user instead of root user. 这有效,它将所有者更改为我的用户,而不是root用户。 I still don't understand because my user already had sudo rights and all those permissions. 我仍然不明白,因为我的用户已经具有sudo权限和所有这些权限。 It was the user I created during the ubuntu18.04 setup, so there shouldn't be an issue, or idk. 这是我在ubuntu18.04设置期间创建的用户,因此应该没有问题或idk。

The permission error is occurring because the folder does not have the rights and rights are reserved with different user. 发生权限错误,因为该文件夹不具有该权限,并且权限由其他用户保留。 (you can inspect this by doing ls -l folderName ) (您可以通过ls -l folderName进行检查)

The solution for your problem can be handled in different ways following are the few : 以下是几种解决问题的方法:

WAY1: WAY1:

  1. Find out who is running apache by running the command apachectl -S 通过运行命令apachectl -S找出谁正在运行apache
  2. Locate the user name (say www-data) 找到用户名(例如www-data)
  3. Change the ownership of your folder as chown -R www-data:www-data /var/www/html (this will allow only your apache to play with files) 将文件夹的所有权更改为chown -R www-data:www-data / var / www / html (这将仅允许您的Apache播放文件)
  4. Run the following command ln -s /var/www/html /home/username/html (this will create a soft link for your folder, where you can edit/delete/read which will reflect on your apache) 运行以下命令ln -s / var / www / html / home / username / html (这将为您的文件夹创建一个软链接,您可以在其中编辑/删除/读取将反映您的Apache的软链接)

WAY2: WAY2:

  1. goto /var/www/ 转到/ var / www /
  2. sudo chown -R www-data:${USER} html (Now both apache and your loged-in user will have rights to play with file). sudo chown -R www-data:$ {USER} html (现在,apache和您登录的用户都将有权使用文件)。

File ownership issues can be fixed at the command line by typing: 可以通过在命令行中键入以下内容来修复文件所有权问题:

sudo chmod 777 /var/www/html -R

One caveat from turnkeyLinux.com : 一个来自turnkeyLinux.com的警告:

Changing file permissions is a trade off (often increasing security reduces user-friendliness and/or usability). 更改文件权限是一个折衷(通常,提高安全性会降低用户友好性和/或可用性)。 For security 'best practice' only the folders that require write access by the webserver should be owned by the webserver. 为了实现安全性“最佳实践”,只有需要由Web服务器进行写访问的文件夹才应归Web服务器所有。 If your webserver has write access everywhere and your server is compromised it makes it easier to hack your WordPress install) but for ease of use giving the webserver ownership should resolve all your issues... 如果您的Web服务器到处都有写访问权限,并且服务器受到威胁,则可以更轻松地破解WordPress安装),但是为了易于使用,赋予Web服务器所有权应该可以解决所有问题...


This article on Understanding File Permissions was great, too. 关于理解文件权限的这篇文章也很棒。

Edit the file as root. 以根用户身份编辑文件。 Or better yet fix your permissions so you don't have to worry. 最好还是修正您的权限,这样您就不必担心。

This will help you. 这将为您提供帮助。

sudo chgrp -R www-data /var/www/html
sudo gpasswd -a username www-data
sudo chmod -R 777 /var/www/html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Laravel 错误:“/var/www/html/DocApp/storage/logs”中没有现有目录,并且它不可构建:权限被拒绝 - Laravel Error: There is no existing directory at "/var/www/html/DocApp/storage/logs" and its not buildable: Permission denied 在 Ubuntu 16.04 LTS 上的 var/www/html/ 中运行 Codeigniter 项目时找不到 404 页面? - 404 Page Not Found when run Codeigniter project inside var/www/html/ on Ubuntu 16.04 LTS? 在下载过程中,Apache2服务器/网站停止响应 - Apache2 server/website stops responding while download is in progress 在APACHE2中创建数据库,返回内部服务器错误 - Creating Database in APACHE2 returning internal server error 更改“ / var / lib / mysql /”的所有权:权限被拒绝 - changing ownership of '/var/lib/mysql/': Permission denied 在整个站点中浏览时,Apache2网站不会更改默认URL - Apache2 Website Won't Change Default URL When Navigating Throughout the Site 从Ubuntu中的MySQL Workbench启动MySQL Server时权限被拒绝 - Permission denied when starting MySQL Server from MySQL Workbench in Ubuntu 网站繁忙时如何停止apache2崩溃? - How do I stop apache2 crashing when the website gets busy? MySQL Server启动权限被拒绝 - MySQL Server start permission denied 为什么apache2服务器和mysql无法在XAMPP中启动? - why apache2 server and mysql is not starting in XAMPP?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM