wasil.org Abandon the search for Truth; settle for a good fantasy

15Jan/1417

Sublime Text 3 perfect PHP development set-up

This is follow-up arti­cle to Sub­lime Text 2 per­fect PHP devel­op­ment set-up. I decided to write this updated ver­sion, because from some time now Sub­lime Text 3 is out there. Maybe it is still offi­cially beta, but works pretty sta­ble and I’m using it for few months now.

This list is almost the same as in pre­vi­ous arti­cle — most of plu­g­ins I used with ST2 have been updated in order to work with ST3 and I stopped using few of them, so they are out. I’m kinda lazy, so some of descrip­tions are copy-pasted from pre­vi­ous article ;)

Any­way, here is the list:

  1. Pack­age Con­trol (https://sublime.wbond.net)
    Thanks to this lit­tle piece of soft­ware all other plu­g­ins are eas­ily installed.
  2. Sub­lime­CodeIn­tel (https://github.com/SublimeCodeIntel/SublimeCodeIntel)
    This is pack­age I use all the time. Its job is to pro­vide hints related to func­tion, object, vari­able etc. names. It also hints what meth­ods and para­me­ters are avail­able in objects/classes. It’s based on Komodo CodeIn­tel and some­times it has some prob­lems work­ing at all. But most of the time it rocks :)
  3. Sub­limeLin­ter (https://sublime.wbond.net/packages/SublimeLinter)
    This pack­age does full-time job for me — it con­stantly watches what I write and instantly lets me know if some­thing is not OK, for exam­ple I for­get semi-colon or brackets.

    (update)

    From ver­sion 3 and up, Sub­limeLIn­ter has become mod­u­lar. This means, that you have to install main pack­age first, and then plugin/module for every lan­guage you need sup­port for. Each plu­gin has it’s own set of require­ments, so please make sure you read them thoroughly.

    For PHP + JavaScript devel­op­ment I’m using:

  4. Side­BarEn­hance­ments (https://sublime.wbond.net/packages/SideBarEnhancements)
    Pro­vides great new options when right-clicking on side­bar ele­ments (files/folders). Very convenient.
  5. VCS Gut­ter (https://sublime.wbond.net/packages/VCS%20Gutter)
    Lately I don’t imag­ine work­ing with­out this one. Every day I use Git and Mer­cu­r­ial and this plu­g­ins gives me real-time infor­ma­tion about what was changed (or added/removed) in cur­rent file using sym­bols in left-hand edit win­dow gutter.
  6. SFTP, paid (http://wbond.net/sublime_packages/sftp)
    Great pack­age enabling very com­fort­able use of SFTP, FTP and FTPS. It sup­ports remote fold­ers brows­ing, edit­ing and syn­chro­niza­tion between local and remote files. Also reg­u­lar upload, down­load pn save or file open.
  7. Tor­toise (on Win­dows only) (http://wbond.net/sublime_packages/tortoise)
    I use it as a com­ple­men­tary pack­age to Side­Bar­Git if I’m work­ing in Win­dows envi­ron­ment. It doesn’t have so many fea­tures but those what it pro­vide are very help­full and intuitive.If you like Tor­toise Git but you are work­ing on Linux you might want to check out Rab­bitVCS. It isn’t inte­grated with ST2, but it pro­vides com­fort­able right-mouse-click Git GUI.
  8. sublime-github (https://github.com/bgreenlee/sublime-github)
    Every devel­oper should use code snip­pets of some kind. I use Gist pro­vided by GitHub and this pack­age enables me to use them instantly (save/paste).
  9. Tag (https://github.com/SublimeText/Tag)
    It is fine plu­gin, but now ST3 sup­ports tag match­ing, so I don’t need it any more.
  10. Php­Doc (https://sublime.wbond.net/packages/PhpDoc)
    Great plu­gin aid­ing writ­ing doc­u­men­ta­tion docblocks for PHPDocumentor.
  11. Phpcs (http://soulbroken.co.uk/code/sublimephpcs)
    This pack­age adds sup­port for PHP_CodeSniffer to ST2. It checks if you code is writ­ten accord­ing to one of the stan­dards. Just pick one: Zend, PEAR.. and more :) Check out PHP_CodeSniffer web­site for con­fig­u­ra­tion details.
  12. Trail­ing­Spaces (https://github.com/SublimeText/TrailingSpaces)
    Small hor­ror of every code — empty spaces at lines ends, at the end of file. Espe­cially trou­ble­some if you are work­ing on the code with other devel­op­ers, who might use dif­fer­ent editors/IDEs which might inter­pret them (empty spaces) differently.
  13. Brack­etHigh­lighter (https://github.com/facelessuser/BracketHighlighter)
    Same sit­u­a­tion as with Tag plu­gin. In my every­day cod­ing ST3 bracket high­light­ing capa­bil­i­ties of ST3 are good enough. It is still great plu­gin though.
  14. Sub­lime Func­tion Name Dis­play (https://github.com/akrabat/SublimeFunctionNameDisplay)
    Dis­plays in bot­tom bar name of a func­tion (or method) in which our cur­sor is placed. Sim­ple and helpful.
  15. Ter­mi­nal (http://wbond.net/sublime_packages/terminal)
    Using Git or maybe some PEAR pack­ages you might need to switch to con­sole from time to time and do some magic. Maybe use Zend Tool or “bake” some­thing ;) It’s just what this plu­gin is for.
  16. Xde­bug Client (https://sublime.wbond.net/packages/Xdebug%20Client)
    Lately my favorite Xde­bug client for ST3. Works great and allows to use all of Xde­bug debug­ging capabilities.

Few sup­port­ing pack­ages. I con­sider them optional, but they come in handy:

  1. LineEnd­ings (https://sublime.wbond.net/packages/LineEndings)
    Nice to have plu­gin if you are work­ing with other devel­op­ers using Win­dows and Unix/Linux machines. It takes care of dif­fer­ent (invis­i­ble) line end­ing char­ac­ters in those systems.
  2. Sass (https://sublime.wbond.net/packages/Sass)
    This one comes in handy when work­ing with Sass files. Syn­tax high­light­ing and so on.
  3. Plain­Tasks (https://github.com/aziz/PlainTasks) added thanks to Virion’s com­ment
    Great tool for every­one who like to have their tasks orga­nized, flex­i­ble with many great features.
  4. Sub­limerge (http://www.sublimerge.com/added thanks to Virion’s com­ment
    Diff tool on steroids. Ideal for every­one who has to do a lot with merg­ing, espe­cially use­ful when it comes to large files.
  5. Dash­Doc (https://sublime.wbond.net/packages/DashDoc(Mac only)
    This one is for Mac users only and only for those who have Dash installed, but I really rec­om­mend it. Dash pro­vides access to docs of almost every major library, frame­work etc. and so much more! With this plu­gin you can access it directly right from Sub­liem Text code win­dow with key­board short­cut. It really speeds up coding.

That’s it for now. I might come back and some­thing later, but this is my set-up and works great for me.

If you know any plu­gin worth men­tion­ing, then let me know — I’ll be glad to add it to my list. Any suggestions? :)

1Sep/133

Zend Framework + Whoops (php errror for cool kids)

In Zend Frame­work you can eas­ily set a con­troller and action for error han­dling. In fact there is always default set for you. There is also default tem­plate. But what if you’d like to use some­thing more sophis­ti­cated, let’s say.. nicer look­ing or bet­ter dis­play­ing error stack trace, which obvi­ously helps a lot while debugging?

My sug­ges­tion is to use Whoops, an open source library enabling great look­ing and very intu­itive error dis­play­ing in any PHP appli­ca­tion. Whoops author pre­pared sup­port for Zend Frame­work 2, Silex and more, but unfor­tu­nately there is no ready solu­tion for Zend Frame­work 1 and this is what I’ll try to do in this article.

First of all you’ll need a way to enable it. You can include appro­pri­ate classes in index.php or some other place. I, on the other hand, pre­fer Com­poser, an open source pack­age man­ager for PHP. I won’t go into details in here on how to set up Com­poser autoload­ing — you can see one way of doing in my pre­vi­ous arti­cle or use your own way, whichever you prefer.

To include Whoops in Com­poser, add this to “require” sec­tion in composer.json:

{
  "require": {
    "filp/whoops": "1.*"
  }
}

And install it with:

composer install

Now it is time to init Whoops  and reg­is­ter it as a default error han­dler. I do it in main boot­strap like this:

protected function _initWhoops()
{
    // creating new Whoops object
    $whoops = new Whoops\Run();

    // adding an error handler, pretty one ;)
    $whoops->pushHandler(new Whoops\Handler\PrettyPageHandler());

    // and now final touch: setting Whoops as default error handler
    $whoops->register();
}

One other thing which I had to do was to force Zend Frame­work to ignore all errors and let Whoops han­dle them.
In fact this works for every other error han­dler. In method described before add one line, just before every­thing else:

Zend_Controller_Front::getInstance()->throwExceptions(true);

All together should look some­thing like that:

protected function _initWhoops()
{
    // this line forces Zend Framework to throw Exceptions as they are and letting us handle them
    Zend_Controller_Front::getInstance()->throwExceptions(true);

    // creating new Whoops object
    $whoops = new Whoops\Run();

    // adding an error handler, pretty one ;)
    $whoops->pushHandler(new Whoops\Handler\PrettyPageHandler());

    // and now final touch: setting Whoops as default error handler
    $whoops->register();
}

Basi­cally that’s it. Now Whoops should inter­cept all errors and show them in fancy way :)

25Oct/125

Zend Framework 1 and Composer

Recently I found out, that Zend Frame­work 2 fully sup­ports Com­poser — gem like pack­age man­ager for PHP. But I couldn’t find a way to use it with Zend Frame­work 1 because of it’s default Zend_Loader_Autoloader behav­ior. I really wanted to use it so I came up with dirty hack, here it is:

  1. first you have to add require 'vendor/autoload.php'; in order to load Com­poser autoloader. I do it in Bootstrap.php file:
    (By the way as you can see I’v put vendor folder in library, just to keep things organized.)

    /** *| loading Composer autoloader. */
     protected function _initComposer()
     {
      require '../library/vendor/autoload.php';
     }
    
  2. now we have (the­o­ret­i­cally) access to libraries pro­vided by Com­poser, but we can’t load them, because Zend_Loader_Autoloader is in our way, try­ing to do it’s thing and load classes from appro­pri­ate folder struc­ture. We have to bypass it, by turn­ing it off, access­ing what we need from Com­poser, and turn­ing it on again, so it will be avail­able for fur­ther auto loading.
  3. switch­ing off:
    spl_autoload_unregister(array('Zend_Loader_Autoloader','autoload'));
  4. now some load­ing hap­pens, for example:
    $phpExcel = new PHPExcel();
  5. and now in order to bring it back:
    spl_autoload_register(array('Zend_Loader_Autoloader', 'autoload'));
I know it’s dirty, but works for me, and actu­ally per­forms really well :)
2Aug/1213

Sublime Text 2 perfect PHP development set-up

Update: There is also avail­able plu­g­ins list for Sub­lime Text 3, check it out here

Lately, I’ve become a huge fun of Sub­lime Text 2, which in my hum­ble opin­ion (OK, not only mine, take a look in here) is best text editor/IDE I’ve ever used.

I called it IDE (Inte­grated Devel­op­ment Envi­ron­ment) which isn’t really true yet, but it’s get­ting awfully close to become one.

Sub­lime Text 2 is great on its own, but it really starts to kick ass with help of addons called ‘pack­ages’. You can look for them on Inter­net or browse on wbond web­site.

OK, but get­ting to the point: I use ST2 for some time now for PHP devel­op­ment and I tried almost all pack­ages I came across which are even slightly related to my job. In order to get most of them (except one or two) you’ll need wbond’s Sub­lime Pack­age Con­trol. Ok, really you CAN install all of them man­u­ally, but what’s the point of re-inventing the wheel? I’ll stick with the easy way if you don’t mind ;)

And here is my list, enjoy and maybe throw a sug­ges­tion or two if you know some­thing I don’t know ;)

  1. Sub­lime­CodeIn­tel (https://github.com/Kronuz/SublimeCodeIntel)
    This is pack­age I use all the time. It’s job is to pro­vide hints related to func­tion, object, vari­able etc. names. It also hints what meth­ods and para­me­ters are avail­able in objects/classes. It’s based on Komodo CodeIn­tel and some­times it has some prob­lems work­ing at all. But most of the time it rocks :)
  2. Sub­limeLin­ter (https://github.com/SublimeLinter/SublimeLinter)
    This pack­age does full-time job for me — it con­stantly watches what I write and instantly lets me know if some­thing is not OK, for exam­ple I for­get semi-colon or brackets.
  3. SFTP, paid (http://wbond.net/sublime_packages/sftp)
    Great pack­age enabling very com­fort­able use of SFTP, FTP and FTPS. It sup­ports remote fold­ers brows­ing, edit­ing and syn­chro­niza­tion between local and remote files. Also reg­u­lar upload, down­load pn save or file open.
  4. Side­Bar­Git (https://github.com/SublimeText/SideBarGit)
    I use Git on daily basis and hav­ing an easy and com­fort­able GUI is essen­tial. This is what this pack­age does — it pro­vides set of most often used func­tions and inte­grates it with ST2 via right-click menu.
  5. Tor­toise (on Win­dows only) (http://wbond.net/sublime_packages/tortoise)
    I use it as a com­ple­men­tary pack­age to Side­Bar­Git if I’m work­ing in Win­dows envi­ron­ment. It doesn’t have so many fea­tures but those what it pro­vide are very help­full and intu­itive.
    If you like Tor­toise Git but you are work­ing on Linux you might want to check out Rab­bitVCS. It isn’t inte­grated with ST2, but it pro­vides com­fort­able right-mouse-click Git GUI.
  6. sublime-github (https://github.com/bgreenlee/sublime-github)
    Every devel­oper should use code snip­pets of some kind. I use Gist pro­vided by GitHub and this pack­age enables me to use them instantly (save/paste).
  7. Tag (https://github.com/SublimeText/Tag)
    Great pack­age, which sim­ply takes care of all tag-matching related issues. Love it :)
  8. DocBlockr (https://github.com/spadgos/sublime-jsdocs)
    Nobody likes it, at least nobody I know, but as a devel­oper you have to main­tain solid code doc­u­men­ta­tion. This is where this pack­age helps — it pre­pares DocBlock com­ments for classes, params, meth­ods etc. Speeds up things.
  9. Phpcs (http://soulbroken.co.uk/code/sublimephpcs)
    This pack­age adds sup­port for PHP_CodeSniffer to ST2. It checks if you code is writ­ten accord­ing to one of the stan­dards. Just pick one: Zend, PEAR.. and more :) Check out PHP_CodeSniffer web­site for con­fig­u­ra­tion details.
  10. Trail­ing­Spaces (https://github.com/SublimeText/TrailingSpaces)
    Small hor­ror of every code — empty spaces at lines ends, at the end of file. Espe­cially trou­ble­some if you are work­ing on the code with other devel­op­ers, who might use dif­fer­ent editors/IDEs which might inter­pret them (empty spaces) differently.
  11. Brack­etHigh­lighter (https://github.com/facelessuser/BracketHighlighter)
    One of my favorites: clearly high­lights match­ing brack­ets, quotes etc. Just makes every­day life eas­ier when look­ing at code with mul­ti­ple brackets-in-brackets constructions.
  12. Detect­Syn­tax (https://github.com/phillipkoebbe/DetectSyntax)
    Detects syn­tax of opened file. ST2 doesn’t always get it right and this pack­ages helps.
  13. Encod­ingHelper (https://github.com/SublimeText/EncodingHelper)
    Detects and dis­plays file encod­ing and sticks to it. Help­ful in shared devel­op­ment envi­ron­ment if some­one uses for exam­ple IDE with default win­dows encod­ing instead of UTF-8.
  14. Sub­lime Func­tion Name Dis­play (https://github.com/akrabat/SublimeFunctionNameDisplay)
    Dis­plays in bot­tom bar name of a func­tion (or method) in which our cur­sor is placed. Sim­ple and helpful.
  15. Ter­mi­nal (http://wbond.net/sublime_packages/terminal)
    Using Git or maybe some PEAR pack­ages you might need to switch to con­sole from time to time and do some magic. Maybe use Zend Tool or “bake” some­thing ;) It’s just what this plu­gin is for.
  16. Xde­bug (https://github.com/Kindari/SublimeXdebug)
    Last but not least — power of Xde­bug in ST2. It brings Xde­bug capa­bil­i­ties to ST2 and enables debug­ging as most of “big” IDEs can do.

Few pack­ages I use but don’t con­sider essential:

  1. Color High­lighter (https://github.com/Monnoroch/ColorHighlighter)
    When you move your cur­sor on color def­i­n­i­tion (hex, for exam­ple) it high­lights text with this color. help­ful when writ­ing CSS.
  2. Col­or­Picker (https://github.com/weslly/ColorPicker)
    Graph­i­cal color picker. Doesn’t really need expla­na­tion, doesn’t it?
  3. Pre­fixr (http://wbond.net/sublime_packages/prefixr)
    This one is nice and I would prob­a­bly make more use of it if I were devel­op­ing more CSS :)
  4. All Auto­com­plete (https://github.com/iamnoah/Autocomplete-All)
    Enhances ST2 abil­ity to auto­com­plete by increas­ing scope to all opened files, not only one we are cur­rently in.
  5. ApacheConf.tmbundle (https://github.com/colinta/ApacheConf.tmLanguage)
    Lan­guage def­i­n­i­tions for Apache conf and .htac­cess files.
  6. Zend-Framework.tmbundle (https://github.com/ybits/Zend-Framework.tmbundle)
    Code snip­pets for devel­op­ing in Zend Frame­work. Although I do use ZF I never started to make use of these snip­pets, at least not of their full potential.
  7. Addi­tional PHP Snip­pets (https://github.com/stuartherbert/sublime-phpsnippets)
    Same here as with Zend Frame­work snip­pets. I might some day start to use more of them.

There are also pack­ages for Word­Press, Emmet (pre­vi­ous name: Zen­Cod­ing) or one mov­ing Semi­Colon out of brack­ets and many more, but I’m doing all right with­out them.

Yousuf men­tioned in com­ments that Emmet (https://github.com/sergeche/emmet-sublime) is worth men­tion­ing. It does great job speed­ing up gen­er­a­tion of HTML tags and more! If you are more of a fron­tend devel­oper than back­end, you will most likely greatly appre­ci­ate it.

13Jun/120

Zend Framework: options config file

Zend Frame­work series #1

How to use options from addi­tional con­fig ini file? Pretty easy actually :)

  1. cre­ate new file in application\configs direc­tory. Name it some­thing like extra_parameters.ini
  2. you can place here any type of options and I mean ANY:
    1. list of access lev­els of your app
    2. infor­ma­tion if debug is enabled (or other flag you wish to use)
    3. or any of avail­able Zend con­fig parameters
    4. for exam­ple:
      colors[] = blue<br />colors[] = red

      or

      <br />resources.session.name = "my_session"

      and so on, and so on... :)

  3. As you might already know Zend Frame­work rec­og­nizes var­i­ous Appli­ca­tion Envi­ron­ments, mostly used are Pro­duc­tion and Devel­op­ment, but you might want to use few of your own. Each set of options in INI file must belong to one of these envi­ron­ments. you can define it like this:
    [production]<br />; some options<br />[development : production]<br />; some more options

    By the way: you can define that one environment will inherit it's options from another, in my example "development" inherit's from "production".

  4. Now, that you have your options and para­me­ters, it’s time to get to them from our appli­ca­tion. I will access my con­fig from con­troller. It is basi­cally few lines of code and it gives you full (read) access to con­fig file, as follows:
    $options = new Zend_Config_Ini('../application/configs/extra_parameters.ini', APPLICATION_ENV);

    APPLICATION_ENV - this will make Zend read only appropriate section from config

    now in order to access particular option do something like this (if it is an array):

    $some_option = $options-&gt;your_option-&gt;toArray();

    or like this:

    $some_option = $options-&gt;your_option;
  5. And that’s pretty all. From now on you can use these val­ues as any other PHP variables/arrays, maybe pass them to the view… you options are limitless ;)
20Dec/1149

GitLab installation on Fedora 16 (with gitolite)

This is updated ver­sion of my tuto­r­ial for Git­Lab 2.1. Old ver­sion can be found here

Atten­tion: this guide seri­ously out­dated! It has been writ­ten for Git­lab v2.1 and cur­rent ver­sion is >= v7.1.1. Almost every­thing has changed since then.

Git­Lab is a won­der­ful piece of soft­ware made by these guys and I’d like to try and install it on Fedora 16 sys­tem, as it is most recent Fedora OS at the time I am writ­nig this. I will base my tuto­r­ial on on found here by Déja. Also on my way to suc­cess­ful install I’ve stum­bled upon this descrip­tion, so I might have gain some expe­ri­ence from it too.

Git­Lab is Ruby on Rails appli­ca­tion and it takes some expe­ri­ence to get it all work­ing because of many, many, many depen­den­cies and pack­ages it needs. It’s noth­ing like sim­ple PHP on Apache instal­la­tion. But it works and it’s worth it, I assure you :)

Let’s begin! (by the way: I per­form all as root user — again: test environment)

small edit: For peo­ple who only want this to work and not nec­es­sar­ily wish to know how and why, I have pre­pared easy instal­la­tion scripts in here
another EDIT: Git­Lab is under heavy devel­op­ment and now it’s sta­ble ver­sion is 2.1. This means that my guide might be not entirely accu­rate. Please be cau­tious. I’ll update it soon.
  1. First of all: I am work­ing on vir­tual machine with brand new and fresh Fedora 16 installed. Min­i­mal instal­la­tion, just to make sure noth­ing messes with Git­Lab. Con­sider this a test environment.
  2. Once you have your OS ready, update it with yum update and also install some pack­ages you will need on the way:
    yum install make openssh-clients gcc libxml2 libxml2-devel \
    libxslt libxslt-devel python-devel
  3. Check what ver­sion of ruby is avail­able via yum. Git­Lab needs at least ver­sion 1.9.2
    yum info ruby

    on mine it says that the only avail­able ver­sion for me is 1.8.7.357 so I have to get it some­where else.

  4. Using RVM to install Ruby.
    EDIT: I have switched to ruby 1.9.3p0 — it works and starts a lot faster, you can use it instead of 1.9.2-p290 in this guide.

    I will use RVM, which stands for Ruby Ver­sion Man­ager — bril­liant tool, which you can use to install and man­age your Ruby with ease. Let’s check it out, shall we? (you can install Ruby any way you want — I’ll just do this RVM way)

    Notice use of –with-openssl switch — with­out that pas­sen­ger will com­plain about Ruby OpenSSL sup­port and won’t com­pile in next step.

    sudo bash -s stable < <(curl -sk https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)
    
    source /etc/profile.d/rvm.sh
    
    rvm install ruby-1.9.2-p290 --with-openssl
    
    rvm use ruby-1.9.2-p290 --default
    

    Done. Just like that we have oper­a­tional Ruby 1.9.2-p290. No RPMs, no going back in time.. nice, huh? :)

  5. Good. Small (nice) sur­prise: our RPM installed ruby gems for us, so now we only have to get rails gem.
    first, just to make sure every­thing is up to date, execute:
    rvm all do gem update --system

    now install rails with:

    rvm all do gem install rails
  6. Now we will install apache2 as a web­server and Pas­sen­ger for ruby apps deploy­ment. I know that most Git­Lab tuto­ri­als use nginx but I really like apache ;)
    yum install -y httpd
    rvm all do gem install passenger

    as I men­tioned: I use apache, so I will need pas­sen­ger mod­ule for it:
    first some required packages:

    yum install -y gcc-c++ curl-devel openssl-devel zlib-devel \
    httpd-devel apr-devel apr-util-devel

    an then use

    passenger-install-apache2-module

    in order to install it.it gives you 2 infor­ma­tion on how to pro­ceed with apache configuration:

    • add fol­low­ing lines to /etc/httpd/conf/httpd.conf (at the very end):
      LoadModule passenger_module /usr/lib/ruby/gems/1.9.1/gems/passenger-3.0.11/ext/apache2/mod_passenger.so
      PassengerRoot /usr/lib/ruby/gems/1.9.1/gems/passenger-3.0.11
      PassengerRuby /usr/bin/ruby
      
    • and then cre­ate file named default.conf (or gitlab.conf, or some­thing other you like) in /etc/httpd/conf.d/ con­tain­ing these lines (remem­ber to change to fit your environment):
      <VirtualHost *:80>
      ServerName www.yourhost.com
      DocumentRoot /somewhere/public
      <Directory /somewhere/public>
      AllowOverride all
      Options -MultiViews
      </Directory>
      </VirtualHost>
      

      (don’t worry, we’ll come back to this one later)

  7. Now it is time for gito­lite. I won’t use gito­sis because it is not actively devel­oped any more and I found that new Git­Lab works bet­ter with gitolite.install it with
    yum install -y gitolite

    now, wasn’t that quick? :)

  8. Now we will need to cre­ate new gito­lite server con­fig­u­ra­tion and in order to do that we have to gen­er­ate SSH key-pair. But first things first.
    To get us started we will cre­ate git user with

    adduser -r -m --shell /bin/bash \
     --comment 'git version control' git
    mkdir /home/git/.ssh
    chown git:git -R /home/git/.ssh
    

    Now we have to cre­ate SSH keys pair for him:

    ssh-keygen -q -o -N '' -t rsa -f /home/git/.ssh/id_rsa

    To ini­tial­ize Gito­lite we need to first edit it’s default con­fig­u­ra­tion file and change default per­mis­sions and then ini­tial­ize it by using git user:

    sed -i 's/0077/0007/g' /usr/share/gitolite/conf/example.gitolite.rc
    
    su - git -c "gl-setup -q /home/git/.ssh/id_rsa.pub"

    as men­tioned here

  9. Just to make sure that git user has all nec­es­sary access rights to his own home direc­tory after we have added SSH keys for him:
    chown git:git -R /home/git/
  10. OK, time for next require­ments: python Pip, I will go with method from orig­i­nal post and NOT use yum for that.
    curl http://python-distribute.org/distribute_setup.py | python
    

    and then

    easy_install pip
    
  11. Data­base. We need it. We have it already — it was installed on the way as a depen­dency. Just to make sure check if you have SQLite at list ver­sion 3.6 with:
    yum info sqlite

    I have 3.7.7.1. All we need is SQLite devel­op­ment pack­age, get it with:

    yum install -y sqlite-devel
  12. And now the main event! GitLabHQ!

    I like install web apps in /var/www so we will go there and git clone GitLab:

    cd /var/www
    
    git clone git://github.com/gitlabhq/gitlabhq.git
    
    cd gitlabhq/
    

    we need to use pip to install some python dependencies:

    pip install pygments

    and bundler gem so it can later on do most of the work for us:

    rvm all do gem install bundler

    you will need one more depen­dency for bun­dle install

    yum install -y libicu-devel

    finally (remem­ber to be in Git­Lab direc­tory):

    bundle install

    (go get your­self a cof­fee or other treat — it takes a while)

  13. Redis instal­la­tion. More about Redis here
    yum install -y redis

    and start it with:

    service redis start
    
  14. Prepar­ing con­fig files.copy data­base and git­lab con­fig files from exam­ple to work­ing copies:
    cp config/gitlab.yml.example config/gitlab.yml
    cp config/database.yml.example config/database.yml
  15. DB setup:
    And now data­base setup and import:
    RAILS_ENV=production rake db:setup
    RAILS_ENV=production rake db:seed_fu
    

    TIP: if you get errors here, check if you don’t have 2 ver­sions of rake installed (I had some­how): 0.8.7 and 0.9.2. If you do, remove older with:

    gem uninstall rake

    and choose appro­pri­ate ver­sion. If you still have prob­lems try:

    gem install rake

    -> don’t know why, but if it installs again same ver­sion of rake, it works.

  16. Apache vir­tual host con­fig­u­ra­tion should look some­thing like this (I told you, we will get back to that):file: /etc/httpd/conf.d/gitlab.conf
    <VirtualHost *:80>
    ServerName www.yourhost.com
    DocumentRoot /var/www/gitlabhq/public
    <Directory /var/www/gitlabhq/public>
    AllowOverride all
    Options -MultiViews
    </Directory>
    </VirtualHost>
    
  17. enable apache user, co you can su into this account:
    usermod -s /bin/bash -d /var/www/ apache

    pre­pare SSH key for him (actu­ally use one cre­ated for git user)

    mkdir /var/www/.ssh
    
    cp -f /home/git/.ssh/id_rsa /var/www/.ssh/ && chown apache:apache /var/www/.ssh/id_rsa && chmod 600 /var/www/.ssh/id_rsa
    

    add local­host to apache user known_hosts with:

    ssh-keyscan localhost >> /var/www/.ssh/known_hosts

    also give him per­mis­sions to his own home direc­tory with:

    chown -R apache:apache /var/www/

     

  18. add apache user to git group with:
    usermod -a -G git apache
  19. check if repos­i­to­ries direc­tory has cor­rect per­mis­sions, it should be 770. You can set it with
    chmod 770 /home/git/repositories/
  20. dou­ble check your fire­wall (for exam­ple ipt­a­bles) if it allows con­nec­tions on port 80 to your server.
  21. impor­tant: Apache won’t be able o start with SELinux set to “enforc­ing”. Please set it to permissive.
  22. start apache server with:
    service httpd start
  23. Now it all should work. Fin­gers crossed.. go to http://www.yourhost.com
  24. Now you should be able to log in using these cre­den­tials:

    user: admin@local.host
    pass: 5iveL!fe

    and you’re in :)

It wasn’t so hard, wasn’t it? ;)

Trou­bleshoot­ing:

  1. I get error 500 when I enter par­tic­u­lar project and try to get into it’s “Admin” sec­tion. Don’t know how to fix it yet.To fix it, check if repos­i­to­ries direc­tory has cor­rect per­mis­sions, it should be 770. You can set it with
    chmod 770 /home/git/repositories

    also set this:

    chmod 770 /home/git
  2. If Pas­sen­ger insists, that we don’t have or he can’t see grit library (gem actu­ally, as far as I know) even though we have it.

    https://github.com/gitlabhq/grit.git (at mas­ter) is not checked out. Please run ‘bun­dle install‘ (Bundler::GitError)

    Only res­o­lu­tion to this prob­lem I have found is to (as root) change /usr/local/rvm/gems/ruby-1.9.3-p0/gems own­er­ship to apache user with:

    chown apache:root -R /usr/local/rvm/gems/ruby-1.9.3-p0/gems

    I know that is not great res­o­lu­tion but it worked for me. If you’ll hap­pen to know bet­ter way — please let me know, so I can update this tuto­r­ial and my knowl­edge of course ;)

    Edit

    I found another solu­tion (instead of chang­ing per­mis­sions): after first

    bundle install

    edit Gem­file and in lines con­tain­ing “git:” remove every­thing after first comma, for example:

    gem "grit", :git => "https://github.com/gitlabhq/grit.git"

    should be

    gem "grit"

    and so on.

    then do again

    bundle install

    and now pas­sen­ger shouldn’t com­plain any more.

Return to Top ▲Return to Top ▲