john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

OpenShift PHP Drupal PHPMyAdmin DIY Tomcat

[TOC]

Prerequisites

sudo apt-get update sudo apt-get install ruby1.9.3

ruby 1.9.3 comes with Ubuntu 12.04 but you can always use a newer version (like 2.1.2) via rvm

sudo apt-get install git-core

sudo gem install rhc

The red hat client (apparently written in ruby)

rhc setup

Created local config file: /home/ubuntu/.openshift/express.conf
The express.conf file contains user configuration, and can be transferred to different computers.
No SSH keys were found. We will generate a pair of keys for you.
2: No such file or directory
    Created: /home/ubuntu/.ssh/id_rsa.pub
Your public ssh key must be uploaded to the OpenShift server.  Would you like us to upload it for you? (yes/no) yes

WebUI

https://openshift.redhat.com/app/console/application_type/quickstart!13145
Choose a public url (name-domain.rhcloud.com)
Source Code: https://github.com/openshift/drupal-quickstart.git
Gear: Small
Cartridges: PHP 5.3 and MySQL 5.5
No Scaling

After waiting about 5 minutes it comes up with credentials for the Database and how to clone the repo

The WebUI makes it easy to:

  • Add a Cartridge (from a list) to add phpMyAdmin and Cron Cartridges
  • Click on the link box to the right of phpMyAdmin 4.0 to launch it
    • https://name-domain.rhcloud.com/phpmyadmin/
  • The DB username and password are to the right of the MySQL 5.5 Cartridge

rhc app stop -a APPNAME

SSH into the application

You may optionally SSH into an application and interact with the environment

IMPORTANT to note that the repo that you have cloned and commit code to is a small part of the cloud file structure:

At the root (after ssh) you will see the directories:

app-deployments
app-root
cron
git
mysql
php
phpmyadmin

ONLY app-root/data will be preserved between pushes (and is not versioned controlled)

ssh 12345randomstring@appname-domain.rhcloud.com

ONCE YOU'VE SSH'D IN... help ps|ls| ctl_app start [stop|restart|status] mysql | mongo | quota

NOTE: sometimes it's easier to use a UI https://openshift.redhat.com/app/console/applications

My Account -> Public Keys

My Applications -> APPLICATION_NAME ->

Drupal Modules

For a Drupal installation you can install modules from the WebUI

http://appname-domain.rhcloud.com/admin/modules/install

They will appear in app-root/data/sites/all/modules/

Similarly themes will appear in app-root/data/sites/all/themes/

Migrating an existing Drupal Installation Manually

For uploading a custom logo, just re-upload it and it will appear in data/sites/default/files

note: this may mean different paths if previously you had a multi-site drupal installation

https://www.openshift.com/developers/openshift-environment-variables

Thus to have file uploads work in Drupal you need to ensure they upload there,

AND/OR for scp'd files to be accessible make a symbolic link to a static directory:

mkdir app-root/data/photos
cd app-root/repo/php
ln -s ../../data/photos photos

OR modify drupal to reference a directory in the repo? (maybe symlink from app-root/data/sites/default/files)?

https://www.openshift.com/forums/openshift/one-newbie-question

Hack the Drupal RSS feed to show more items

Downloading items from an existing Drupal installation (via the RSS feed) requires an extra hack:

