How to deploy PHP/HTML website with Gitlab CI

Setting up Gitlab-CI to deploy your PHP & HTML (or any other ‘static’ site) is quite simple, but poorly documented. After a few weeks of fiddling around I found the following solution. I’d love to hear everyone’s feedback.

Requirements:

  1. Your webserver must have root access (to install the runner).
  2. Your site/codebase should be rather small and not too complex.
    • This example uses rsync to move/sync two folders, so sites that can self-update their DB like wordpress should be OK, but I have not tested it.
    • We’re going to use rsync to move/sync two folders, so sites that self-manage media content, like wordpress, will lose that media content. You will need to tweak the rsync script to handle this yourself.
  3. A gitlab install or repo you have permission to add runners to.
  4. These instructions are for Linux (Ubuntu 14.04 specifically) but they should be applicable to any OS supported by the runner.

Continue reading “How to deploy PHP/HTML website with Gitlab CI”

How to setup Let’s Encrypt for Gitlab

This information is outdated as of 2019, but I’ll leave it up here for future reference.

This is a quick guide to setting up Let’s Encrypt for Gitlab

Assumptions made:

  1. You’re using the Omnibus Gitlab install.
  2. You’re using Ubuntu (or Debian).
  3. Gitlab is available on the root of a subdomain (gitlab.yourdomain.com)

Continue reading “How to setup Let’s Encrypt for Gitlab”

Howto: Resolve “Failed to Open File” error when installing Magneto Connect extensions

If you’re trying to install a Magento extension though Magento Connect and getting an error like the following:

CONNECT ERROR: Failed to open file /var/www/magento/downloader/.cache/community/OrganicInternet_SimpleConfigurableProducts-0.7.4/app/code/community/OrganicInternet/SimpleConfigurableProducts/Catalog/Model/Product/Type/Configurabl

It’s caused by a simple (yet long-lived and un-fixed) bug in Magento’s downloader.

Open:

/downloader\lib\Mage\Archive\Tar.php

Find:

if (!($header['name'] == '././@LongLink' && $header['type'] == 'L')) {
     $header['name'] = trim($header['name']);
     return $header;
}

Replace with:

if (!(trim($header['name']) == '././@LongLink' && $header['type'] == 'L')) {
     $header['name'] = trim($header['name']);
     return $header;
}

Then try to install your extension again. Always remember to disable the compiler before hand, clear caches, and log out of the admin after installing an extension.

HowTo: Remove message requirement when assigning tickets in OSTicket

Sometimes you just need to assign a ticket to another team member quickly and move on, but OSTicket insists on a leaving an assignment message. This is especially annoying when the reason for the assignment is blatantly obvious (such as a sales inquiry being assigned to a sales rep in the dept).

In OSTicket v1.9.7 open scp/tickets.php and locate the following block (around line 171):

 //Comments are not required on self-assignment (claim)
if($claim && !$_POST['assign_comments'])
$_POST['assign_comments'] = sprintf(__('Ticket claimed by %s'),$thisstaff->getName());
elseif(!$_POST['assign_comments'])
$errors['assign_comments'] = __('Assignment comments required');
elseif(strlen($_POST['assign_comments'])<5)
$errors['assign_comments'] = __('Comment too short');

If you want to remove the comment requirement altogether then either comment out or remove the last 4 lines like so:

//Comments are not required on self-assignment (claim)
if($claim && !$_POST['assign_comments'])
$_POST['assign_comments'] = sprintf(__('Ticket claimed by %s'),$thisstaff->getName());

If you just want to shorten the minimum requirement, then change the 2nd to last line.

From:

elseif(strlen($_POST['assign_comments'])<5)

to:

elseif(strlen($_POST['assign_comments'])<3)

A quick guide to Solving: Error code: ssl_error_rx_record_too_long

If you’re getting the error “Error code: ssl_error_rx_record_too_long” when trying to setup an SSL enabled website on Apache (2.4 specifically, but likely 2.2 as well), double check that you’ve actually enabled SSL in the virtualhost config file. Its very easy to get carried away imputing all the various SSL parameters and forget the most important:

SSLEngine on

Add customers to Magento newsletter via web form form

Recently I was tasked with adding customers to a Magento newsletter via a pre-exisitng form. Previously this form just sent an email that was mostly ignored, so now the ManInCharge wanted it feeding into Magento, which has several nice plugins for MailChimp integration, but that’s a story for another day.

Setup your form just like any other HTML text form, point it with a POST action at something like this:

$email = $_POST["email"];
if ($email){

# create new subscriber without send an confirmation email
Mage::getModel('newsletter/subscriber')->setImportMode(true)->subscribe($email);

# get just generated subscriber
$subscriber = Mage::getModel('newsletter/subscriber')-&gt;loadByEmail($email);

# change status to "subscribed" and save
$subscriber->setStatus(Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED);
$subscriber->save();
}

With some help from ifuelinteractive and paniticz

Monitor S.M.A.R.T. stats in Zabbix

Need to track disk SMART stats in Zabbix? I found a fairly simple method that does not rely on external scripts (other than the Zabbix agent).

1) Edit your Zabbix Agent config to permit remote commands if you have not already done so. It’s usually /etc/zabbix/zabbix_agentd.conf

EnableRemoteCommands=1

2) Near the bottom of your agent config there should be several “UserParamerter=…” lines, add a new one:

UserParameter=hdd.smart[*],sudo smartctl -A /dev/$1 | grep -E -i '^[ ]*($2)[ ]' | cut -c88-

In short, this command spits out a full SmartMonTools report for your drive ($1), greps it for a single specific line ($2), then removes the first 88 characters, leaving only the raw value behind.

Make sure that smartctl is in your suroers file for any user to run without a password prompt. I detail that process in a previous post.

Continue reading “Monitor S.M.A.R.T. stats in Zabbix”

Allow any user on linux to run smartctl without password

Need to have a script or external application run smartctl without being prompted for a password? Simply add it to the sudoers file. Under Ubuntu/Debian use “visudo” to edit it (DO NOT EDIT IT WITHOUT USING THIS COMMAND!) and add the following line:

ALL ALL=(ALL)NOPASSWD: /usr/sbin/smartctl

This allows any user, from any source (local or remote) to run the smartctl command without being prompted for a password. Note, your script or user will still need to preface the smartctl command with sudo.