Sophie, a command line tool for apache 2 virtual host and git bare repository creation

I’m using a VPS to host web apps with apache2 and git. I setup a virtual host and a git repository per app. I use git to easily push updates to applications, everything on the production branch is in sync with the live server.

The steps I used to take when I wanted to create a new web app for hosting on the server was to create a new virtual host configuration file from a template, create the folders needed for the virtual host and create a git bare repository with the configuration needed to push updates to the virtual host. This turned out to be a repetitive task and so I decided to create a program to automate the whole process.

Meet Sophie, Sophie automates the creation of virtual hosts and git (bare) repositories. Sophie is fully configurable, for example you can configure template files for both virtual host and git hook. There are also command line options to create either a virtual host, a repo or both. So now, creating a new virtual host is as easy as:

Here’s every command line option available.

To start using Sophie:

  1. download the repository
  2. copy/rename sophie.sample.ini to sophie.ini
  3. edit sophie.ini and update the paths – defaults are set for default debian installations

I’m sharing as someone else might have the same need. Leave a comment if you find it useful.

Python 3 virtual environment and pip requirements how to

If you have installed pyvenv execute

After installation create ~/pyenv directory and change to it.Execute

to create a virtual environment and

to activate it. After activation install any packages you need via pip and execute

to save the requirements.txt file. Now when you’ll need to install your project on another computer execute

and you’re ready to go

PHP: How to enable errors on browser

You’re coding your small app (not coding a small app? give Laravel a read/try) and you like to display any php errors directly to your browser. Here’s how to do it, set the error_reporting level to E_ALL, display_errors to on. Here’s how, add the following code at the top of every php file or on your index/config file

Now each time a PHP error occurs you’ll see it on your browser. Don’t forget to comment out those 2 lines on your production/live server else when an error occurs everybody will be able to see.

Essential Drupal modules you can not live without

Alright, you could live without but you really should not. I have started using Drupal 7 three weeks ago and that time was enough to figure out that there is a set of modules that are essential for every Drupal application you will ever make. So far I have identified five modules I could not live without, if you think there should be more on this list contact me and I will add them.

Starting with Module filter and Administration menu, two modules that helps you do stuff faster.

1) Module filter transforms the modules page into a page that makes it easy to find modules faster by categorizing them into tabs, sorting them alphabetically in their respective tab and by adding an in-page search box which allows you to search for installed modules instantly.

Here is a screenshoot of Module filter.

2) Administration menu is a time saving module, it replaces the default toolbar with one that displays a nested menu with all the administrative options. So instead of clicking “People” waiting for the page to load and then clicking “Permissions”, you just navigate to permissions through the menu and you’re there. Don’t forget to enable Administration menu style to beautify the toolbar.

Here is a screenshot of Administration menu.

3) Autocomplete deluxe is a must have module that helps end users by allowing them to create taxonomy terms on the fly. It’s a widget for term refs field which enables the autocompletion and creation of taxonomy terms as you type. Say you start writing an article or adding a new product and you have forgot to create a tag or a category term, autocomplete will create it for you without you having to go to the taxonomy interface, add it and got back to the content type you were adding.

Here is a screenshot of Autocomplete deluxe.

4) Token translates small bits of code into dynamic content. For example you’re sending out email with subject “Welcome [user:name]”, [user:name] will be replaced with the actual name of the user the email being send.

5) Views as far as I can understand is your “SQL statements” via a UI. With Views you can select any fields from your database and make them browseable and viewable to your site.

I am sure I am missing many “must have” modules, what is your pick?

Linux Mint Debian Edition (LMDE) post installation

As I’m coding on a crappy Pentium D PC. I was looking for some time now a fast and user friendly Linux distro. Always preferred debian based distros so I’ve given a try to Ubuntu, Ubuntu LTS and of course Debian 7. Debian was the fastest of the 3 but was lacking a nice and fast UI. Meet Linux Mint Debian Edition (LMDE)! Debian based with the beautiful MATE desktop and the speed of Debian.

Here I’m documenting the steps I’ve took to setup my newly installed OS to my taste.

First step to fetch any new upgrades but before that add i386 support for your system.

and then

Next step installing the development environment which includes apache, php5 + modules, composer, mysql, git, vim and gvim.

Composer doesn’t exists on the official repository so we’ll install it by hand. Firstly we are gonna create a new folder called bin on our home directory and then update our $PATH to include that directory.

Now edit your ~/.bashrc and append ~/bin to your $PATH

While you’re at your .bashrc export vim as your default editor

Install java

Install java using this tutorial

Turn auto-login on

Menu > Administration > Login Window Preferences > Security. Click ‘Enable Automatic Login’ and select the user you want to auto login

Laravel 4 – Versioning your app using git

A simple and neat way of versioning your app with git automatically.

What you’ll need:

  • a git hook
  • an artisan command
  • a new laravel config file

First create an artisan command using php artisan command:make versioning then edit your app/start/artisan.php to register your newly created artisan command by appending Artisan::add(new Versioning); at the end of the file.

Let’s take a look at our newest artisan command, let’s do a php artisan list to see if it is there, (if it isn’t run php artisan dump).

Now we are gonna edit the command to our needs, here’s how it should look like.

Now we are gonna create a new hook with the name post-commit under .git/hooks with the following content:

EDIT: If you’re on a Mac and you run into permission issues with post-commit please see this comment. There’s a possible solution thanks to @snipe

The version is based on your git tags so there would be at least one tag. Type git tag to see your available tags, if you don’t have you must create one to be able to version your app using git. Type git tag 0.1 to create a new tag name 0.1, a git tag name doesn’t have to be a number it could be a word like so git tag milestone1.

Now every time you commit your version will be changing, here’s an example of what you’ll be seeing every time you run

The first part is your tag name, the second part is the number of commits you’ve made since the tag was made and the last part is the unique SHA of your lastest commit.

How do you retrieve the version you say? Easily by doing

Laravel 4 – Simple Validation Trait

A simple drop in validation trait that can be used in your models.

Validator Trait

Add the trait in your model and set your $rules array if needed. The $rules array can also be passed as an argument.

Employee Model

 

A simple usage scenario.

Controller

Most used git commands

Keeping those here as a reference.

EVE-SL will be released to the public.

12/12 EDIT: Not able to push EVE-SL to a stable release as I have a very heavy schedule. I’ll keep you posted for any updates.

It’s been sometime now that i’m working on rewriting EVE-SL to be released as an open source project. You can follow the progress on github. Pull requests will be not be accepted at this point, i want to rewrite everything first.

Server downtime

There was a hard disk failure on the server my VPS is on two days ago and Quickweb.co.nz had to replace the faulty disk. Sites and services were down for more than 24hs (btw, Quickweb took the opportunity to change to a newer sandy bridge server) . Now everything is restored (thanks to my daily backups) and fully functional. I understand shit can happen and do happens all of the time but didn’t expect a downtime of more than 24hs.

I will get a new VPS in another country (currently I’m hosted in Germany) and setup a failover/load balancer, so it when the shit hits the fan again it won’t be for 24hs, it’ll be for a lot less. Failover/load balancing works best using two machines on the same LAN so to be able to use the same public IP but unfortunately my provider simply doesn’t provide that service and I don’t wanna change them as I trust those guys, been running for 7 months without a glitch.

Will keep you posted and I’m open in any suggestions/ideas.