Sunday 30 May 2010

Using git to deploy code to remote server

I am developing a web application locally (at my laptop). I am using git to version my code. Now, I wish to deploy it to my virtual server (obviously, at a remote location).

Suppose I start from scratch. I usually keep my webpage code in /var/www/my_domain and at the same location in my web server.

The first thing I have to do is to create a bare git repo in my remote machine. Usually, in my home directory. I log into your remote machine and do (thanks to Caius) as follows:

mkdir git_my_domain
cd git_my_domain
git init --bare
git --bare update-server-info
git config core.worktree /var/www/my_domain
git config core.bare false
git config receive.denycurrentbranch ignore
cat > hooks/post-receive
#!/bin/sh
git checkout -f
^D
chmod +x hooks/post-receive

Then, at my local machine, I go to /var/www/my_domain and create a local git repository and add the remote repository I created before as a remote git repository:

mkdir /var/www/my_domain
cd /var/www/my_domain
git init
git remote add vps ssh://username@12.12.12.12[:port]/path/to/git_my_domain

Now I can add files to /var/www/my_domain, commit changes and then deploy automatically typing

git push vps master

Tuesday 25 May 2010

Permalink issue in Wordpress

As I tried to activate permalinks in Wordpress on Apache, I got 404 errors (page not found) after following the instructions. The problem was related to my default Apache configuration file.

Wordpress relies on Apache's mod_rewrite module for the URL conversion. As you define your conversion rules, it creates a custom .htaccess file that indicates Apache how to rewrite your URLs.

But there is a directive at the Apache configuration file that prevents Apache from reading your .htaccess file explicitly: AllowOverride.

In particular, within my directory section, I had: 

Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all


Changed it to

Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all


and rocked!