Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set the Apache htdocs/subfolder as GIT working dir

Tags:

git

apache

htdocs

I have just started trying to learn Git and I have got a little stuck. We are using Github to hold our "stable" project but I am having trouble working with the repo.

I want to know if its possible to use a local webservers htdocs/[projectname] as the working directory - this way I could clone the repo from github, work on it on the local server ( so it works as the application should allowing me to test everything i write properly ) and then stage -> commit from there.

I am working on a Mac using the MAMP environment. The application is a PHP based CMS. We are holding it on Github on a private repository. Currently Git seems to be using /Users/Ben/Core-CMS as the working dir but this makes it very hard to test things out - it would be much better if the working dir was inside the apache htdocs dir

I bought Pro Git but I am having a very hard time learning the concepts of git - I have purposely avoided using the GUI's as I wish to learn the inner workings of Git properly before I start 'cheating'!

like image 274
Ben Duffin Avatar asked Oct 26 '11 11:10

Ben Duffin


People also ask

How do I turn an existing folder into a git repository?

git init Existing Folder For an existing project to become a Git repository, navigate into the targeted root directory. Then, run git init . Or, you can create a new repository in a directory in your current path. Use git init <directory> and specify which directory to turn into a Git repository.

How do you change the current working directory to the location where you want the cloned directory?

Go to the current directory where you want the cloned directory to be added. To do this, input cd and add your folder location. You can add the folder location by dragging the folder to Git bash.

How do I clone a git repository to Htdocs?

Click the "Clone repository" link or use the "Start → Clone repository… ​" menu item. In the resulting "Clone" dialog box, enter the clone URL obtained in the first step. Set the destination directory to the htdocs\ subdirectory of your XAMPP installation directory (typically, C:\xampp).


2 Answers

If you have the permission to write in the htdocs dir, just move /Users/Ben/Core-CMS to htdocs/Core-CMS and access it at http://localhost/Core-CMS.

If you cannot write in the htdocs dir, I'd create /Users/Ben/web, put my projects in there and tell apache to serve from there. To tell apache to look in /Users/Ben/web to serve your projects, look for the following line in your apache conf:

DocumentRoot /path/to/htdocs

and replace it with:

DodumentRoot /Users/Ben/web
like image 75
Benoit Garret Avatar answered Sep 18 '22 11:09

Benoit Garret


This should not be a problem. I'm doing this all the time.

Switch to your public directory and run:

git clone REPO_URL NAME_OF_DIR_TO_CLONE_TO

first.

The dir where you clone a git repository must not exist.

You just need a ssh key authorized to push your changes from the repository to github and git installed on the server (or in your client if you have mounted everything to your local machine).

Then you do you commit which is just local and if you are done you may push your changes to github.

Another way would be to make the webserver use your working directory as its DocumentRoot.

I hope I didn't miss your problem here ;)

like image 39
Hikaru-Shindo Avatar answered Sep 20 '22 11:09

Hikaru-Shindo