Monday, 3 August 2015

Building PHP from source on Ubuntu 15.04

I was working on a project which required that I play around with threads in PHP. I am a recent convert to PHP so you can imagine my surprise to find out that PHP had threading support via pthreads. There was a catch though. PHP would have to be compiled with zend-thread safety enabled. So here's a walk-through on how that came along.

Uninstall PHP

Easily done (P.S. uninstalling is always the easy bit)

sudo apt-get remove php5-*

sudo apt-get purge php5-*


Get PHP

Simple head here to pick the version of PHP you want. I got version 5.6.11 (latest one at the time)

 wget -P ~ http://uk1.php.net/distributions/php-5.6.11.tar.gz


(replace url with url of preferred php install)

Fulfill all the dependencies

One thing I have learnt while doing the configure;make;make install process is that not having all the dependencies can be a real bummer. So you would want to make sure you have got them all.

You can check for the dependency list here. Also make sure that the dependency versions you install are compatible with those mentioned in the list.

This is the command to install all the dependencies needed:

sudo apt-get install \

libxml2-dev \

libcurl4-openssl-dev \

libjpeg-dev \

libpng-dev \

libxpm-dev \

libmysqlclient-dev \

libpq-dev \

libicu-dev \

libfreetype6-dev \

libldap2-dev \

libxslt-dev \

libreadline6-dev \

libmcrypt-dev \

autoconf \

automake \

libtool \

re2c \

bison


Installation:

If you have ever done any installation by compiling from source and suddenly you wish to uninstall the application then you would know it can be a real painstaking process to get the application out. If we had installed via APT, a simple apt-get purge/remove would have done the trick but no such luck for source installs.

To uninstall you would have to manually delete all the files and folders created by the installation process and God help you if you do not remember where they all were. (P.S. by default, the make installation method usually uses the /usr/local/ directory)

In view of this we would be using stow. Stow manages this whole process by giving a common tree where all the files get installed and then when you are ready it creates  a symlink from the stow directory to the target tree i.e. /usr/local/.

To install stow (we would not be building it from source *sigh*)

sudo apt-get install stow


You should now have a /usr/local/stow directory. Now we can get on with our installation.

Extract the tarball
cd ~
tar -xvJf  php-5.6.11.tar.gz
cd ~/php-5.6.11/


Next we configure, this was my configuration command (Note you should run this as a regular user and not sudo)

./configure \

  --prefix=/usr/local/ \

  --with-apxs2=/usr/bin/apxs \

  --enable-mbstring \

  --with-curl \

  --with-openssl \

  --with-xmlrpc \

  --enable-soap \

  --enable-zip \

  --enable-sockets \

  --enable-opcache \

  --enable-pcntl \

  --with-pdo-mysql \

  --with-pdo-pgsql \

  --with-readline \

  --enable-zip \

  --enable-mysqlnd \

  --with-pear \

  --with-gd \

  --with-mcrypt \

  --with-jpeg-dir \

  --with-png-dir \

  --with-mysql \

  --with-pgsql \

  --enable-embedded-mysqli \

  --with-freetype-dir \

  --enable-intl \

  --enable-maintainer-zts \

  --with-xsl \

  --with-config-file-scan-dir=/usr/local/lib/php/conf.d


Now we can run :
make

and finally

sudo make install prefix=/usr/local/stow/php56


When this is done, the directory /usr/local/stow/php56 would not contain all our php installation files.

Now we 'stow' it:

cd /usr/local/stow
sudo stow php56

and tada

php -v

PHP 5.6.11 (cli) (built: Aug  4 2015 02:48:50)

Copyright (c) 1997-2015 The PHP Group

Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies

And it's a wrap!

Wednesday, 8 July 2015

Setting up Open Broadcasting Software on Ubuntu

Introduction:

Open broadcasting software (OBS) is one of those really awesome tools out there for streaming video from your PC.

You can find out more information about them from this link.

Installation:

First things first, make sure you've got the required hardware (I found this out the hard way)

Install mesa-utils like so:

sudo apt-get install mesa-utils


after that run the command below:

