0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

gnu social + heroku

Last updated at Posted at 2019-04-01

gnu social on heroku.

herokuでgnu socialを動かします。動いた環境を記録します。

heroku info

src : https://git.gnu.io/dansup/gnu-social/tree/composer-autoloading, 75488c2335866b3e6e9ad15df5abd7d7f3a00a97

$ git clone https://git.gnu.io/dansup/gnu-social
$ git checkout composer-autoloading
# git reset --hard 75488c2335866b3e6e9ad15df5abd7d7f3a00a97

stack : heroku-18

buildpack : https://github.com/heroku/heroku-buildpack-php

buildpack-version : aba6e847a9208ce86f98f534007283fe39faadd2

$ heroku buildpacks:set https://github.com/heroku/heroku-buildpack-php#v153 -a $APP_NAME

Procfile : web: vendor/bin/heroku-php-apache2

addons(DB) : cleardb:ignite

$ heroku addons:add cleardb:ignite -a $APP_NAME

example

$ git clone https://git.gnu.io/dansup/gnu-social
$ cd !$:t
$ git checkout composer-autoloading

$ php -v
7.3

$ vim composer.json
{
  "require": {
    "ext-pgsql": "*",
    "ext-gd": "*",
    "ext-intl": "*",
    "php": "^7.3.0",
    "illuminate/contracts": "*",
    "illuminate/support": "*",
    "ramsey/uuid": "^3.0",
    "ezyang/htmlpurifier": "^4.10",
    "psy/psysh": "^0.8.17"
  }

$ composer update

$ heroku create $APP_NAME
$ heroku buildpacks:add https://github.com/heroku/heroku-buildpack-php -a $APP_NAME
$ heroku addons:add cleardb:ignite -a $APP_NAME
$ heroku config -a $APP_NAME

$ vim Profile
web: vendor/bin/heroku-php-apache2

$ heroku git:remote -a $APP_NAME
$ git add .
$ git commit -m "first"
$ git push heroku master

# 次に、dockerを使って、DBにアクセスする。ついでに、そこで作成されたconfig.phpを取得する、config.phpの位置情報を適切に保存するため、これはdockerから実行するのが望ましい
$ open -a Docker
$ sudo docker run -p 8000:80 rudism/gnu-social /root/start
$ open -a Google\ Chrome http://localhost:8000/install.php

# ブラウザで開いた/install.phpの設定は、以下の値を参考に設定する
# `/install.php`をhttpで実行する必要がある。
# DBなどの情報をheroku configから取得する
# example : mysql://A:B@example.com/C
# optionである?,=,trueとかの末尾の部分はいらない
# 	host : example.com
# 	DB name : C
# 	user : A
# 	password : B
# $config['site']['path'] = false; 
# $config['site']['ssl'] = 'never'; 
# $config['site']['fancy'] = false;

# 初期設定が完了したらlocalhost:8000で一度、/index.php/well-known/host-metaを確認して、投稿し、/index.php/well-known/webfinger?resourece=acct:user@localhost:8000を確認しておくといいかもしれません

# config.phpを取得する
$ sudo docker cp `sudo docker ps -q`:/var/www/gnu-social/config.php .

# config.phpを編集する
$ vim config.php
- $config['site']['server'] = 'localhost:8000';
+ $config['site']['server'] = 'APP_NAME.herokuapp.cf';
# ついでにこちらの設定を追加しても良い、好みによる
+ $config['site']['path'] = false; 
+ $config['site']['ssl'] = 'never'; 
+ $config['site']['fancy'] = false;

# config.phpをherokuにdeployする
# .gitignoreに注意してください
$ git add config.php
$ git commit -m "add config"
$ git push heroku master

# DBをdumpして編集して、restoreする、profile domain(url)が一部、localhostになっているため、本来のdomain(url)にしたあと、restoreする
# 一応、heroku-mysql dashboardでもbackupを作成してdlしておく
$ mysql --host=$HOST --user=$USER_NAME --password=$PASSWORD $DB_NAME
mysql > select * from user;
$ mysqldump --host=$HOST $DB_NAME --user=$USER_NAME --password=$PASSWORD >! dump.sql
$ vim dump.sql # localhost -> example.com
$ mysql --host=$HOST --user=$USER_NAME --password=$PASSWORD $DB_NAME < dump.sql

# apache_conf.appでも何でもいいので、それらを使って./well-knownあたりの設定を行う、heroku webでは権限上アクセスできなかったりした
# ./well-known/以下はwebfingerにとって重要で、これがインスタンス間のやり取りを行う上で必要な情報になる
$ vim .htaccess
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule (.*) index.php/$1 [L,QSA]
</IfModule>
<FilesMatch "\.(ini)">
        Require all denied
</FilesMatch>
<FilesMatch ".well-known/*">
    Require all granted
</FilesMatch>

説明

gnu socialは、phpで書かれた分散snsです。しかし、composerすらないので、forkを使います。

srcやbuildpackを合わせても、今後、herokuやaddonの仕様変更によって動かなくなる可能性はあります。

動いた日付 : 2019/04/01

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?