Wordpress + Heroku + PostgreSQL + Amazon S3 = Â¥0 / ç¡æã§ãµã¤ãéå¶
WordpressãHerokuã§éå¶ããã¨ä½ãã¨æ¥½ã ãªãã¨æã£ã¦ãã£ã¦ã¿ããã¿ãã ãã
ã§ãå®éã¯ãã£ããããã£ããããããæ¸ãã¦ãããªãã¨ç¢ºå®ã«å¿ããã
2015/06/01
Herokuã®æ°ãã©ã³çºè¡¨ã§18æéã ãç¡æã«ãªã£ã¦ãã¾ãã¾ããã
Herokuãç¡æã§ãªããªãæ¥ | Workabroad.jp
24æé稼åã¯$7ãããã¾ãã
ãã
ãã
2015/02/20追è¨
ãã¼ããªã³ã¯ãå¤æ´ãã¦ãããã°ããããã¨ã¾ãå
ã«æ»ãã¨ããç¾è±¡ãèµ·ããã¾ããã
mod rewriteã®è¨å®ãããã°ç´ãããã§ãã
http://blog.mah-lab.com/2013/05/01/wordpress-on-heroku/
ãã
ãã
2015/02/02追è¨
wp-configã®è¨å®ã足ããªãã£ãã®ã§ä¿®æ£
ãã
ãã
æåã¯èªåã§ãããããªã¨æã£ããã©ãéä¸ã§ãããã ããã®ã§ä»ã®äººã®åãåãããã¨ãããã¨ã«ã
2015å¹´1æç¾å¨ã§ã¯ Wordpress 4.1 ã«ãªã£ã¦ããã
wordpress-heroku
ãã¼ã«ã«éçºç°å¢
ã¾ãã¯ãã¼ã«ã«éçºç°å¢ã
é¢åã ãã©ä¸åãã£ã¦ãã¾ãã°å¾ã®ãããã¤ã¯æ¥½ãªã¯ãã
Rails + Heroku ã³ã³ããã¼ã·ã§ã³ãå¤ãããåãããã«ãããã¤ã§ããã®ã¯å¬ããã
- Vagrant ( CentOS6 + Apache )
- PostgreSQL
- Wordpress
ãã¦ã³ãã¼ããã¦ãã©ã«ãã®ååå¤ããã
1
2
$ git clone git://github.com/mhoofman/wordpress-heroku.git
$ mv wordpress-heroku my-wordpress
Git repository ãä½ã£ã¦ããªã¢ã¼ããç»é²ãã¾ãããã
Gitã®æµãã¯åã«Railsãã¼ã¸ã§ã³ã§æ¸ããã®ã§ãã¡ããåç
§ã
herokuã§Railsã¢ããªãå
¬éããæé ããã£ããä¸å¯§ã«ã | Workabroad.jp
PostgreSQL
Wordpressã¯æ®éMySQLã ãã©ããã£ãã®ã¬ãã¸ããªãããã¦ã³ãã¼ããããã®ã«ã¯æ¢ã«ãã©ã°ã¤ã³ãã¤ã³ã¹ãã¼ã«ãã¦ãã£ã¦ãPostgreSQLã使ããããã«ãªã£ã¦ããã
ãã©ã°ã¤ã³ã¯ãã¡ãã
WordPress ⺠PostgreSQL for WordPress (PG4WP) « WordPress Plugins
â»Wordpressã®ç®¡çç»é¢ããæä½ãããããªæ®éã®ãã©ã°ã¤ã³ã§ã¯ãªãã
ãªã®ã§ãPostgreSQLã®DBã¤ããã¾ãã
1
2
3
4
5
6
7
$ sudo -u postgres psql
DBä½æ
postgres=# create database my-wordpress owner yourname;
確èª
postgres=# \l
çµäº
postgres=# \q
Apacheã®è¨å®ã¨ç°å¢å¤æ°
æçµçã«Herokuã«ãããã¤ããã®ã§ãDBã®æ¥ç¶æ
å ±ãç°å¢å¤æ°ã«ç»é²ãã¦ããã
1ã¤ã®IPã§è¤æ°ã®ããã¸ã§ã¯ããéçºãã¦ããããVirtualHostã§åãæ¿ããã
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Apacheè¨å®ãã¡ã¤ã«ã®ç·¨é
$ sudo vi /etc/httpd/conf/httpd.conf
â
<VirtualHost *:80>
ServerName dev.yoursite.com
DocumentRoot "/var/www/html/my-wordpress"
setEnv WP_ENV development #å¿
è¦ã ã£ãã
setEnv WP_DB_URL xxxxxxxxxxxxxxxxxxxxxxxxxx
setEnv WP_DB_NAME xxxxxxxxx
setEnv WP_DB_USER xxxxxxxxx
setEnv WP_DB_PASSWORD xxxxxxxxx
</VirtualHost>
setEnvã§ç°å¢å¤æ°ãç»é²ãã¦ããã¦ã
PHPå´ã§ã¯ getenv('WP_DB_NAME')
ã®ããã«ä½¿ãã
DBã®URLã¯ãããªæ¸å¼ã
// postgres://USER_NAME:PASSWORD@HOST:5432/DB_NAME
ãã
Apacheèµ·å
1
2
$ service httpd start
$ service httpd restart èµ·åãã¦ããåèµ·å
ãã
ãã©ã¦ã¶ã§dev.yoursite.comã«ã¢ã¯ã»ã¹ããæã«ã
ãã®IPã«è¡ã£ã¦ãããå¿
è¦ãããããHostè¨å®ãããã
Mac使ã£ã¦ãã Hoster ã便å©ã
http://www.redwinder.com/macapp/hoster/
Wordpressã®è¨å®
å
ã»ã©è¿½å ããç°å¢å¤æ°ãè¨å®ãã¡ã¤ã«ã«åæ ãããã
WP_DB_HOSTã¯ãã¼ã«ã«ã ã¨ã ãããlocalhostãHerokuã ã¨DB追å ããæã«å¤ãåå¾ã§ããã
wp-config.php
php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
// ** Heroku Postgres settings - from Heroku Environment ** //
$db = parse_url(getenv('WP_DB_NAME'));
/** MySQL database username */
define('DB_USER', getenv('WP_DB_USER'));
/** MySQL database password */
define('DB_PASSWORD', getenv('WP_DB_PASSWORD'));
/** MySQL hostname */
define('DB_HOST', getenv('WP_DB_HOST'));
?>
ãã
çç¥ãã¾ããããã¡ããç°å¢å¤æ°ã«ãã¾ãããã
便å©ãªã¸ã§ãã¬ã¼ã¿ã¯ãã¡ãã
php
1
2
3
4
5
6
7
8
define('AUTH_KEY', 'xxxxxx');
define('SECURE_AUTH_KEY', 'xxxxxxxx');
define('LOGGED_IN_KEY', 'xxxxxxxx');
define('NONCE_KEY', 'xxxxxxxx');
define('AUTH_SALT', 'xxxxxxxx');
define('SECURE_AUTH_SALT', 'xxxxxxxx');
define('LOGGED_IN_SALT', 'xxxxxxxx');
define('NONCE_SALT', 'xxxxxxxx');
ããã
ã¡ãªã¿ã«ããã¼ã«ã«éçºç°å¢ã¨æ¬çªç°å¢ã®configãåããããã¨ãããã
ãããªæã¯ãããªæããç°å¢å¤æ° WP_ENV
ãã»ãããã¦ãããã¨ãå¿ããã«ã
herokuã®æ¹ã«ã¯ã heroku config:set WP_ENV=production
ã¨ãã¦ããã
åèï¼Multi Environment WordPress wp-config.php
php
1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
if ( getenv('WP_ENV') === "development" ) {
define('WP_HOME','http://dev.your_site.com');
define('WP_SITEURL','http://dev.your_site.com');
} elseif ( getenv('WP_ENV') === "production" ) {
define('WP_HOME','http://your_site.com');
define('WP_SITEURL','http://your_site.com');
}
?>
ãã
wp-config.php 13è¡ç®
$_ENV['DATABASE_URL']
ã getenv('WP_DB_NAME')
ã«å
¥ãæ¿ããã
php
1
2
3
4
5
6
<?php
if (preg_match('/localhost/', getenv('WP_DB_NAME'))) {
preg_match('/(.*)\/wp-.*\/(\w*\.php)+$/', $_SERVER['REQUEST_URI'], $path);
return ("http://" . $_SERVER['HTTP_HOST'] . $path[1]);
}
?>
ãã
ããã§ãã©ã¦ã¶ããã¢ã¯ã»ã¹ããã¨ãWordpressã®åæè¨å®ç»é¢ã表示ãããã¯ãã
ãã®ä¾ã§ã¯dev.my-wordpress.comã§ããï¼Hosterã®è¨å®ï¼
Amazon S3
Herokuãåæã«ãã¦ããã®ã§ãç»åã®ä¿åå
ãå¥ã«è¨ããå¿
è¦ãããã¾ãã
Railsã§ãã¤ããã£ã¦ããããã«Amazon S3ã«ä¿åãããã¨ããã§ãã
Bucket
Amason S3ã«ãã£ã¦ãé©å½ãªååã®Bucketãä½ã£ã¦ãã ããã
Bucket Policyã®è¨å®ããã¦ããã¾ãããã
Policyã®ãµã³ãã«ã¯ãã¡ãã®ãã¼ã¸ã§ã
https://docs.aws.amazon.com/AmazonS3/latest/dev/example-bucket-policies.html
Granting Read-Only Permission to an Anonymous User ã§ããã¨æãã¾ãã
ããã
IAM
Wordpressã«ç»åãã¢ãããã¼ããã権éãä¸ããªããã°ãããªãã®ã§ã
IAMã«è¡ã£ã¦é©å½ã«ã¦ã¼ã¶ã¼ãä½ã£ã¦ãS3ã«é¢ãã権éãä¸ãã¾ãã
Key 㨠Secret ãåå¾ã§ããããWordpresså
ã§ä½¿ãã®ã§ä¿åãã¦ããã¾ãããã
ãã
WP Read-Only
wordpress-herokuã«ã¯S3ã使ããã©ã°ã¤ã³ãäºãå
¥ã£ã¦ã¾ãã
â»ããã©ã«ãã§ã¯ã¢ã¯ãã£ãã§ãªãã®ã§ãPlugins / Installed Plugins ã«ãã£ã¦ONã«ããã
ãã©ã°ã¤ã³ã¯ãã¡ãã
WordPress ⺠WP Read-Only « WordPress Plugins
Settings / WPRO Setting ã§å
ã»ã©ã®Keyã¨Secretãå
¥åãããå®äºã
ã¡ãã£ã¨ããã£ãã®ããRegionã®é¸æã
ä½ããã®çç±ã§Sydneyã®Regionã¨ãã使ã£ã¦ããå ´åã¯ãWPROã®Regionã»ã¬ã¯ããªãã·ã§ã³ã«åå¨ãã¾ããã
ãã
ã ããèªåã§ä»ãå ããã
Regionä¸è¦§ã¯Amazonã®å
¬å¼ããã
http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
wpro.php 350è¡ç®ããã
php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<select name="wpro-aws-endpoint" id="wpro-aws-endpoint">
<?php
$aws_regions = array(
's3.amazonaws.com' => 'US East Region (Standard)',
's3-us-west-2.amazonaws.com' => 'US West (Oregon) Region',
's3-us-west-1.amazonaws.com' => 'US West (Northern California) Region',
's3-eu-west-1.amazonaws.com' => 'EU (Ireland) Region',
's3-ap-southeast-1.amazonaws.com' => 'Asia Pacific (Singapore) Region',
's3-ap-southeast-2.amazonaws.com' => 'Asia Pacific (Sydney) Region', //追å ãã
's3-ap-northeast-1.amazonaws.com' => 'Asia Pacific (Tokyo) Region',
's3-sa-east-1.amazonaws.com' => 'South America (Sao Paulo) Region'
);
// Endpoints comes from http://docs.amazonwebservices.com/general/latest/gr/rande.html
foreach ($aws_regions as $endpoint => $endpoint_name) {
echo ('<option value="' . $endpoint . '"');
if ($endpoint == get_option('wpro-aws-endpoint')) {
echo(' selected="selected"');
}
echo ('>' . $endpoint_name . '</option>');
}
?>
</select>
Herokuã®è¨å®
ãã¼ã«ã«ç°å¢ã§Wordpressãåãã ããã®ã§ã次ã¯Herokuã
æ®éã«ã¢ããªä½æãã¦ãAddonã追å ã
PostgreSQLã¨SendGridã使ãã¾ãã
PostgreSQLã®æ å ±ãHerokuã®ç°å¢è¨å®ã«ã»ããã
1
2
3
4
5
$ heroku config:set WP_DB_URL=xxxxxxx
$ heroku config:set WP_DB_NAME=xxxxxxx
$ heroku config:set WP_DB_USER=xxxxxxx
$ heroku config:set WP_DB_PASSWORD=xxxxxxx
$ heroku config:set WP_DB_HOST=xxxxxxx
Sendgridã®IDã¨ãã¹ã¯ã¼ããåå¾ã
1
2
3
4
$ heroku config
â
SENDGRID_PASSWORD: xxxxxxxx
SENDGRID_USERNAME: [email protected]
åå¾ã§ããããã¼ã«ã«ã®Wordpressã«æ»ã£ã¦ãSettings / SendGrid Settings ã«ä¿åãã¦ããã¾ãã
ä»åã¯ãã£ã¦ãªããã©Mandrillã§ããæ¹æ³ãè¦ã¤ããã
http://www.andrewgertig.com/2013/05/set-up-wordpress-on-heroku
Mandrillã®æ¹ãç¡æã§éããã¡ã¼ã«ã®æ°ã¯å¤ãã¯ãã
Composer
ãã®ã¾ã¾ãããã¤ãã¦ã確ãã«åããã ãã©ãç»åãã¢ãããã¼ãããæã«ããµã ãã¤ã«ç»åãçæãããªãããªãªã¸ãã«ç»åããä¿åãããªãã¦ãè¨äºã«æ¿å
¥ããã¨ãã§ãï¼ãã¦ãªãã¾ãã
ããã¯GDããªãããã
Wordpressã®ã«ã¼ãã« conposer.json ãã¤ãã£ã¦ãããã¤ããå¿
è¦ãããã
Herokuã®PHPæ¡å¼µãªã¹ãã¯ãã¡ãã
https://devcenter.heroku.com/articles/php-support
internal identifier ã« ext-
ãã¤ããã®ãã«ã¼ã«ãããã
composer.json
1
2
3
4
5
6
7
{
"require": {
"php": "~5.6.0",
"ext-gd": "*",
"ext-mbstring": "*"
}
}
Composerã¯ãã¡ã
https://getcomposer.org/
Herokuããã¥ã¡ã³ãã«ã¯ãã¼ã«ã«ã«ã¤ã³ãã¼ã«ãã¦ã©ãã®ããã®ã¨æ¸ãã¦ãããã©ã
composer.jsonãã«ã¼ãã«ç½®ãã¦ãããã¤ããã ãã§ä¸å¿åãã
ããã¾ãé¢ä¿ãªããã©ã
Resize images before upload ã¨ããWordpressã®ãã©ã°ã¤ã³ã¯çµæ§è¯ãã£ãããããã¢ãããã¼ãããåã«ç»åããªãµã¤ãºãã¦ãããã®ã§ãå¾
ã¡æéãæ©ããªãã6MBã®ç»åããµã¼ãã¼ã«éãå¿
è¦ãªãã¦ãªããããã
ãããã¤
ãã¼ã¦ããã£ã¨Herokuã«Pushãã¾ããã
ãã¼ã«ã«ã§Git commitãã¦ããã¦ã
1
$ git push heroku master
ãã¡ã¤ã«æ°å¤ãããæåã¯æéãããããã
ããã§Herokuã§Wordpressãåãã¨æãã¾ãã
S3ãå年度ç¡æã ããHerokuãPostgresSQL10000è¡ã¾ã§ç¡æã
ã«ã¹ã¿ã ãã¡ã¤ã³ã§éç¨ããå ´åã¯å¤å Route53 ã®æéãããããã©å
¨ç¶å¤§ãããã¨ãªãã
Herokuã®ã«ã¹ã¿ã ãã¡ã¤ã³ã®è¨å®ã¯ãã¡ãã
heroku 㧠ç¬èªãã¡ã¤ã³ã使ãéã®æåçãèãã | Workabroad.jp
ãªã«ãããµã¼ãã¼ãããã¾ãæèããªãã¦ããã®ã¯ç´ æµã ãã
åè
Herokuã«WorpPressãPostgreSQLã§æ§ç¯ãã
WordPressã®ããã°ãherokuã§ç«ã¡ä¸ãã¦ãä½ãã¡ãªããããã®ï¼ | mah365
ãã