简体   繁体   English

在 /var/www/html/ 上使用 git 存储库

[英]Use a git repository on /var/www/html/

I am making a web tool and hosting this project on Github.我正在制作一个网络工具并在 Github 上托管这个项目。 I want to create a repository on my machine (running linux) being able to easily test it on local.我想在我的机器上创建一个存储库(运行 linux),以便能够在本地轻松测试它。

I can test it without problems on /var/www/html (already have apache and php set up), but I am having trouble creating a repository there.我可以在 /var/www/html 上测试它而没有问题(已经设置了 apache 和 php),但是我在那里创建存储库时遇到问题。 However, if I try to create the repo in ~/Documents/Github/PROJECT_NAME it works perfectly;但是,如果我尝试在 ~/Documents/Github/PROJECT_NAME 中创建存储库,它可以完美运行; but I can't test my project from there.但我无法从那里测试我的项目。

How can I create a repo inside /var/www/html where I can put my project files and run them locally without problems?如何在 /var/www/html 中创建一个存储库,我可以在其中放置我的项目文件并在本地运行它们而不会出现问题?

I tried to run sudo git init then sudo git clone git@github.com:xxx/xxx.git (that is how I clone my repo on ~/Documents/Github/PROJECT_NAME, so I have already exchanged SSH keys with Github) but it didn't work:我尝试运行sudo git init然后sudo git clone git@github.com:xxx/xxx.git (这就是我在 ~/Documents/Github/PROJECT_NAME 上克隆我的 repo 的方式,所以我已经与 Github 交换了 SSH 密钥)但是它没有用:

Cloning into 'PrerequisiteVisualizer'...克隆到“PrerequisiteVisualizer”...

Warning: Permanently added the RSA host key for IP address '192.30.252.129' to the list of known hosts.警告:已将 IP 地址“192.30.252.129”的 RSA 主机密钥永久添加到已知主机列表中。

Permission denied (publickey).权限被拒绝(公钥)。

fatal: Could not read from remote repository.致命:无法从远程存储库读取。

Please make sure you have the correct access rights and the repository exists.请确保您拥有正确的访问权限并且存储库存在。

EDIT: I am able to run without problems编辑:我可以毫无问题地运行

mkdir ~/Desktop/TESTING cd ~/Desktop/TESTING git init git clone git@github....

My question is similar to Attempting to use symbolic link for var/www/html but it still is different.我的问题类似于尝试对 var/www/html 使用符号链接,但它仍然不同。

EDIT2: I think I need to clarify why the thread I cited isnt what I am looking for. EDIT2:我想我需要澄清为什么我引用的线程不是我要找的。 I saw the solution proposed there but note that, as long as I understood the other thread, they created a directory in his home (~) and made it accessible locally using the per-user web directories.我看到了那里提出的解决方案,但请注意,只要我理解另一个线程,他们就会在他的家 (~) 中创建一个目录,并使用每个用户的 Web 目录在本地访问它。 But this is not what I want to do.但这不是我想做的。 I just want to "create a repo inside /var/www/html", not in anywhere else.我只想“在 /var/www/html 中创建一个 repo”,而不是在其他任何地方。

The problem isn't strictly with /var/www/html, it's with sudo.问题不完全在于 /var/www/html,而是在于 sudo。 If you use sudo to do git, you are running it as a different user, which doesn't have access to your private ssh credentials (nor should it have).如果您使用 sudo 执行 git,则您是以不同的用户身份运行它,该用户无权访问您的私人 ssh 凭据(也不应该访问)。

In the other thread you pointed to there's an explanation of per user www directories, which should be one way of solving your problem.您指出的另一个线程中,有对每个用户 www 目录的解释,这应该是解决问题的一种方法。 If it doesn't, you could amend the question with reasoning why it doesn't.如果没有,您可以修改问题并说明为什么没有。


Update: based on the discussion, you want all content within /var/www/html owned by the user operating git repository.更新:根据讨论,您希望 /var/www/html 中的所有内容归操作 git 存储库的用户所有。 That you should be able to do in the way proposed by @rogerovo in a comment to this answer:您应该能够按照@rogerovo 在对此答案的评论中提出的方式进行操作:

sudo chown -R _currentuser_:www-data /var/www/html && chmod -R g+sw /var/www/html

Permissions for /var/www/html folder needs to be changed. /var/www/html 文件夹的权限需要更改。 Kindly run this command sudo chmod o+w /var/www/html to give write access to everyone.请运行此命令sudo chmod o+w /var/www/html为每个人提供写访问权限。

Once run, you should be able to transfer files in /var/www/html folder.运行后,您应该能够传输 /var/www/html 文件夹中的文件。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM