Linux, Web Development

Making npm work on a Cifs/Windows Share

I spent the last 5 hours trying to work out why I couldn’t use npm install for bootstrap in a cifs partition.

Turns out some has had this problem and posted a fix: http://askubuntu.com/questions/269727/npm-errors-when-installing-packages-on-windows-share

npm install --no-bin-links

This is since on a cifs partition npm will actually bail out with chmod when trying to set symlinks for the modules that it cannot due to you using a Windows share.

Linux

How to change Window Control positions in Ubuntu 10.04

So I finally got the time to download Ubuntu 10.04 only to find that when I downloaded it my window controls shifted from the right to the left…why, why did the Ubuntu team do that? Making Linux look like a Mac ain’t a good thing and I would like to think the most heated debate on the Ubuntu forums right now is: “WHY THE FUCK HAVE YOU COPIED THAT SHITTY MAC OS?”.

But anyway a deep breath and spurt of Googling later I found this:

Free Trader Beowulf – Ubuntu 10.04 – Window Controls

This article, at the bottom, will tell you exactly how to change your Unix back into a Linux :). Enjoy.

Linux, MySQL, PHP

Beginners Guide to LAMP server Setup

LAMP – Linux Apache MySQL PHP server which can often have parts of the removed for other languages such as Perl or Prostge SQL but most commonly known as Linux Apache MySQL and PHP.

Lamp is the first letter combination of the build up of a typical Linux based server. In this tutorial we will learn how to set-up one of these server and get it working properly.

Tutorial Warning

This tutorial does not follow through Apache or PHP security protocols and although it might be fine on a normal server that would host, say, a video site I would not recommend this guide for commercial set-ups which require absolute security.

As another note this is under Ubuntu 9.04 and most Ubuntu versions are the same interface-wise, however, the instructions may differ from different distros and even Operating Systems.

First things first you must install Apache, so terminal:

sudo apt-get install apache

After that follow this tutorial here (Okay, so I could have actually wrote the tutorial but I like this tutorial so I thought I would link this instead =]).

Okay, so you have just followed the tutorial I linked and came back here, good. You are now ready to begin everything else since setting up Apache is only a fraction of the process. We will immediately move onto PHP and MySQL installation.

Both of these can be download from the universe just:

sudo apt-get install mysql-server
sudo apt-get install php5

At some point throughout the PHP installation you will be asked to state which server PHP is being installed to, just say Apache 2.x (or 2.2 as it’s sometimes stated). There is also a stoppage within the MySQL set-up when the installer asks for a password, if you try enter a slightly secure yet memorable password then it should be okay.

Now just open phpmyadmin (localhost/phpmyadmin) and enter root as the user and your password you entered on the MySQL set-up. You should now see the database server and the databases upon it. If you don’t just drop a comment and I’ll get back to you.

Wooo, you have the actual server set-up, not that hard was it. Now we need to set-up the environment itself with extensions and such like, all of these are optional, however useful.

PHP PEAR:DB

What is PEAR:DB? DB is a database abstract layer. Still a bit confused? Okay, basically imagine your PHP code with the SQL in it, underneath that is the SQL server right? Wrong, DB acts as a layer between those taking in standardised functions and spitting them out as database queries only difference is that DB can spit these queries out for almost every main stream server out there.

This means in layman’s terms that you would never have to rewrite SQL code so long as you live and not only that you get some pretty cool functions that make your life so much easier. I love easy, I never have time for hard.

To install DB simply type into terminal:

sudo apt-get install php-db

Once this is completed you have the extension. Now you need an example along with a little bit of a tutorial on how to use this extension.

I have decided to explain the rest of this section in a new post. It is a bit long to post here.

PHP mcrypt

PHP mcrypt controls encrytion within any PHP script. To install this extension simply type:

sudo apt-get install php5-mcrypt

Then for its usage:

	function linEncrypt($pass) {
		$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
		$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); //Creating the vector
		$cryptedpass = mcrypt_encrypt (MCRYPT_RIJNDAEL_256, $this->mykey, $pass, MCRYPT_MODE_ECB, $iv);
		return $cryptedpass;
	}

Most of the things here are just default in built commands, except for $mykey. This is a key that the encrypt-or uses to encrypt with (i.e. “S3M_LL4N”). Except for the key everything else is pretty much set default for my basic RIJNDAEL encryption.

Smarty

This has already been written here

uploadprogress

An essential user friendly function for any website which requires an upload page. This extension will effectively allow the developer to track the progress (all the details, even remaining seconds) of an upload.

For an accurate description on it’s usage and such like check out this page. In this section I will hopefully go over the basics of installing the upload progress function. There is an advanced tutorial for readers who are looking for something more intensive to do with this extension.

Okay, first we need to download and install the package. If you enter:

sudo pecl install uploadprogress

I found that for some reason sometimes you need sudo and sometimes you don’t (I am unsure as to the reason this is). You will find that when you first install there will be missing packages and the installer will fail. So to fix this problem we simply:

sudo apt-get install php5-dev

