You can't run Laravel 5.1 on OpenShift by default, because it requires PHP >= 5.5.9, and OpenShift provides just PHP 5.4 support.
So if you want to run small presentation or test your app for free, using OpenShift Free Plan, you have to do a lot of preparation by yourself!
Just keep in mind that free plans have 24h idling, which means your application will respond pretty slow if not accessed in previous 24h, because OpenShift will idle those gears.
One more thing to keep in mind! OpenShift gears don't share storage. So if you chose scaling you have to store assets (not versioned) externally, eg. images.
Thanks to Warnar Boekkooi who provided nginx and PHP cartridges we can create proper environment for Laravel 5.1. Required cartridges source code is located on GitHub:
You should check those pages details and supported configurations. You can follow steps there for setup via command line, or continue and do it via OpenShift web console.
OpenShift application creation steps
- Go to OpenShift's create application page: https://openshift.redhat.com/app/console/application_types.
- Scroll to the bottom and find in the left corner "Code Anything" title with input field bellow.
- Paste URL of nginx cartridge
http://cartreflect-claytondev.rhcloud.com/github/boekkooi/openshift-cartridge-nginx
, then hit next button. - Populate Public URL field.
- Chose Scaling if you want.
- Hit "Create Application" button and wait for OpenShift to build your environment.
- Copy application git repo link and continue to the application overview page.
Add PHP cartridge to your application
- Find on the bottom of the application overview page "see the list of cartridges you can add" link and click on it.
- Scroll to the bottom of the page and find "Install your own cartridge" title with input field bellow.
- Paste URL for PHP cartridge
http://cartreflect-claytondev.rhcloud.com/github/boekkooi/openshift-cartridge-php
, then hit next button. - On next page check details and hit "Add Cartridge" button and wait for OpenShift to update your environment.
Additional cartridges
If you need anything else like DB for example use existing OpenShift cartridges (MySQL, PostgreSQL).
Prepare for Laravel 5.1
- Clone application repo localy
- Go to repo's root
Prepare Laravel project
- Run
composer create-project laravel/laravel --prefer-dist
, and this will create project inlaravel
subdir. You are not able to create project in non empty dir! - Go to file manager and move all files from
laravel
subdir one step up, then removelaravel
dir. - Check
config/app.php
line 81 for APP_KEY! - Commit changes!
Update NGINX configuration to enable pretty URLs
-
Open
.openshift/nginx.conf.erb
in some text editor (eg. Atom) -
Find
server
block, starting at line 29 and replace it with:server { listen <%= ENV['OPENSHIFT_NGINX_IP'] %>:<%= ENV['OPENSHIFT_NGINX_PORT'] %>; root <%= ENV['OPENSHIFT_REPO_DIR'] %>/public; index index.html index.htm index.php; charset utf-8; location / { try_files \$uri \$uri/ /index.php?\$query_string; } location = /favicon.ico { access_log off; log_not_found off; } location = /robots.txt { access_log off; log_not_found off; } location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:<%= ENV['OPENSHIFT_PHP_SOCKET'] %>; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_script_name; include <%= ENV['OPENSHIFT_NGINX_DIR'] %>/usr/nginx-<%= ENV['OPENSHIFT_NGINX_VERSION'] %>/conf/fastcgi_params; } location ~ /\.ht { deny all; } }
-
Commit changes!
Add composer support
-
Create file
.openshift/action_hooks/deploy
. -
Give it executable permissions:
chmod +x .openshift/action_hooks/deploy
. -
Paste this content to file:
#!/bin/bash # .openshift/action_hooks/deploy ( cd $OPENSHIFT_REPO_DIR ; composer install --no-interaction --no-dev )
-
Commit changes!
Deploy to OpenShift
Assuming your origin is OpenShift and you want to push local master to remote master run git push
.
You should see detailed response from OpenShift about stoping PHP and NGINX, than installing all your dependencies.
Now go to public URL for your app and you should see Laravel 5 default page!