Install Custom laravel 4 Application to OpenShift
Step by step tutorial on how to install laravel 4 with mysql database on OpenShift
Openshift is a cloud computing platform as a service product from redhat .
This product is much like Amazon Elastic beans or Google App Engine .
To understand this tutorial you have to know
- GIT Version Control
- Linux and SSH
- Knowledge about Cloud Hosting
What you will get from this tutorial ?
- Install Laravel Application with MySql database from the GIT repository (Bitbucket)
Note: we did this tutorial using a windwos machine, if you use Linux you may skip some parts.
Let's Start :)
- Login to your OpenShift dashboard
- Click Add Application
- Search For PHP and choose PHP 5.4 as in this image
- in this step you will choose your application name and domain name as in this image
- This step will allow you to choose whether you want to scale your application with traffic or not , this is very useful option as OpenShift will scale your application automatically to handle your traffic using your free three gears , Please note if you didn't choose to scale your application at this point you can't change this later for this application .
- Setup your public key (Paste it) , you can skip this part and use openshift RHC client tool to setup it for you automatically
- Here you can clone repository to your local machine, do your changes,commit and push it directly to OpenShift , this is most practical example and I would prefer this model but as I mentioned earlier in this tutorial we will use BitBucket repository as for me myself I use it as primary GIT code repository , others may use GITHUB or any other similar tool , these steps apply to all :)
- Click Continue to the application overview page so we can add MySql cartridge and get SSH Link
- To connect Your OpenShift Gear you need Putty SSH Client and PuttyGen to convert your private key from pub to PPK so it will work with putty , you can download booth tools from Putty SSH site
- Convert your private key , it's located under your name in windows users folder inside .SSH folder . (It will be there after you use RHC client)
As in above picture import your key and click (Save private key) button to convert it.
- Put your SSH link as in this image and don't forget to remove SSH from its start
After that click Auth. and choose your private key from earlier step then click open, you will have message ask you to accept certificate, click Yes
- if everything OK you will get screen like this
- Change your current directory to app-root directory inside this you will find repo directory this is where you should put your application code , as for now it have one PHP file called index,php
- back to your laravel application open app/config/database.php and do this changes:
For host 'host' => getenv('OPENSHIFT_MYSQL_DB_HOST'),
and important add another config array element called port
'port' => getenv('OPENSHIFT_MYSQL_DB_PORT'),
this is important and if you forgot it your MySql connection will not work , and for database user and password you can get them from OpenShift application dashboard .
- Back to your SSH session run this command rm -rf repo this will delete repo folder content and throw permeation denied exception to you , don't worry it's ok :)
- From your current directory app-root run git clone repo_url repo (replace repo_url with your repository https clone url) , so this will clone your repository with predefined configuration from previous step to your machine .
- Openshift gear comes with Composer pre-installed , if you did run composer update and got any error like memory error or something similar then you have to download your custom version of composer and run update against it .
To do this use this command
curl -s https://getcomposer.org/installer | php -- --quiet --install-dir=$OPENSHIFT_DATA_DIR
This will quietly install composer after that you can run
php $OPENSHIFT_DATA_DIR/composer.phar update
or whatever composer command you want !
- Last step run ln -s public php this will create symbolic link from laravel public folder to php as redhat central apache server search this location for your app.
Now everything should run smoothly, if anything goes wrong please post comment below.
comments powered by Disqus