Creating a wordpress project in the webroot is something which is a really static task. And when you have done that task several times you really fed up with it. That’s why I thought “Why not automate this task?”.
I started out thinking about doing a complete solution with django, but decided to just do a quick bash script which gets executed by a php script which is situated in a htpasswd protected folder.
Here’s a basic description for the algorithm:
So here’s what the bash script looks like:
#!/bin/bash
function quit {
echo "Usage: $0 'path' 'projectname' 'uid/gid'"
exit
}
if [ -z "$1" ]; then
quit
else
httpRoot="$1"
fi
if [ -z "$2" ]; then
quit
else
projectName="$2"
fi
if [ -z "$3" ]; then
quit
else
userGroup="$3"
fi
echo "Downloading latest wordpress... "
wget http://wordpress.org/latest.tar.gz
echo "Unpacking... "
tar -xf latest.tar.gz
mkdir $httpRoot/$projectName -p
cp wordpress/* $httpRoot/$projectName -R
sudo rm latest.tar.gz wordpress -rf
chown "$3:$3" $httpRoot/$projectName -R
echo "Wordpress project created!"
Really simple and straight-forward. The script it executed in the terminal like this:
sudo sh create-project.sh /srv/http test.paralyzed.se 33
Where the first argument is my webroot, the second is the name of what I want the project to be called and third is my http uid.
When you want to use with php just use the exec function:
exec("sudo sh create-project.sh /srv/http test.paralyzed.se 33");
A really simple way to save some minutes of your work day (and sanity). And also a practical example of not trying to reinvent the wheel and how to be efficient. Why spend a couple of hours creating a complete solution in django when you can do it with a little bash and php scripting.