glxinfo | grep OpenGL

Check the resulting string for your Open GL version, OBS requires that you have Open GL >= 3.2

If you don't, then you will have to change your GPU .

If you are among the chosen, and your system is good to go, next step is to install some dependencies.

OBS requires ffmpeg and so if you do not already have it installed, I suggest you hit this link for a guide.

Now with ffmpeg installed, the next step would be to install OBS.

Add the OBS ppa like so

sudo add-apt-repository ppa:obsproject/obs-studio


Then:

sudo apt-get update && sudo apt-get install obs-studio


When I did this, I got this error:

Depends: libavcodec-ffmpeg56 (>= 7:2.4) which is a virtual package. 

Depends: libavdevice-ffmpeg56 (>= 7:2.4) which is a virtual package.

Depends: libavfilter-ffmpeg5 (>= 7:2.4) which is a virtual package.

Depends: libavformat-ffmpeg56 (>= 7:2.4) which is a virtual package.

Depends: libavutil-ffmpeg54 (>= 7:2.4) which is a virtual package.

Depends: libswresample-ffmpeg1 (>= 7:2.4) which is a virtual package.

Depends: libswscale-ffmpeg3 (>= 7:2.4) 


Quick fix, you need to add the universe source to your list of sources, so edit the /etc/apt/sources.list file and add this line at the end of the file:

deb http://us.archive.ubuntu.com/ubuntu vivid main universe

Then the usual:

sudo apt-get update && sudo apt-get install libavcodec-ffmpeg56

And you can install obs-studio like so:

sudo apt-get install obs-studio
And you're good!

Installing FFMpeg in Linux (Debian and Ubuntu)

So this was surprisingly easy. I had tried to do this a few months back (a method that involved building from source *weeping*  *sobbing hysterically*)

The FFMpeg guys (God bless their souls) have an excellent guide on their website.

For Debian:

The instructions are here:

Basically follow these steps:

1. check your debian version ( cat /etc/debian_version)

2. Depending on your debian version ( squeeze = Debian 6, wheezy = Debian 7, jessie = Debian 8), add one of the sources  given in this link to your /etc/apt/sources.list file.

3. As at the time of writing this, the maintainer of the repository had some issues with his GPG key, so as instructed by him, run the following first

wget http://www.deb-multimedia.org/pool/main/d/deb-multimedia-keyring/deb-multimedia-keyring_2015.6.1_all.deb

and

sudo dpkg -i deb-multimedia-keyring_2015.6.1_all.deb

Then
sudo apt-get update

and finally
sudo apt-get dist-upgrade

With this all done you can now run (with peace of mind):

sudo apt-get install ffmpeg

And that's it, you're good to go.

NOTE: This was pretty straightforward(maybe too easy even), I am still observing to see if any issues come up.

For Ubuntu:

Basically add the Ubuntu Multimedia PPA like so:


sudo add-apt-repository ppa:mc3man/trusty-media


Then update and upgrade like so:
sudo apt-get update && apt-get dist-upgrade

And finally like before:
sudo apt-get install ffmpeg


And that's all.
God bless the FFMpeg guys for some detailed instructions!

Monday, 6 July 2015

Password Protect specific URL with htpassword

So I found this on stackoverflow here.

But here is the gist:

Enable your mod_auth, and mod_env apache modules and add the following apache directives to the Directory section of your virtual host configuration:


# Do the regex check against the URI here, if match, set the "require_auth" var
SetEnvIf Request_URI ^/pretty/url require_auth=true

# Auth stuff
AuthUserFile /var/www/htpasswd
AuthName "Password Protected"
AuthType Basic

# Setup a deny/allow
Order Deny,Allow
# Deny from everyone
Deny from all
# except if either of these are satisfied
Satisfy any
# 1. a valid authenticated user
Require valid-user
# or 2. the "require_auth" var is NOT set
Allow from env=!require_auth

And reload your apache and you are a go

Tuesday, 23 December 2014

THE NEW YEAR BECKONS

I will take a short tech-blog break and ponder (hopefully philosophically) on the year in retrospect and for posterity sake (at the very least) put down in ink (or html, whichever you like) what my targets for the new year would be.

