PHP Deployment with Dropbox

Deploying files over sFTP or scp is boring and takes a lot of time. Using git with commit-hooks to initiate the deployment process is comfortable, but there is a solution that's even faster:

Deploy your server(s) with a Dropbox!


Here we go, first create a new Dropbox account:

Then install the Dropbox client on your Desktop (if you haven't done yet):
Delete the example content in your local Dropbox folder:

Next install the Dropbox client on your server. Dropbox packages for Linux can be found here.
I'm using a 32bit version with my Ubuntu Server VM. Execute the following commands on the shell (as root):

chown www-data:www-data /var/www
su - www-data -c bash
wget -qO - "https://www.dropbox.com/download?plat=lnx.x86" | tar xzf -
# or: wget -qO - "https://www.dropbox.com/download?plat=lnx.x86_64" | tar xzf -
.dropbox-dist/dropboxd
> This client is not linked to any account...
> Please visit https://www.dropbox.com/cli_link?host_id=d4b6c6b6bac2b
> 4b35619067a04b9751f&cl=en_US to link this machine.

Copy the URL given to your browser and confirm the action with your password:
Then we get:

> Client successfully linked, Welcome Thomas!
^C
ls -lisa
> ...
> 401534 4 drwx------ 3 www-data www-data 4096 Jul 10 02:33 .dropbox
> 401628 4 drwx------ 3 www-data www-data 4096 Jul 10 02:33 Dropbox
> 400700 4 drwxr-xr-x 4 www-data www-data 4096 Jun 14 03:40 .dropbox-dist

Now let's make the Dropbox client start automatically:

exit
# we are root again
echo "start-stop-daemon --start --background --chuid www-data --exec /var/www/.dropbox-dist/dropboxd" >/etc/init.d/dropbox
chmod +x /etc/init.d/dropbox
update-rc.d dropbox defaults

# start dropbox daemon
/etc/init.d/dropbox

# change Apache's document_root from /var/www to the Dropbox folder
find /etc/apache2 -type f -exec sed -i "s#/var/www#/var/www/Dropbox#g" {} \;

# protect cache folders
echo -e "\n<Directorymatch /\.>\nOrder deny,allow\nDeny from all\n</Directorymatch>" >>/etc/apache2/conf.d/security
/etc/init.d/apache2 restart

Then create a index.php in your local Dropbox folder:

Check the results on the server:

ls -lisa /var/www/Dropbox/
> 400788 4 -rw-r--r-- 1 www-data www-data 29 Jul 10 03:56 index.php
And finally:

What about security and traceability?

That's the weak point, a this should have never happened thing already happened to Dropbox. Also Dropbox relies on Amazon S3, so there might be elements in the chain that can break. If security is critical to your business, don't deploy with Dropbox!
Compared to git, there is no detailed changelog indicating who changed what, why and when. But you can put your git repository in your Dropbox folder to get these features.

What about memory usage of Dropbox?

On 32bit, you can calculate about 20 MB.

Comments

Popular posts from this blog

How to construct a B+ tree with example

How to show only month and year fields in android Date-picker?

Visitor Counter Script Using PHP