If you are running a server version you may also be missing make package but that one is simple, the phpize command is not instantly understandable (due to it actually being in package: php5-dev). After you have run the uploadprogress setup correctly without faults you will see the uploadprogress extension on your phpinfo(); page and this will signify you are ready to use the extension.

Ffmpeg

Ffmpeg is perhaps one of the greatest thumb nailing extensions for PHP in existence. it is not the only one but it’s the only one that has done exactly what I want it to have done without exploding.

Now to install Ffmpeg simply type:

sudo apt-get install ffmpeg

And to test do this:

ffmpeg

The result should be:

FFmpeg version 0.5-svn17737+3:0.svn20090303-1ubuntu6, Copyright (c) 2000-2009 Fabrice Bellard, et al.
  configuration: --enable-gpl --enable-postproc --enable-swscale --enable-x11grab --extra-version=svn17737+3:0.svn20090303-1ubuntu6 --prefix=/usr --enable-avfilter --enable-avfilter-lavf --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-pthreads --disable-stripping --disable-vhook --enable-libdc1394 --disable-armv5te --disable-armv6 --disable-armv6t2 --disable-armvfp --disable-neon --disable-altivec --disable-vis --enable-shared --disable-static
  libavutil     49.15. 0 / 49.15. 0
  libavcodec    52.20. 0 / 52.20. 0
  libavformat   52.31. 0 / 52.31. 0
  libavdevice   52. 1. 0 / 52. 1. 0
  libavfilter    0. 4. 0 /  0. 4. 0
  libswscale     0. 7. 1 /  0. 7. 1
  libpostproc   51. 2. 0 / 51. 2. 0
  built on Apr 10 2009 23:18:41, gcc: 4.3.3
At least one output file must be specified

Ok so you have the extension now you need an example of its usage:

$comm = 'ffmpeg -itsoffset -00:01:15 -i "/home/sam/inetpub/htdocs/the_stage/'.$filePath.'" -vcodec png -vframes 1 -an -f rawvideo -s 800x600 "/home/sam/inetpub/htdocs/the_stage/upload/'.$randThing.'.png"';
									system($comm);

$comm string forms a system command, a terminal command and system() executes that command. You can always use a different command which will allow you to return an object like an array:

									$command = sprintf('ffmpeg -i "/home/sam/inetpub/htdocs/the_stage/'.$filePath.'" 2>&1');
									exec($command,$output);

But let’s get back to the example. You should notice that in the example I am actually grabbing a image of the film (frame) at 1 min and 15 seconds and saving it to a png file. You always start every command with ffmpeg and then build on the commands from there. Now the actual example is quite easy and straight forward to explain. I set a parameter of time (00:01:15) and a video file (-i “blah/blah/$file.divx”), set certain codec and image size (800×600) and then state the path and name of the file (blah/blah/blah/$file.png).

Ffmpeg is in fact very simple once you understand the basic format of commands. Most of the complicated looking parameters are just instruction saying what image format I want and stating default codec to open the video with. Anyway now you have had a small taste of Ffmpeg.

Linux

Patching Wine from Source

Not many people seem to know this, however, it is relatively easy once you get the hang of it. Imagine you have just downloaded a patch (.diff/.patch) for Wine and don’t have a clue where to start with patching Wine yourself. This tutorial will teach you how to do exactly that.

I will using this wine tutorial with some additional little tips and tricks to deliver a complete and thorough tutorial.

Now if you are doing this for the first time you will need to follow this initial step. Punch this into terminal and run it:

sudo apt-get build-dep wine //gets the dependencies required to compile wine
sudo apt-get install make //gets the (not default installed) make "program" which compiles the actual source code

Note: Once these two lines have been run once they will never need to be run again.

We now continue with downloading the wine source code: http://sourceforge.net/projects/wine/files/Source/. On the page this link relocates to you will see a list of files and folders. To choose the correct one simply choose the version you want and download the .tar.bz2 and NOT the .tar.bz2.sign. If you download the .sign file you will not get the actual source code.

Now after you have downloaded the .tar.bz2 extract it to, say, your home folder so the path will look something like: “/home/someone/wine-1.1.32”. After the extraction is complete download and save the patch into the Wine source code directory (i.e. “/home/somoneone/wine-1.1.32/SetPixelShader.patch”).

Note: if you open up the patch in, say, a web browser from Wine HQ or a similar site then simply do right click->save page as and the page will save correctly.

After you have the patch saved within the Wine source code directory simply cd in terminal there:

cd /home/someone/wine-1.1.32

After you have changed the directory simply run in terminal:

patch -p1 < SetPixelShader.patch

This will display a progress of “hunks” installing. After this is completed you may proceed to configure, compile and install the new Wine. In order to do that you must run the next three commands (within the same terminal window, if you close that terminal window open a new one and cd to the Wine source code directory):

./configure
make depend && make
sudo make install

These commands may take sometime depending on how big the patch you applied was and how many patches that were applied since last compile. Once make install is completed your Wine is ready to be used. Enjoy :).

PS. Almost forgot; to uninstall simply cd in terminal to the wine source code directory (i.e. “/home/someone/wine-1.1.32”) and run:

sudo make uninstall