Heroku 建置筆記
安裝
參考 選擇你所開發的語言 /Introduction /Set up 有說明
https://devcenter.heroku.com/start
info
免費版只能開5個apps
指令
參考:
https://devcenter.heroku.com/articles/heroku-cli-commands
指令 (*常用) | 說明 | 備註 |
---|---|---|
heroku help {heroku commad} | 查heroku指令文件說明 | |
heroku --version | 版本查詢 | |
heroku login | 登入帳號密碼 | |
heroku create | 隨機命名建立一個app | |
heroku apps:create [APP] | 指定命名建立一個app | |
heroku ps | ||
heroku ps:scale web=1 | ||
heroku open | ||
heroku logs --tail | Control+C退出 | |
heroku addons | ||
heroku addons:open papertrail | ||
heroku addons:create heroku-postgresql --app my-app | ||
heroku run | ||
heroku run "php -a" | ||
heroku bash | exit離開 | |
heroku config | ||
heroku config:set TIMES=20 | ||
heroku pg:psql | ?? |
開發PHP
OS環境:CentOS7
參照Heroku官網 https://devcenter.heroku.com/articles/getting-started-with-php#introduction
本機安裝PHP、Composer、git、Heroku CLI
CentOS7 升級 PHP7.1
wget -q http://rpms.remirepo.net/enterprise/remi-release-7.rpm
wget -q https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo rpm -Uvh epel-release-latest-7.noarch.rpm
sudo rpm -Uvh remi-release-7.rpm
#安裝yum-config-manager
sudo yum -y install yum-utils
sudo yum-config-manager –enable remi-php71
#如果已安裝過PHP 5.x
sudo yum update php*
php -version
CentOS7 安裝Heroku CLI
# Where REPLACE_ME_OS is one of “linux”, “darwin”, “windows” and REPLACE_ME_ARCH is one of “x64”, “x86”, or “arm” You also must replace “6.x.x” with the actual version.
$ wget https://cli-assets.heroku.com/heroku-cli/channels/stable/heroku-cli-REPLACEME_OS-REPLACE_ME_ARCH.tar.gz -O heroku.tar.gz
$ tar -xvzf heroku.tar.gz
$ mkdir -p /usr/local/lib /usr/local/bin
$ mv heroku-cli-v6.x.x-darwin-64 /usr/local/lib/heroku
$ ln -s /usr/local/lib/heroku/bin/heroku /usr/local/bin/heroku
heroku 帳號登入
heroku login
#會出現輸入email及密碼
# Prepare the app 下載一個heroku PHP demo網站
git clone https://github.com/heroku/php-getting-started.git
cd php-getting-started
# Composer 本機端下載套裝
##先確認是否有裝unzip
sudo yum install unzip
composer install
建立本機apache環境
設置 Apache 2.4 HTTP Server
hostname {houstname}
調整 /etc/httpd/conf/httpd.conf
Listen {ip}:{port}
ServerName {ip}:{port} 未確定是否要調整?
NameVirtualHost {ip}:{port} 未確定是否要調整?
<VirtualHost *:80>
ServerName test.test.com.tw
DocumentRoot "/var/www/test"
<Directory "/var/www/test">
Options -Indexes +FollowSymLinks +Includes
AllowOverride All
Order allow,deny
Allow from All
</Directory>
</VirtualHost>
systemctl start httpd.service
systemctl enable httpd.service
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload
#測試網址執行成功
網站佈署至Heroku
1.heroku apps:create [APP]
$ heroku apps:create johnnyc7
2.執行成功畫面
3.下 git remote 指令,可以看到遠端git建立heroku
4.開始佈署至Heroku
$ git push heroku master 更新程式
...
開始跑很多push訊息
...
$ heroku ps:scale web=1 設定app實體
$ heroku open 看是否成功
5.到heroku帳號看到已建立一個app了
點進app 右上角有一個Open app也可以開啟網站
看到這個畫面就表示成功了 Yeah!
PHP Slim安裝
# enter slim floder
sudo yum install phpunit #安裝unit
composer create-project slim/slim-skeleton [my-app-name]
#新增Procfile 增加下行
web: vendor/bin/heroku-php-apache2 public/
heroku apps:create johnnyslim
git init
git add .
git commit
heroku git:remote -a johnnyslim
git push heroku master
$ heroku ps:scale web=1