17

I am making a web tool and hosting this project on Github. I want to create a repository on my machine (running linux) being able to easily test it on local.

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. However, if I try to create the repo in ~/Documents/Github/PROJECT_NAME it works perfectly; 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?

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:

Cloning into 'PrerequisiteVisualizer'...

Warning: Permanently added the RSA host key for IP address '192.30.252.129' to the list of known hosts.

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.

EDIT2: I think I need to clarify why the thread I cited isnt what I am looking for. 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. But this is not what I want to do. I just want to "create a repo inside /var/www/html", not in anywhere else.

Community
  • 1
  • 1
Xaphanius
  • 610
  • 2
  • 7
  • 19
  • 1
    This seems like a basic authentication problem. It looks like maybe whatever account your using for the `clone` operation doesn't have access to the appropriate private key. – larsks Jul 25 '15 at 22:41
  • does git init & git clone work anywhere else, either, with those commands? I don't see anything that would be /var/www specific, just user account specific that stems from using sudo. It seems to be basic issue with setting up ssh agent/ssh key for that account. – eis Jul 25 '15 at 22:54
  • also, why would you first use git init without sudo and then git clone with sudo? – eis Jul 25 '15 at 22:56
  • @eis See my edit. Also, sorry for missing the first sudo, I typed it on the terminal but missed it here. – Xaphanius Jul 25 '15 at 23:30
  • @downvoters why downvotting the question? Could you at least post a comment here explaining why is it a bad question? -.- – Xaphanius Jul 26 '15 at 03:28

2 Answers2

36

The problem isn't strictly with /var/www/html, it's with 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).

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. 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. That you should be able to do in the way proposed by @rogerovo in a comment to this answer:

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

Community
  • 1
  • 1
eis
  • 51,991
  • 13
  • 150
  • 199
  • 7
    this is right. one way to quickfix it `sudo chown -R _currentuser_:www-data /var/www/html && chmod -R g+sw /var/www/html` now it should be possible using `git` without the sudos – rogerovo Jul 26 '15 at 08:46
  • @eis "The problem isn't strictly with /var/www/html, it's with sudo." that might help me. I will check it when I get home. Creating a directory outside /var/www/html and make it accessible locally using the per-user web directories seems to be indeed is one way of solving it. However, I want to just create the repo inside /var/www/html/, which I think it isnt the case in that thread. – Xaphanius Jul 27 '15 at 13:46
  • @Xaphanius you still need to think who do you want to own that repo, sudo user or git user? And who do you want to assign the owner of /var/www/html? That needs to be decided first. – eis Jul 27 '15 at 13:48
  • @eis I want the git user to own the repo. But I don't know who should I choose to be the owner of /var/www/html. – Xaphanius Jul 27 '15 at 13:49
  • @Xaphanius so where will the repo reside, directly at /var/www/html or /var/www/html/reponame ? Will there be other folders or will the whole site be just about the single repo? – eis Jul 27 '15 at 13:51
  • @eis /var/www/html/reponame. This site will be completely inside the repo; but I might want -in the future- create another site inside /var/www/html/second_repo and so on... – Xaphanius Jul 27 '15 at 13:55
  • @Xaphanius would that second_repo be in the owner of the same user still if you choose to do that, or of another user? – eis Jul 27 '15 at 14:05
  • @eis So far I plan for both of them have the same owner. – Xaphanius Jul 27 '15 at 14:10
  • @Xaphanius ok. Then I don't think there's a reason not to go with quickfix proposed by rogerovo in the first comment. – eis Jul 27 '15 at 15:20
  • @eis I will try that when I get home. But thanks for helping. :) – Xaphanius Jul 27 '15 at 16:43
  • @eis, to avoid problem with permissions in `/var/www/html`, could be a good idea having your git repo in your `home` folder and then creating a symlink in `/var/www/html` which points to your git repo in `home`? – floatingpurr Dec 31 '17 at 15:43
  • @floatingpurr I don't see how that changes anything, you would still need to change the ownership/permissions on your git repo files – eis Jan 01 '18 at 15:03
  • What about ownership best practices for /var/www/? – Yohan W. Dunon Jun 19 '21 at 22:35
  • 1
    @YohanW.Dunon that's really a topic that deserves a thread of its own. Here's one such a thread: https://stackoverflow.com/questions/28918996/proper-owner-of-var-www-html – eis Jun 20 '21 at 06:57
2

Permissions for /var/www/html folder needs to be changed. Kindly run this command sudo chmod o+w /var/www/html to give write access to everyone.

Once run, you should be able to transfer files in /var/www/html folder.