You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: _posts/2014-07-22-how-to-setup-ghost-on-elastic-beanstalk.md
+49-48
Original file line number
Diff line number
Diff line change
@@ -21,10 +21,10 @@ To get started, you will need access and familiarity with the following AWS tool
21
21
5. EBS - for ephemeral storage
22
22
6. IAM - to allow access to mount EBS volumes
23
23
24
-
###Setup Simple Email Service
24
+
###Setup Simple Email Service
25
25
The first step in this process is to get yourself setup with SES. This will be your blogs email mechanism and will allow you to track things like bounces, complaints and successes all from with the AWS console. Now, to be honest, you could just use your GMail account or any other SMTP server you access to. However, if you're planning on making your blog a success - getting the stats on bounces and complaints is worth setting up SES.
26
26
27
-
####Setup
27
+
####Setup
28
28
1. Created a Verified Email
29
29
1. Log into the AWS console and select the SES service from the menu
30
30
2. Under the "Verified Senders" heading on the left navigation, click "Email Addresses"
@@ -41,10 +41,10 @@ The first step in this process is to get yourself setup with SES. This will be y
41
41
1. If you don't already have production access to send email via SES, you'll need to request it. From the SES Dashboard, click the "Request Production Access" button at the top of the screen.
42
42
2. This will take you to a support screen to request a "Service Limit Increase". Fill out the form with accurate information and submit it. They will review your request and either approve it or contact you with any questions.
43
43
44
-
###Setup Persistent Storage
44
+
###Setup Persistent Storage
45
45
By default, Ghost stores images and other data within the `content` directory. However, since we're using Elastic Beanstalk, if your instance becomes unhealthy, AWS will kill it - and take that `content` directory with it. To get around this, we're going to use a combination of EBS and ebextension configs to mount persistent storage and symlink those directories over to it. To get started we'll need to create an EBS volume.
46
46
47
-
####Create an EBS Volume
47
+
####Create an EBS Volume
48
48
1. From the EC2 console, click the `volumes` link on the left navigation.
49
49
2. Click the `Create Volume` button.
50
50
3. Follow the wizard to create a volume
@@ -59,7 +59,7 @@ Now you have a volume, however, this is basically the equivalent of adding a dri
59
59
3. Run `sudo mkfs -t ext4 device_name` swapping out `device_name` for that of your particular device.
60
60
4. Logout of the shell and unmount the volume from that instance. If you created that instance for this step, now is a good time to terminate the instance as well.
61
61
62
-
####Create an IAM User
62
+
####Create an IAM User
63
63
In order to allow our scripts to mount the EBS volume, we will need to create an IAM user and grant it the specific permissions needed to accomplish this.
64
64
65
65
1. From the IAM Console, click the `Users` link on the left navigation
@@ -85,26 +85,26 @@ In order to allow our scripts to mount the EBS volume, we will need to create an
85
85
15. Click the `Add Statement`
86
86
87
87
88
-
###Prepare Ghost for Installation
88
+
###Prepare Ghost for Installation
89
89
Based on our configuration within AWS, we need to make some minor tweaks to our Ghost codebase before we can begin the installation.
90
90
91
-
####Download Ghost
91
+
####Download Ghost
92
92
1. Down load a copy of Ghost from the [Ghost download page](https://ghost.org/download/)
93
93
2. Unzip it somewhere convenient for you to access it
94
94
95
-
####Modify the Default Node.js HTTP Port
95
+
####Modify the Default Node.js HTTP Port
96
96
In order to get node working in Beanstalk, you will need to ensure it using the correct port: `8081`. This is the port used by Elastic Beanstalks HTTP nGinx web server.
97
97
98
98
1. From within the Ghost directory, create a copy of `config.example.js` and name it `config.js`.
99
99
2. Edit the `server` section of the file and change the port reference from `2368` to `8081` in both the "Development" and "Production" sections of the file.
100
100
101
-
#####Modify the Default URL
101
+
#####Modify the Default URL
102
102
In order to actually use this as a production instance, you will need to update the `config.js` file to reflect your desired url for your blog.
103
103
104
104
1. Edit `config.js` and update the `url` value in both the `development` and `production` sections of the file to reflect the correct url
105
105
2. Save the file.
106
106
107
-
####Ensure the Proper Node.js Version
107
+
####Ensure the Proper Node.js Version
108
108
Ghost is built to run on Node.js version `0.10.*`, but Beanstalk will default to `0.8.*`. To ensure that your Beanstalk Environment provisions with the proper version, we will need to instruct it to via EB's "[ebextensions](http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers.html)" functionality.
109
109
110
110
1. In the root of your ghost directory (the one with "content" and "core"), create a new folder called `.ebextensions`.
@@ -117,7 +117,7 @@ Ghost is built to run on Node.js version `0.10.*`, but Beanstalk will default to
117
117
118
118
This config will get executed during the provisioning of your environment and ensure that your Node.js server starts up with the correct version that Ghost needs.
119
119
120
-
####Configure the EBS Mount
120
+
####Configure the EBS Mount
121
121
As we have the EBS volume and user permissions created, we need to setup another extensions config script that will attach the volume at boot. To do this, we will use an undocumented post-deploy hook that will run the script after the application has been deployed. This is essential as this depends on symbolic links that point `/var/app/current/content/data` and `/var/app/current/content/images` to `/var/app/data/` where we will mount our ebs volume.
122
122
123
123
1. Create another file in your `.ebextensions` folder called `01_mount_volumes.config` and put the following into it:
@@ -176,44 +176,43 @@ Be sure to update it with the following information:
176
176
177
177
Also, if you copy and pasted the script from above, it may be a good idea to paste it into a [YAML validator](http://yamllint.com/) to ensure the format is good; things like an extra `tab` will cause all kinds of headaches.
178
178
179
-
####MySQL RDS Configuration
179
+
####MySQL RDS Configuration
180
180
1. Edit the `config.js` file
181
-
1. Under both the `development` and `production` sections of the config:
3. Edit `package.json` to remove the Sqlite requirements.
208
206
1. Under the `dependencies` section delete the line for Sqlite.
209
207
2. Save and close the file.
210
208
211
209
212
-
####Configure the SMTP Settings for SES
210
+
####Configure the SMTP Settings for SES
213
211
1. Edit `config.js`
214
212
2. Delete the commented mail section under Development and Production. Replace it with the following:
215
213
216
-
mail: {
214
+
```
215
+
mail: {
217
216
transport: 'SMTP',
218
217
host: 'YOUR-SES-SERVER-NAME',
219
218
options: {
@@ -225,19 +224,20 @@ Also, if you copy and pasted the script from above, it may be a good idea to pas
225
224
}
226
225
}
227
226
}
227
+
```
228
228
3. Be sure to replace the following sections with your SES information
229
229
1. Host - replace this with the "Server Name" listed on the SES Consoles "SMTP Settings" page. Mine was `email-smtp.us-west-2.amazonaws.com`, but yours will vary based on the region you configured SES in.
230
230
2. user and pass - these will be found in the `credentials.csv` that you downloaded during the SES setup above.
231
231
4. Save the file and close it.
232
232
233
-
####Package it all up
233
+
####Package it all up
234
234
Now that the necessary config has been done, we need to zip up the directory and get it;ready for uploading to Elastic Beanstalk.
235
235
236
236
To do this:
237
237
238
238
1. Create a zip of your ghost installation. You will want the configuration files and the ghost `core` and `content` folders to be at the root level of the zip.
239
239
240
-
###Setup and Deploy to Elastic Beanstalk
240
+
###Setup and Deploy to Elastic Beanstalk
241
241
Now that you have all the preliminary work done, we can go ahead and start setting up our hosting.
242
242
243
243
1. From the Elastic Beanstalk Console, click the `Create a New Application` button
@@ -275,10 +275,10 @@ Now sit back and wait. It will take about 20 minutes for your RDS instance to co
275
275
276
276
You will note that the URL does not match the one you put in your `config.js` though. Instead, the url will resemble something along the lines of `my-app-env.elasticbeanstalk.com`. This is expected. To use your own domain name, you will need to create a DNS CNAME the points your domain to the Elastic Beanstalk URL. Instructions on this will vary based how you manage your DNS Service. I recommend using CloudFlare, detailed below.
277
277
278
-
###Next Steps
278
+
###Next Steps
279
279
So now that you have your blog up and running, you could just stop there. However, if you really plan on **blogging**, you should consider doing some additional steps to protect your blog from hackers, make it go faster and let it scale - for when it become really popluar.
280
280
281
-
####CloudFlare
281
+
####CloudFlare
282
282
For those of you who aren't familiar with [Cloudflare](http://www.cloudflare.com), its a great - *free* - service to add on top of any site that helps speed it up, keep it safe and reduce load.
283
283
284
284
Note: CloudFlare replaces your current DNS service, so you'll need access to your domain registrar to update your name servers.
@@ -289,20 +289,21 @@ Here is a high-level overview of some of its benefits:
289
289
2.**Overhead**. If the bulk of your content is static, then the majority of your traffic will be served by the caches. This means your server will only see cache refreshes or dynamic content requests and you can size your instances smaller than if they had to server it all. And we all know smaller instances cost less!
290
290
2.**Security**. As all traffic routes through them, they scan it for known threats and block them before they reach your servers. This is a huge deal as protecting your site from being hacked will help ensure a happy blogging experience for both you and your readers.
291
291
292
-
####Centralized Storage
292
+
####Centralized Storage
293
293
One of the downsides to Elastic Beanstalk is that the storage is not persistent and its not shared. We solved this for a single instance environment using our second EBS volume for our content directory. However, if you scale your site up beyond a single instance, this won't work. As this affects one of our goals of scaling with demand, this is definitely no bueno. But have no fear, using [S3FS](https://code.google.com/p/s3fs/wiki/FuseOverAmazon), you can mount an S3 bucket as your content directory. This works *pretty well* - so long as you don't use AWS's US-EAST-1 region - and will allow your site to scale to multiple instances without issue. If the load of your site demands, I would highly reccomend doing this.
294
294
295
-
####Monitoring and Logging
295
+
####Monitoring and Logging
296
296
As with any production-level environment, its always a good practice to setup proper monitoring, alerts and logging. Elastic Beanstalk make this quite straight-forward as you get basic infrastructure monitoring out of the box. I would recommend taking some time to setup the basic thresholds and alerts to notify you of any issues that may arise. You can also enable CloudWatch Logging through an ebextensions config that will send all your system logs to CloudWatch where you can create custom alerts based on events within your logs. [Here is a good walkthrough of the process](http://aws.amazon.com/blogs/aws/cloudwatch-log-service/).
297
297
298
298
Couple these with Google Analytics within your theme or through CloudFlare and you'll have everything you need to monitor traffic and performance for your blog.
299
299
300
-
###Conclusion
300
+
###Conclusion
301
301
If everything went correctly, you should now have a stable, durable blogging environment that you can grow with your demand. I hope you found this walkthrough useful. If anything, its a great way to exercise your knowledge of the AWS stack and its many useful services.
302
302
303
303
If you have any questions or suggestions, feel free to use the comments below or hit me up via [Twitter](http://twitter.com/boringgeek).
304
304
305
-
####Sources:
305
+
#### Sources:
306
+
306
307
-[Six Steps to Deploy Ghost to AWS Elastic Beanstalk](http://blogs.aws.amazon.com/application-management/post/Tx37ALIK2KLNIVC/Six-Steps-to-Deploy-Ghost-to-AWS-Elastic-Beanstalk)
0 commit comments