This year has been one of the most eventful years of my life. From participating in the Shell Eco-Marathon in Rotterdam to completing my final exams in the University of Lagos. There has never been a shortage of interesting activities which have occupied my time this year.

However, this post is not about the fine details about my accomplishments but an overview on what I have been able to achieve in 2014.

At the start of the start of the year, I wanted to be a more efficient person, more time conscious, more effective. I also wanted to "live a little" ( I have been accused of being too rigid). In retrospect I have found out that being a more efficient person is more than having TODO lists for every single day. I am still learning, will get there eventually.

I am an African and as such also very religious. This year however I got more spiritual and alot of that was as a result of joining Opus Dei.

I had an awesome year with awesome friends +David Emukpere +Paula Aliu +Abraham Imohiosen   and met new friends +Victor Adegboye, +omijie emmanuel osas

Most importantly however as the final curtain closes on the year, I have been challenged. There is no room to be inept, no room to be ineffective. There is only results. They speak louder than words. This challenge forms the basis on which my target for 2015 is based.

Whatever must be done this year, must be done with perfection. No excuses, none whatsoever. It's a long walk to freedom, but one which I would walk.

Merry Christmas and a happy new year in advance!

Sunday, 21 December 2014

Android Quickies

With the amount of free time I "apparently" have on my hands, I have finally been able to dabble more into android programming. This blog will be a collection of some short lines which I have found useful.

Updating an ArrayAdapter for a list view


            ArrayList newData = new ArrayList(Arrays.asList(jsonString));
            myData.clear();
            myData.addAll(newData);
            myArrayAdapter.notifyDataSetChanged();
And that takes care of that!


ACTION BAR IN SETTINGS ACTIVITY

Typically, Settings activity extends a Preference Activity. However, for easy addition of the action bar, activities extend the ActionBar activity. You cannot extend more than one class in Java which means that if you are using the Preference activity method you will have to find a hack to hook up the action bar to your Settings activity. There a few workarounds.

If you are targeting android 3.0 and above (quite frankly, I see very little reason why you would be targeting anything less) then you should use PreferenceFragments and attach it to an activity which extends ActionBar activity. A description is given here in the android Docs.

If you are still bent on supporting other devices,..., well I have not figured that out yet. When I do will let you know. If you have please do post a comment.

Wednesday, 17 December 2014

Helpful Linux Terminal Commands

Okay, so I would be compiling a list of helpful linux commands for getting you out of that jam in no time.

REPAIRING A CORRUPT ZIP FILE

You have downloaded a large zip file, with possibly several files in the archive but your Internet connection decides to mess up at the last minute and so a few files at the end have not been downloaded. As a result, there is an end of file (EOF) error and you would have to start all over again.

Well with a simple command you can at least get the files which were completely downloaded with this command:

zip -FF Corrupted.zip --out New.zip
and now you can extract em, good luck!


INSTALLING A .deb FILE FROM COMMAND PROMPT


sudo dpkg -i "file"

CHECKING YOUR FORMATTED DISK SPACE

df -h

RUNNING A COMMAND AS ANOTHER USER (SOURCE)

sudo -H -u otheruser bash -c 'echo "I am $USER, with uid $UID"' 

Sunday, 14 December 2014

Setting Up VIM for Python Code Testing

Hello guys,

So I have got a bit more time on my hands which would mean that I can be doing this alot more often.

I will quickly show how to set up auto-complete features for python on the vi editor in Linux (I am running Ubuntu Gnome 14.04).

First things,

Get Vundle (It's a package manager for vim). The link is here. Follow all the instructions on the page, it is quite detailed.

Next up, head over to the github site here and add this to the .vimrc file and then add it to the plug-ins to be installed. And that is all.

Thank you!

Thursday, 13 February 2014

TESTING CODE HIGHLIGHTER ON BLOGGER

So I have finally decided that instead of building my own stuff from the ground up, I can just use what is there and overcome some inertia. So this is my first post.


def hello():
  print 'hello world!, boy am i glad'