Yet Another Roots on Shared Host “Article” more like Journal

Experimenting with Capistrano on my shared server based on this blog post (a bit dated, yes).

Ya have to set a few configurations including config/deploy.rb:

set :deploy_to, '/home/account_name/deploy'

# Set path to Composer
SSHKit.config.command_map[:composer] = "/home/account_name/bin/composer.phar"

Running bundle exec cap production deploy,

Was getting an error in SSH connection.

Using an .ssh/config file alias (which is set up and working as per this DO tutorial).

role :app, %w{SSHalias_Name}
role :web, %w{SSHalias_Name}
role :db,  %w{SSHalias_Name}

Seem to have solved by running bundle update net-ssh, which updated from version 2.9.1 to 2.9.2.

Now is connecting.

Had to add a line to config/deploy.rb :

set :tmp_dir, "/home/dh_user_name/tmp"

Because my hosts do not allow executables from the /tmp directory.

Thanks to this post for the tip.

Getting Capistrano working on the server tool some fiddling – WHB folks helped (they’re awesome). Had to disable suhosin via CPANEL. Then, from my home directory:

curl -sS | php -- --install-dir=bin

Then execute this command: php bin/composer.phar to unpack the phar archive file.

Now when we run bundle exec cap production deploy we’ll probably get a “permission denied (public key)” error. So we need to SSH into the public server and follow the this DO tutorial methods for generating a public key again, run cat ~/.ssh/, copy the output, log into the github (or equivalent) account and under settings, add it as a new public key for the repository (or for the whole account).

Getting there, but Capistrano is failing on the server with error code 2 and zero output.

Wait a minute! Let’s try running composer install without all the flags, in particular the --quiet flag.

[~/deploy/releases/20150825043555]# /home/account_name/bin/composer.phar install
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - This package requires php >=5.4 but your PHP version (5.3.29) does not satisfy that requirement. 

Update php version via CPANEL and we seem to be in business.

Finished in 0.138 seconds with exit status 0 (successful).

changed access bits set on the folder /home/hamiltonwellness/deploy/ from 777 to 755

updated htaccess:

RewriteEngine on 
RewriteCond %{HTTP_HOST} ^(www.)?$ 
RewriteCond %{REQUEST_URI} !^/web/ 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ /web/$1 
RewriteCond %{HTTP_HOST} ^(www.)?$ 
RewriteRule ^(/)?$ web/index.php [L] 

Final hurdle was getting the .env file that holds the database credentials to transfer into the deploy/revisions/TIMESTAMP directory, which required setting some more details in the config/deploy,rb file:

set :linked_files, fetch(:linked_files, []).push('.env')
set :linked_dirs, fetch(:linked_dirs, []).push('web/app/uploads')

At the end of the day, I’m not sure if it’s really worth the trouble to try and use a shared account for this style of Application tree. May have been more of a learning experience than anything. More later, I guess.