Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use a git repository on /var/www/html/

Tags:

git

linux

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 [email protected]: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.

like image 915
Xaphanius Avatar asked Jul 25 '15 22:07

Xaphanius


People also ask

How do I open a Git repository in my browser?

Type git open to open the repo website (GitHub, GitLab, Bitbucket) in your browser.

Where is var www html?

You need to find what the root of the server (for the virtual host if hosting multiple sites) is. This is specified with DocumentRoot - so go to the Apache config files (normally in /etc/Apache or /etc/apache2 or /etc/httpd and look for that directive. /var/www/html is the typical/default location.


2 Answers

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

like image 101
eis Avatar answered Oct 07 '22 04:10

eis


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.

like image 35
Moosa Sharieff Avatar answered Oct 07 '22 05:10

Moosa Sharieff