grep -r 'items per feed' .
# learned from drupal-7.28/modules/system/system.module
vi modules/system/system.admin.inc
$form['feed_default_items']
  • https://www.openshift.com/blogs/how-to-migrate-drupal-to-openshift
  • export from Drupal using phpMyAdmin
  • (ensure that the new one from OpenShift is the same version as the one you're exporting from)
  • Import once you've opened the phpMyAdmin on your new OpenShift Gear
  • drop all the tables for the database (i.e. appname)
  • Import Button (browse to the local file location of your .sql or .sql.tar.gz, just accept all of the defaults)

Now for files...

RedHat Cloud CLI commands

rhc -h rhc domain show //prompts for password

rhc app create -h

Valid application types are (nodejs-0.6, ruby-1.9, jbossas-7, python-2.6, jenkins-1.4, ruby-1.8, jbosseap-6.0, diy-0.1, php-5.3, perl-5.10)

OpenShift DIY Application

rhc app create -a john -t diy-0.1

rhc app show -a john

rhc app cartridge list

rhc app add-alias -a myapp --alias myapp.net

Cloning the new OpenShift Application to your local machine

ON YOUR LOCAL MACHINE BROWSE TO WHERE YOU WANT TO STORE YOUR GIT REPO

git clone git clone ssh://a261d0fc2932413694456e3473fdc972@APPNAME-DOMAIN.rhcloud.com/~/git/APPNAME.git/

git status git pull

REPO LAYOUT of ~/john/repo

.openshift/action_hooks/start - Script that gets run to start your application
.openshift/action_hooks/stop - Script that gets run to stop your application
.openshift/action_hooks/pre_build - Script that gets run every git push before the build
.openshift/action_hooks/build - Script that gets run every git push as part of the build process (on the CI system if available)
.openshift/action_hooks/deploy - Script that gets run every git push after build but before the app is restarted
.openshift/action_hooks/post_deploy - Script that gets run every git push after the app is restarted
diy
misc
README
static/         If it exists externally exposed static content goes here

CHANGES ARE ONE DIRECTIONAL FROM THE GIT CLONE TO THE OPENSHIFT BOX

mv diy/testrubyserver.rb  ../misc
mv diy/index.html  ../misc

git add -A
git commit -m "moved initial test stuff to /misc"
git push                //if the app is running then a git push automatically ...

    Counting objects: 6, done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (4/4), done.
    Writing objects: 100% (4/4), 607 bytes, done.
    Total 4 (delta 1), reused 1 (delta 0)
    remote: Stopping application...
    remote: Done
    remote: ~/git/john.git ~/git/john.git
    remote: ~/git/john.git
    remote: Running .openshift/action_hooks/pre_build
    remote: Running .openshift/action_hooks/build
    remote: Running .openshift/action_hooks/deploy
    remote: Starting application...
    remote: Done
    remote: Running .openshift/action_hooks/post_deploy

Install Tomcat manually via SSH into the DIY Application

ssh 51233d90ea45fd91e42096651d937e@john-pfeiffer.rhcloud.com //note that HOME is /var/lib/stickshift/12315longidentifier

cd app-root/data
wget http://mirror.cc.columbia.edu/pub/software/apache/tomcat/tomcat-7/v7.0.29/bin/apache-tomcat-7.0.29.tar.gz
tar -xzvf apache-tomcat-7.0.29.tar.gz           //expands to 13MB, note that JAVA is already installed by default
rm apache-tomcat-7.0.29.tar.gz

OpenShift Ports

Since OpenShift has a proxy setup that passes port 80 to your local server on port 8080, BUT

OpenShift does not allow users to bind to any port below 15000 other than 8080, so...

ssh 521233d90ea45fd91e42096651d937e@john-pfeiffer.rhcloud.com

env             //shows you all of the environment variables in the openShift multitenant config
env | grep INTERNAL
    OPENSHIFT_INTERNAL_PORT=8080
    OPENSHIFT_INTERNAL_IP=127.13.29.1

vi app-root/data/apache-tomcat-7.0.29/conf/server.xml

<Server port="15005" shutdown="SHUTDOWN" address="127.13.29.129" >

<Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
                   address="127.13.29.129"
               redirectPort="15443" />

<Connector port="15009" protocol="AJP/1.3" redirectPort="8443" address="127.13.29.129" />

<Engine name="Catalina" defaultHost="127.13.29.129">

<Host name="APPNAME-DOMAINname.rhcloud.com"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

escape key then :x (save and quit)

Manually Start and Stop Tomcat

cd app-root/data/apache-tomcat-7.0.29/bin

sh startup.sh && tail -f ../logs/*

(this is how you can start it manually from within ssh, you'll have to stop it manually too!)

Adding Tomcat to your default start and stop scripts

(which are used during every git push)

In your local git repo there is a hidden directory ".openshift"

cd APPNAME/.openshift/action_hooks

vi .openshift/action_hooks/start

#nohup $OPENSHIFT_REPO_DIR/diy/testrubyserver.rb $OPENSHIFT_INTERNAL_IP $OPENSHIFT_REPO_DIR/diy > $OPENSHIFT_LOG_DIR/server.log 2>&1 &

cd $OPENSHIFT_DATA_DIR/apache-tomcat-7.0.29/bin
nohup sh startup.sh
echo "completed tomcat7 startup"

vi .openshift/action_hooks/stop

cd $OPENSHIFT_DATA_DIR/apache-tomcat-7.0.29/bin
nohup sh shutdown.sh
echo "completed tomcat7 shutdown"
exit 0

git add -A git commit -m "removed testrubyserver.rb and added tomcat to start/stop scripts" git push

http://APPNAME-DOMAINNAME.rhcloud.com

Auto Deploy the newest by moving your WebApps Directory to the git repo

mv $OPENSHIFT_DATA_DIR/apache-tomcat-7.0.29/webapps ~/john/repo/diy/webapps

ln -s ~/john/repo/diy/webapps webapps

Cleanup Tomcat

Strongly advised to remove the manager and example apps (just deploy your .war's)

rhc app-stop -a APPNAME -p YOURPASSWORD //yes, it uses your RHCloud account username and password for app management

ssh 521233d90ea45fd91e42096651d937e@john-pfeiffer.rhcloud.com mv ~/app-root/data/apache-tomcat-7.0.29/webapps/* app-root/repo/misc mv app-root/repo/misc/ROOT ~/app-root/data/apache-tomcat-7.0.29/webapps

rhc app-start -a APPNAME -p YOURPASSWORD


  • « mock unit test py test attribute method side effect assert
  • concurrency threading external communication control through queue inherit super »

Published

Jun 30, 2014

Category

linux

~1096 words

Tags

  • drupal 43
  • openshift 2
  • php 82
  • tomcat 8