Upload laravel 5.3 ke openshift

Diharapkan sudah mengerti dan menginstall composer dan git, sudah memiliki account di openshift

Buat project laravel (atau masuk ke direktori project jika sudah dibuat)

composer create-project --prefer-dist laravel/laravel blog
cd blog

Buat git repository pada project tersebut

git init

Buat application di openshift dengan jenis catridge PHP 7 (langsung include dengan nginx) https://hub.openshift.com/quickstarts/253-php-7
Openshift PHP 7 Catridge

Tambahkan alamat repository openshift pada directory project

git remote add openshift ssh://xxxxx/~/git/xxxx.git/

Lakukan pull request dari openshift, nanti akan muncul beberapa directory dan file tambahan dari openshift

git pull openshift HEAD --allow-unrelated-histories

Buat file dengan nama post_deploy pada directory .openshift/action_hooks/ isi dengan script sebagai berikut

#!/bin/bash

export MY_PHPCOMPOSER=$OPENSHIFT_DATA_DIR/composer.phar

# if composer not exists, download
if [ ! -f $MY_PHPCOMPOSER ]; then
    cd $OPENSHIFT_DATA_DIR
    echo "Downloading composer..."
    php -r "readfile('https://getcomposer.org/installer');" | php 
fi

$MY_PHPCOMPOSER -n -q self-update
cd $OPENSHIFT_REPO_DIR 
# install
php -dmemory_limit=1G $MY_PHPCOMPOSER update
php artisan key:generate
php artisan config:clear

Ubah web directory config pada file config/nginx.d/default.conf.erb menjadi seperti berikut
Sebelum

...
root              <%= ENV['OPENSHIFT_REPO_DIR'] %>/www;
...

Sesudah

...
root              <%= ENV['OPENSHIFT_REPO_DIR'] %>/public;
...

Lakukan commit dan push ke openshift
git add .
git commit -m ‘initial commit to openshift’
git push openshift master

Semoga berhasil

  • Saurabh Shah

    what about migrations? how to link the database? please explain that too

    • for connections to database, edit file database.php on config directory, change mysql array like this

      'mysql' =&gt; [
                  'driver' =&gt; 'mysql',
                  'host' =&gt; env('DB_HOST', getenv(&quot;OPENSHIFT_MYSQL_DB_HOST&quot;)),
                  'port' =&gt; env('DB_PORT', getenv(&quot;OPENSHIFT_MYSQL_DB_PORT&quot;)),
                  'database' =&gt; env('DB_DATABASE', 'your_db_name'),
                  'username' =&gt; env('DB_USERNAME', getenv(&quot;OPENSHIFT_MYSQL_DB_USERNAME&quot;)),
                  'password' =&gt; env('DB_PASSWORD', getenv(&quot;OPENSHIFT_MYSQL_DB_PASSWORD&quot;)),
                  'charset' =&gt; 'utf8',
                  'collation' =&gt; 'utf8_unicode_ci',
                  'prefix' =&gt; '',
                  'strict' =&gt; true,
                  'engine' =&gt; null,
              ],
      

      To run migrations, add this line on .openshift/action_hooks/post_deploy at last line

      php artisan migrate --force