dpzp5127
2015-05-01 22:15
浏览 112
已采纳

linux(ubuntu)apache www文件夹访问问题

I'm a newbie in Linux, just installed ubuntu 14.04 and wanted to install WAMP (MAMP), I followed a youtube tutorial to install php5, apache2, mysql and phpmyadmin. Installed successfully both http://localhost and http://localhost/phpmyadmin works fine logged in successfully.

now I wanted to add some files and folders to apache www folder which is located at /var/www but cant create files or folders. I'm a Windows user where I usually keep all my PHP work in www folder.

I would like to know if there is a way to use any-other folder as www folder or how to create folders and files in that www folder. I reckon its permission issues, since being a newbie don't know how to fix that.. please help

Regards

图片转代码服务由CSDN问答提供 功能建议

我是Linux的新手,刚刚安装了ubuntu 14.04并想安装WAMP(MAMP),我跟着一个 youtube教程安装php5,apache2,mysql和phpmyadmin。 已成功安装 http:// localhost http:// localhost / phpmyadmin 可以正常登录成功。

现在我想要 将一些文件和文件夹添加到apache www文件夹,该文件夹位于 / var / www 但无法创建文件或文件夹。 我是一个Windows用户,我通常将我的所有PHP工作保存在www文件夹中。

我想知道是否有办法将任何其他文件夹用作www文件夹或如何 在该www文件夹中创建文件夹和文件。 我认为它的许可问题,因为作为一个新手不知道如何解决..请帮助

问候

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongzhen4180 2015-05-01 22:23
    已采纳

    Ubuntu 14.04 runs apache as user www-data, you can change to this user using the command in terminal (shell)

    sudo su 
    

    This will make you root and have access to /var/www directory, and you will be able to create files and directories. Say you had a directory of images containing img1.jpg, img2.jpg, etc. in say /home/user1/images

    as root you could

    sudo su                      <- change to the document folder
    cd /var/www                  <- change to the document folder
    cp /home/user1/images/ .     <- copy what you need to copy
    chown -r www-data images/    <- give the web server read/write permission to the folder / files
    

    which will let you do access the images via a browser via the url

    http://localhost/images/img1.jpg
    
    已采纳该答案
    打赏 评论
  • dongluxin6711 2015-05-01 22:25

    The reason is that apache runs under different user (given your distro most likely www-data), while /var/www belongs either to the user or root.

    So if you want to allow apache to write somewhere you have to give it permissions. Since it is not good practice to give apache full permission to your disk, usually you would have a special directory where it can upload data.

    For example creating directory /var/www/myProject/uploaded

    and then giving permission to all to write there

    chmod 777 /var/www/myProject/uploaded
    

    Alternatively you can change the owner/group with chown.

    打赏 评论

相关推荐 更多相似问题