Adding a directory to PATH in Mac

To see if a directory is in PATH:

$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

Note that directories are separated by : symbol. To add your directory to the path, edit your bash_profile:

$ vi ~/.bash_profile

Add the following line of code, assuming you want to add /usr/local/mysql/bin to the PATH

export PATH="/usr/local/mysql/bin:$PATH"

Save your changes. Close your terminal. Open a new terminal. Your directory should be in PATH

PHP package managers

PHP has seemingly countless extensions and packages. See http://www.packagist.org to see the list of packages. Naturally, you would wish to have a software to manage the extensions and packages. Wish granted! PEAR, PECL, and composer are PHP package managers.

PEAR

PEAR was the first PHP package manager. It is designed for systemwide packages so anytime you install a package through PEAR, it is installed in a central repository. The scripts and commands become available from anywhere on the commandline.

PECL

PECL manages compiled extensions to PHP.

Setting up virtual lamp stack on microsoft windows

Oracle's VirtualBox is a very solid and stable virtual machine but it isn't the simplest to work with. So I abandoned it a week after I started working with. Recently, I had to return. Why? Vagrant. It is a fantastic virtual machine workflow system. It is amazingly easy to use and deals with VirtualBox for you. On top of that there are many excellent stack available for free download from the Internet. Following is how I setup my LAMP stack.

apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

###Problem###
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName

###Solution###
This is not an error, only a warning.

To fix this in Ubuntu 12.04 LTS, type the following:

$ echo "ServerName localhost" | sudo tee /etc/apache2/conf.d/fqdn
ServerName localhost
$ sudo service apache2 restart

To fix this in Ubuntu 14.04 LTS, type the following:

echo "ServerName localhost" | sudo tee /etc/apache2/conf-available/fqdn.conf
sudo a2enconf fqdn

Creating csv files using PHP

It is very easy to create a csv file using PHP. All you need to do is create a two dimensional array of data and call fputcsv() function.

$aa = array( array ('a', 'b'), array('1 ', '2'));
$fh = fopen('file.csv', 'w');
foreach ($aa as $a) { fputcsv($fh); }
fclose($fp);

This script create nice csv files even in you have quotes in the file.

Make sure your script has sufficient directory permission to create the file and populate it.

Pages