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!