Learn how to connect a repository on github.gatech.edu to a vhost on one of our servers (requires at least version 5 of OpenSSH on our server).
Make SSH Keys on Server
- On your server, become the superuser (
sudo su
). - Become the apache user (
su -s /bin/bash - apache
).- As the apache user, change to the home directory (
cd ~
) - Find where that home directory is located (
pwd
) (example: /usr/share/httpd)
- As the apache user, change to the home directory (
- Go back to root user by typing command (
exit
). - Create a folder in which to store SSH keys (
mkdir /usr/share/httpd/.ssh
). - Create an SSH key pair on your server in the (/usr/share/httpd/.ssh) .ssh directory (
ssh-keygen -b 4096 -t rsa
), and name the key for the virtual host (example: /usr/share/httpd/.ssh/support). Don't enter passwords just hit enter both times. Create a config file (
touch /usr/share/httpd/.ssh/config
) and add this code inside it (only final line needed if only a single virtualhost on this VM):# support.cc Host support HostName github.gatech.edu PreferredAuthentications publickey IdentityFile /usr/share/httpd/.ssh/support
- Change the .ssh folder permissions (
chmod 700 /usr/share/httpd/.ssh
). - Change the .ssh folder ownership for use by apache (
chown -R apache:apache /usr/share/httpd/.ssh)
. - Change ownership of the already-existing vhost's folder for use by apache (
chown -R apache:apache /var/www/vhosts/support.cc.gatech.edu)
or if not multisite (chown -R apache:apache /var/www/html
). - You may need to restart apache after changing the .ssh config. (
systemctl restart httpd
) Add your key:
ssh-add /usr/share/httpd/.ssh/support
You might need to startssh-agent
before you run thessh-add
command:eval `ssh-agent -s` ssh-add
- Copy the contents of the public key into your Text Editor of choice (
cat /usr/share/httpd/.ssh/support.pub
).
Add Deploy Key on Github
- Create your private repo on github.gatech.edu, under the appropriate departmental Team (example: https://github.gatech.edu/CC-TSO-WebDev). Do not add any files (not even a README).
- Within your repo, click the Settings tab.
- Choose "Deploy keys" in the left side menu, and click on "Add deploy key"
- Give a descriptive title, like "Scouter server public key".
- Paste the public key you copied from your server into the "Key" area.
- If this is your initial copying of the repo from the server TO github, check "Allow write access", so that you can push to this github repo from your server.
- If you already have the initial copy of your files pulled from the server, you need to delete the old key and make a new one that does NOT allow write access (to improve our security setup).
- Click "Add key".
Connect your Server to Github
- Make sure git is running (
git --version
). - Become the apache user (
su -s /bin/bash - apache
).
Existing Server Repository
If this vhost on your server already has a git repo initialized, follow these steps:
- Change to your vhost's or html folder (
cd /var/www/vhosts/support.cc.gatech.edu
) or html folder (cd /var/www/html
). - Use ssh to add the github repo as its origin, including the "Host" you created in the .ssh/config file as the url so that the server uses the correct ssh key to connect (
git remote add origin git@support:CC-TSO-WebDev/support.git
). [if only single virtualhost on VM, usegit@github.gatech.edu:CC-TSO-WebDev/support.git
] - Push your server's repo to github (
git push -u origin master
). - Check the repo on github to make sure you see the commits from your server.
New Server Repository
If this vhost on your server does not yet have a git repo initialized, follow these steps:
- Change to the directory above your vhost (
cd /var/www/vhosts
). - Use ssh to copy the repo from to your server, including the "Host" you created in the .ssh/config file as the url so that the server uses the correct ssh key to connect (
git clone git@support:CC-TSO-WebDev/support.git support.cc.gatech.edu
).[if only single virtualhost on VM, usegit@github.gatech.edu:CC-TSO-WebDev/support.git support.cc.gatech.edu
] - Change to your vhost's folder (
cd /var/www/vhosts/support.cc.gatech.edu
). - Check the repo on your server to make sure you see the commits from github (
git log -n 1
).
Firewalls for Github.com
You may need to open the firewalls to allow an off-campus connection to github.com.
Customize .gitignore file
For a Drupal 7 site, add these lines to the repo's .gitignore file (as they should not be version controlled):
- sites/*/files
- sites/*/private
- sites/*/settings.php
Configure protected master branch on Github (Under construction section)
Since you will be connecting the repo to a Production site, you need to protect the master branch on github, so that all changes pushed to it must go through an approval process before being merged into the master/production branch.
Set crontab to do a git pull as the apache user (Under construction section)
Example (run every 4 hours):0 */4 * * * cd /var/www/vhosts/support.cc.gatech.edu && git pull origin master >> /dev/null
Change File Permissions (Under construction section)
Often, the file and directory permissions on the server differ from your local development environment. You will need a cron job or automatic git-accompanying command so that, whenever it pulls updates from the remote repository, files and directories receive the correct ownership and permissions for the server.
For a Drupal 7 site, the defaults should be:
- user and group = apache:apache
- most directories = 755
- most files = 644
- not version controlled, so set it once and forget it:
- settings.php file = 444
- /sites/*/files = 777 (directory)
- /sites/*/files/* = 666 (files)
Repository default settings
Details will go here.