Monday, September 23, 2013

Installing Alternative PHP Cache (APC) on OSX.

`APC` is an opcode cache for optimizing PHP performance. Here is the steps to install it on Mac.

1. Create a src directory [Optional].
*$ cd /usr/local/
$ mkdir src
$ cd src*
2. Download `PCRE`, the `APC` requires `PCRE` libraries and header files.
curl -O ftp://ftp.csx.cam.ac.uk//pub/software/programming/pcre/pcre-8.31.tar.gz
3. Unzip the downloaded file.
tar -xvzf pcre-8.31.tar.gz
4.Install `PCRE`.
*$ cd pcre-8.31
$ ./configure
$ make
$ sudo make install*
5. Install `APC`.
sudo pecl install apc
6. Put the following line into the end of `php.ini` file.
extension=apc.so
7. Make sure that you have completely install `APC`.
php -m | grep apc  #should return "apc"

Installing "intl" extension on OSX.

1. Normally, the PHP is automatically installed on OSX. So, if you would like to use the XAMPP, or whatever apache server, you must change the path point to XAMPP. You can check the path by using:
$ which php
You should get
/Applications/XAMPP/xamppfiles/bin/php 
if not, you will get
/usr/bin/php. 
This is OSX' php. So, you have to change it by using:
$ PATH="/Applications/XAMPP/xamppfiles/bin:${PATH}"
2. Now, it's time to install `intl`. Firstly, you need to install `icu4c`
$ brew install icu4c
It takes a couple of times and returns its path to you, should look something like this:
/usr/local/Cellar/icu4c/x.x.x 
3. Next, let's install `intl` by using `pecl`
$ sudo pecl update-channels 
$  sudo pecl install intl 
It will prompt you to put the `icu4c` path.
After finish installing `icu4c`, put the following statement to `php.ini`
extension=intl.so 
4. Restart apache. and check whether it's neatly installed.
$ php -m | grep intl #should return 'intl'
That's it!

Tuesday, September 3, 2013

Composer - Dependycy Management

Composer is a tool for dependency management in PHP. It allows you to declare the dependent libraries your project needs and it will install them in your project for you.

After install something by Composer, DONT FORGET to run the following command:
$ php composer.phar update
Otherwise, it will not reflect the change. Moreover, you can update a specific environment by adding , for example, --dev to the end of command.

Symfony2: YUI_Compressor

YUI compressor is used to compress files, for example javascript and css files, into minified.
When it is used with symfony2, sometimes it doesn't work even though you correctly add it.
In this case, the app/console command is provided to help you solve the issue. It is used to directly generate the minified.
$ php app/console assetic:dump --env=prod  

The result will show up the number of minified files. Moreover, you can let it show the progress by adding the -v at the end of command, it should be looked like this: 
$ php app/console assetic:dump --env=prod -v

The -v shows more details about the process of compression, you can see if there is an error which causes problems with yui compressor, and fix it!