Tuesday, July 10, 2012

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.

No comments:

Post a Comment

Labels

performance (23) benchmark (6) MySQL (5) architecture (5) coding style (5) memory usage (5) HHVM (4) C++ (3) Java (3) Javascript (3) MVC (3) SQL (3) abstraction layer (3) framework (3) maintenance (3) Go (2) Golang (2) HTML5 (2) ORM (2) PDF (2) Slim (2) Symfony (2) Zend Framework (2) Zephir (2) firewall (2) log files (2) loops (2) quality (2) real-time (2) scrum (2) streaming (2) AOP (1) Apache (1) Arrays (1) C (1) DDoS (1) Deployment (1) DoS (1) Dropbox (1) HTML to PDF (1) HipHop (1) OCR (1) OOP (1) Objects (1) PDO (1) PHP extension (1) PhantomJS (1) SPL (1) SQLite (1) Server-Sent Events (1) Silex (1) Smarty (1) SplFixedArray (1) Unicode (1) V8 (1) analytics (1) annotations (1) apc (1) archiving (1) autoloading (1) awk (1) caching (1) code quality (1) column store (1) common mistakes (1) configuration (1) controller (1) decisions (1) design patterns (1) disk space (1) dynamic routing (1) file cache (1) garbage collector (1) good developer (1) html2pdf (1) internationalization (1) invoice (1) just-in-time compiler (1) kiss (1) knockd (1) legacy code (1) legacy systems (1) logtop (1) memcache (1) memcached (1) micro framework (1) ncat (1) node.js (1) openssh (1) pfff (1) php7 (1) phpng (1) procedure models (1) ramdisk (1) recursion (1) refactoring (1) references (1) regular expressions (1) search (1) security (1) sgrep (1) shm (1) sorting (1) spatch (1) ssh (1) strange behavior (1) swig (1) template engine (1) threads (1) translation (1) ubuntu (1) ufw (1) web server (1) whois (1)