Building Wordpress sites in the cloud
If you want to see the quickest demo possible, sign up for Cloud9 at c9.io, log in via GitHub and create an index.php file:
When you now click the 'Debug' button we spawn a shell version of PHP that echoes 'Hello world' back to you. To run it via Apache go to the run panel, select 'Apache+PHP' and re-click 'Debug'.
To install wordpress, we'll download the latest .zip file, unzip it. Then right click on the root folder in your tree and select 'Upload files' and choose the wordpress folder. Because the folder upload the files are in a seperate subfolder under root. Drag them to root and remove the 'wordpress' folder. Rename the 'wp-config-sample.php' to 'wp-config.php'.
Or do it via the terminal (CMD+T, CTRL+T)
1 2 3 4 5
$ wget http://wordpress.org/latest.tar.gz $ tar xzfv latest.tar.gz $ cp -r wordpress/* . $ rm latest.tar.gz $ rm -rf wordpress
When you now click 'Debug' and open the site, an error is thrown that no database connection could be made. That's correct, because we don't have a database server running on this machine. To make this fun we'll run Wordpress with PostgreSQL instead of MySQL. To get that to work we'll need to install the pg4wp plugin first. Follow the steps in the installation page to add the driver. We still have no connection, because no database was installed on the virtual machine in Cloud9 but now we've got something to get started with. Let's install Postgres first!
Cloud9 comes with a fully functional shell, that can be opened via 'View'->'Terminals'->'New Terminal'. This is just a SSH connection that you'd normally have to servers in your data center. That means that you have a limitless environment where you can install stuff (yes even vi!).
First we'll need to have the Postgres sources, then configure it, and finally make, install and start the server (and yes, this might take a while!).
1 2 3 4 5 6 7 8 9 10 11 12 13 14
$ cd .. $ mkdir pgsource $ cd pgsource # go into new directory $ wget http://ftp.postgresql.org/pub/source/v9.1.4/postgresql-9.1.4.tar.gz # grab source code $ tar xzfv postgresql-9.1.4.tar.gz # untar it $ cd postgresql-9.1.4 $ ./configure --without-readline --prefix=$PWD/../postgres # configure $ make $ make install # now to start it $ cd ~/pgsource/postgres/bin $ ./initdb -D ../data $ ./pg_ctl -D ../data -l logfile start $ ./createdb wp
With a running postgres instance (you can add the bin/ folder to your path if you like) which can be verified by running ./psql, and a created database we can now configure Wordpress to use this database. In 'wp-config.php' change the database settings to (don't have to restart debugging, changes are immediate!):
A running wordpress install, that you can use, modify and edit live from cloud9.
A hosted database solution (also for free users)
Because a local database won't hold when deploying this to a cloud service, we'll use the hosted postgres solution that Heroku offers. Select the dev plan (which is free) and create a database. Click on your new database to get the connection settings (hostname, username, password, etc.). To use this from within Cloud9 we can now load different configurations per environment, because on C9 the 'C9_PROJECT' environment variable is present.
If you want to migrate data from local -> hosted database, you can use the normal postgres tooling like pg_dump.
Deploying the application to Heroku
Now time to deploy this application to Heroku's hosted applications solution. Go to the 'Deploy' tab in Cloud9 (fourth tab with the balloon) and choose '+'.
Choose Heroku, log in with your fresh credentials and create a new app. Give it any name you like and click 'Add'. Because Cloud9 enforces a Procfile which is not required for PHP apps at the moment, we now need to manually push instead of via the UI. In the console (SHIFT+ESC) type:
1 2 3 4
$ git remote add heroku firstname.lastname@example.org:APPNAME.git $ git add . $ git commit -m "Initial commit" $ git push heroku master
And now your application has been deployed to the URL mentioned in the console message. For example: here is my brand new blog!
Updating the site
In case you want to edit the PHP files, just edit them in Cloud9; test them via the built in Apache process, and when you're ready do a 'git add' for the files you edited, commit them and push to heroku. Easy as that!
We're open source, so if you have cool improvements that you'd like to contribute, see the GitHub page. The VMs terminal stuff are only available on the hosted version, but you can roll your own by install c9 on your own cloud VM (f.e. on Amazon).
How is the current support for mobile devices like the iPad? It would be perfect if I could edit on the road all my stuff.
truegrit schreef op woensdag 11 juli 2012 @ 19:32:
I fiddled with c9 in the past for a bit, but i was unaware it had so much possibilities. I shall have to try it out some day
Great! We've made some incredible improvements in the past week, so I'd love to hear your feedback.Vold schreef op woensdag 11 juli 2012 @ 20:16:
I didn't knew you could deploy php apps to Heroku with such ease! I used cloud9 a while ago, but I thought it was too buggy back then, I looks way more stable now!
Tablet device support is not in there at the moment, can't give a timeline for it either a.t.m. But it's something that'll definitely land in the near future.How is the current support for mobile devices like the iPad? It would be perfect if I could edit on the road all my stuff.
Reageren is niet meer mogelijk