{"id":133,"date":"2013-04-12T17:45:54","date_gmt":"2013-04-12T17:45:54","guid":{"rendered":"https:\/\/www.peopleperhour.com\/engineering\/?p=133"},"modified":"2013-04-12T17:45:54","modified_gmt":"2013-04-12T17:45:54","slug":"yiises-setup-guide","status":"publish","type":"post","link":"https:\/\/www.peopleperhour.com\/engineering\/2013\/04\/12\/yiises-setup-guide\/","title":{"rendered":"YiiSES Setup guide"},"content":{"rendered":"<p>We wanted to build a marketing email application (which we are calling &#8220;MailChap&#8221;) and since we are a Yii shop I figured before we started, we should try the <a href=\"http:\/\/www.yiiframework.com\/extension\/yiises\/\">YiiSES<\/a> module. Setup was a little tricky so I documented it here in case it&#8217;s useful to someone else.<\/p>\n<p>These instructions apply to a Ubuntu machine with a LAMP stack installed. For reference, we&#8217;re using a &#8220;m1.small&#8221; EC2 instance.<\/p>\n<h3 id=\"SetupYiiSES\">Set up YiiSES<\/h3>\n<ol>\n<li>Create the Apache document root:<br \/>\n<tt>sudo mkdir \/var\/www\/yiises;cd \/var\/www\/yiises<\/tt><\/li>\n<li>Clone the <a href=\"http:\/\/www.yiiframework.com\/wiki\/374\/yiiboilerplate-setup-a-professional-project-structure-in-seconds\/\">yiiboilerplate<\/a> repository: <tt>sudo git clone git:\/\/github.com\/clevertech\/YiiBoilerplate.git \/var\/www\/yiises<\/tt>\n<\/li>\n<li>Edit the config files to set Yii up with a mysql connection:\n<ol>\n<li><tt>sudo vim common\/config\/params-local.php<\/tt><br \/>\n<tt>        'db.name' =&gt; 'mailchap',<br \/>\n        'db.connectionString' =&gt; 'mysql:host=[your_db_url];dbname=yiises',<br \/>\n        'db.username' =&gt; 'mailchap_webapp',<br \/>\n        'db.password' =&gt; '[your_password]',<br \/>\n<\/tt><\/li>\n<li><tt>sudo vim console\/config\/main.php<\/tt> &#8211; uncomment db section.\n<\/li>\n<li><tt>sudo vim backend\/config\/main.php<\/tt> &#8211; uncomment frontend alias line, and db section.\n<\/li>\n<li><tt>sudo vim frontend\/config\/main.php<\/tt> &#8211; uncomment db section.\n<\/li>\n<\/ol>\n<\/li>\n<li>Run the script that &#8220;deploys&#8221; the environment that we call &#8220;local&#8221;: <tt>sudo .\/runpostdeploy local no-migrate<\/tt><\/li>\n<li>Run the yii migrations to create the users table: <tt>sudo .\/yiic migrate<\/tt><\/li>\n<li>Setup 2 DNS rules (e.g. using AWS Route53) for this app:\n<ol>\n<li>Make &#8220;yiises.yourdomain.com&#8221; a DNS Alias for the instance IP. Test it with by browsing to <a class=\"ext-link\" href=\"http:\/\/yiises.yourdomain.com\/\"><span class=\"icon\">\u200b<\/span>http:\/\/yiises.yourdomain.com\/<\/a><\/li>\n<li>Make &#8220;admin.yiises.yourdomain.com&#8221; a DNS Alias for the instance IP. Test it with by browsing to <a class=\"ext-link\" href=\"http:\/\/admin.yiises.yourdomain.com\/\"><span class=\"icon\">\u200b<\/span>http:\/\/admin.yiises.yourdomain.com\/<\/a><\/li>\n<\/ol>\n<\/li>\n<li>Set up Apache:\n<ol>\n<li><tt>sudo vim \/etc\/apache2\/sites-available\/yiises:<br \/>\n&lt;VirtualHost *:80&gt;<\/p>\n<p>  ServerName yiises.yourdomain.com<br \/>\n  DocumentRoot \/var\/www\/yiises\/frontend\/www<br \/>\n  AddDefaultCharset UTF-8<\/p>\n<p>  &lt;Directory \/var\/www\/yiises\/frontend\/www&gt;<br \/>\n    Options FollowSymLinks<br \/>\n  &lt;\/Directory&gt;<\/p>\n<p>  ErrorLog  \/var\/log\/apache2\/yiises-error.log<br \/>\n  CustomLog \/var\/log\/apache2\/yiises-access.log combined<br \/>\n&lt;\/VirtualHost&gt;<br \/>\n&lt;VirtualHost *:80&gt;<\/p>\n<p>  ServerName admin.yiises.yourdomain.com<br \/>\n  DocumentRoot \/var\/www\/yiises\/backend\/www<br \/>\n  AddDefaultCharset UTF-8<\/p>\n<p>  &lt;Directory \/var\/www\/yiises\/backend\/www&gt;<br \/>\n    Options FollowSymLinks<br \/>\n  &lt;\/Directory&gt;<\/p>\n<p>  ErrorLog  \/var\/log\/apache2\/yiises-error.log<br \/>\n  CustomLog \/var\/log\/apache2\/yiises-access.log combined<br \/>\n&lt;\/VirtualHost&gt;<br \/>\n<\/tt><\/li>\n<\/ol>\n<\/li>\n<li>Enable the rewrite module and the new vhost:<br \/>\n<tt>sudo a2enmod rewrite<br \/>\nsudo a2ensite yiises<br \/>\nsudo service apache2 reload<br \/>\n<\/tt><\/li>\n<li>Check it works: <a class=\"ext-link\" href=\"http:\/\/yiises.yourdomain.com\/\"><span class=\"icon\">\u200b<\/span>http:\/\/yiises.yourdomain.com\/<\/a> you should see:<br \/>\n<blockquote class=\"citation\">\n<p>\n<em>This is index view file&#8230;<\/em>\n<\/p>\n<\/blockquote>\n<\/li>\n<li>A less boring page should be the admin backend: <a href=\"http:\/\/admin.yiises.yourdomain.com\/\">http:\/\/admin.yiises.yourdomain.com\/<\/a><\/li>\n<li>Install the yiises module:\n<ol>\n<li><tt>cd \/var\/www\/yiises\/backend\/modules<\/tt><br \/>\n<tt>sudo wget https:\/\/github.com\/clevertech\/YiiSES\/archive\/master.zip<br \/>\nsudo unzip master.zip<br \/>\nsudo rm master.zip<br \/>\n<\/tt><\/li>\n<li>Rename to &#8220;ses&#8221;: <tt>sudo mv YiiSES-master ses<\/tt>\n<\/li>\n<li>Move a command from the module into the correct place: <tt>sudo cp ses\/commands\/CampaignCommand.php ..\/..\/console\/commands\/<\/tt><\/li>\n<li>Declare the module in the backend config<br \/>\n<tt>sudo vim backend\/config\/main-local.php<br \/>\nAdd:<br \/>\n        'modules' =&gt; array(<br \/>\n                'ses'=&gt;array('password'=&gt;'clevertech',),<br \/>\n        ),<br \/>\n<\/tt><\/li>\n<\/ol>\n<\/li>\n<li>Set the SES params that the module needs:\n<ol>\n<li>In the AWS SES console, Verify a email address.<\/li>\n<li>Setup a IAM user called &#8220;MailChap-app&#8221; and give it access to SES. Note down the creds for the next step.<\/li>\n<li>Add the creds to the config: <tt>sudo vim common\/config\/params-local.php<\/tt>:<br \/>\n<tt>'ses.aws.key'          =&gt;'[your-key]',<br \/>\n'ses.aws.secret'       =&gt;'[your-secret]',<br \/>\n'ses.aws.verifiedEmail'=&gt;'[your-email]',<br \/>\n'ses.aws.test.email'   =&gt;'[your-email]',<br \/>\n'ses.from.name'        =&gt;'MailChap App',<br \/>\n<\/tt><\/li>\n<\/ol>\n<\/li>\n<li>Run the migrations for yiises:\n<ol>\n<li>Move the migration from the module into the correct place: <tt>sudo cp ses\/migrations\/m120809_075915_ses_initial_migration.php ..\/..\/console\/migrations\/<\/tt>\n<\/li>\n<li>Edit the migration file so the <tt>subscribed<\/tt> field is added to the <tt>users<\/tt> table (because this is not in the default from the yiiboilerplate).\n<\/li>\n<li>Run the migration: <tt>sudo .\/yiic migrate<\/tt>\n<\/li>\n<\/ol>\n<\/li>\n<li>Hit <a class=\"ext-link\" href=\"http:\/\/admin.yiises.yourdomain.com\/ses\"><span class=\"icon\">\u200b<\/span>http:\/\/admin.yiises.yourdomain.com\/ses<\/a> &#8211; The password is as above &#8220;clevertech&#8221;\n<\/li>\n<li>Once you send some emails, you can view the sending stats at <a class=\"ext-link\" href=\"http:\/\/admin.yiises.yourdomain.com\/ses\/amazon\/manage\/\"><span class=\"icon\">\u200b<\/span>http:\/\/admin.yiises.yourdomain.com\/ses\/amazon\/manage\/<\/a>\n<\/li>\n<\/ol>\n<p>Phew! It&#8217;s not too hard, unless you never used <a href=\"http:\/\/www.yiiframework.com\/wiki\/374\/yiiboilerplate-setup-a-professional-project-structure-in-seconds\/\">yiiboilerplate<\/a> before (like me).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We wanted to build a marketing email application (which we are calling &#8220;MailChap&#8221;) and since we are a Yii shop I figured before we started, we should try the YiiSES module. Setup was a little tricky so I documented it here in case it&#8217;s useful&#8230;<\/p>\n","protected":false},"author":40,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[21],"tags":[38,22],"class_list":["post-133","post","type-post","status-publish","format-standard","hentry","category-aws","tag-aws","tag-ses"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2CA4w-29","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.peopleperhour.com\/engineering\/wp-json\/wp\/v2\/posts\/133","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.peopleperhour.com\/engineering\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.peopleperhour.com\/engineering\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.peopleperhour.com\/engineering\/wp-json\/wp\/v2\/users\/40"}],"replies":[{"embeddable":true,"href":"https:\/\/www.peopleperhour.com\/engineering\/wp-json\/wp\/v2\/comments?post=133"}],"version-history":[{"count":29,"href":"https:\/\/www.peopleperhour.com\/engineering\/wp-json\/wp\/v2\/posts\/133\/revisions"}],"predecessor-version":[{"id":162,"href":"https:\/\/www.peopleperhour.com\/engineering\/wp-json\/wp\/v2\/posts\/133\/revisions\/162"}],"wp:attachment":[{"href":"https:\/\/www.peopleperhour.com\/engineering\/wp-json\/wp\/v2\/media?parent=133"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.peopleperhour.com\/engineering\/wp-json\/wp\/v2\/categories?post=133"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.peopleperhour.com\/engineering\/wp-json\/wp\/v2\/tags?post=133"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}