Make sure you had homebrew. If not yet, head over http://mxcl.github.com/homebrew/ and install it.
Then you need to install: pcre, libjpeg, mcrypt.
brew install pcre
brew install libjpeg
brew install mcrypt
Download PHP5.4 on PHP.net. Extract then come into that folder:
</div> <div>./configure \</div> <div id="LC2">--prefix=/usr \</div> <div id="LC3">--mandir=/usr/share/man \</div> <div id="LC4">--infodir=/usr/share/info \</div> <div id="LC5">--sysconfdir=/private/etc \</div> <div id="LC6">--with-apxs2=/usr/sbin/apxs \</div> <div id="LC7">--enable-cli \</div> <div id="LC8">--with-config-file-path=/etc \</div> <div id="LC9">--with-libxml-dir=/usr \</div> <div id="LC10">--with-openssl=/usr \</div> <div id="LC11">--with-kerberos=/usr \</div> <div id="LC12">--with-zlib=/usr \</div> <div id="LC13">--enable-bcmath \</div> <div id="LC14">--with-bz2=/usr \</div> <div id="LC15">--enable-calendar \</div> <div id="LC16">--with-curl=/usr \</div> <div id="LC17">--enable-dba \</div> <div id="LC18">--enable-exif \</div> <div id="LC19">--enable-ftp \</div> <div id="LC20">--with-gd \</div> <div id="LC21">--enable-gd-native-ttf \</div> <div id="LC22">--with-icu-dir=/usr \</div> <div id="LC23">--with-iodbc=/usr \</div> <div id="LC24">--with-ldap=/usr \</div> <div id="LC25">--with-ldap-sasl=/usr \</div> <div id="LC26">--with-libedit=/usr \</div> <div id="LC27">--enable-mbstring \</div> <div id="LC28">--enable-mbregex \</div> <div id="LC29">--with-mysql=mysqlnd \</div> <div id="LC30">--with-mysqli=mysqlnd \</div> <div id="LC31">--without-pear \</div> <div id="LC32">--with-pdo-mysql=mysqlnd \</div> <div id="LC33">--with-mysql-sock=/var/mysql/mysql.sock \</div> <div id="LC34">--with-readline=/usr \</div> <div id="LC35">--enable-shmop \</div> <div id="LC36">--with-snmp=/usr \</div> <div id="LC37">--enable-soap \</div> <div id="LC38">--enable-sockets \</div> <div id="LC39">--enable-sysvmsg \</div> <div id="LC40">--enable-sysvsem \</div> <div id="LC41">--enable-sysvshm \</div> <div id="LC42">--with-tidy \</div> <div id="LC43">--enable-wddx \</div> <div id="LC44">--with-xmlrpc \</div> <div id="LC45">--with-iconv-dir=/usr \</div> <div id="LC46">--with-xsl=/usr \</div> <div id="LC47">--enable-zip \</div> <div id="LC48">--with-pcre-regex \</div> <div id="LC49">--with-pgsql=/usr \</div> <div id="LC50">--with-pdo-pgsql=/usr \</div> <div id="LC51">--with-freetype-dir=/usr/X11 \</div> <div id="LC52">--with-jpeg-dir=/usr \</div> <div id="LC53">--with-png-dir=/usr/X11</div> <div>--with-mcrypt=/usr</div> </div> <div></div> <div>sudo make</div> <div>sudo make install</div> </div> <div>
12
May 12
Setup php-fpm with Apache
It has somay tutorial on how to get php-fpm work with Nginx but I did’t have much luck on setting it up with Apache. Hope this article can help s.o in the same situation like me: Setting php-fpm with apache.
1. Install apache, php, php-fpm package
sudo pacman -S apache php php-fpm
2. create alias to php binary
ln -s /usr/bin/php-cgi /srv/http/php5.fcgi
3. Edit config file
Make sure you don’t load apache php module. Remove all the lines which you added when installing php as an apache module.
Open the file /etc/httpd/conf/httpd.conf, make sire these link were there. If not, add them
# PHP – FPM
Include conf/extra/httpd-fpm.conf
Then we create conf/extra/httpd-fpm.conf as following:
LoadModule fastcgi_module modules/mod_fastcgi.so
Alias /php5.fcgi /srv/http/php5.fcgi
# Assign the ‘fake’ fcgi to call to an ‘external’ FastCGI Server
FastCGIExternalServer /srv/http/php5.fcgi -flush -host 127.0.0.1:9000 -pass-header Authorization
# Create the handler mappings to associate PHP files with a call to ‘/php5.fcgi’
AddType application/x-httpd-fastphp5 .php
Action application/x-httpd-fastphp5 /php5.fcgi
Config /etc/php/php-fpm.conf for listen setting. When you installed php-fpm, this file is created for you. You just need to open it and carefully go over settings there to confirm if nothing wrong for your machine setting
4. Running
run apache first, then run php-fpm
sudo rc.d start httpd
sudo rc.d start php-fpm
Troubleshoot: If you see this error when connectiong to MySQL: #2002 – The server is not responding (or the local MySQL server’s socket is not
correctly configured)
Edit setting for mysql socket in /etc/php.ini
mysqli.default_socket = /var/run/mysqld/mysqld.sock
mysql.default_socket = /var/run/mysqld/mysqld.sock
Normally it is /var/run/mysqld/mysqld.socket
You can double check via reading file /etc/mysql/my.cnf:
# The MySQL server
[mysqld]
port = 3306
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
4
Apr 12
Sprig hacking in Kohana 3.2: Filter, timestamp field, hasmany field
I worked with Kohana for awhile. Sprig is my choose for ORM. It’s really good but its development dropped. As I can see on GitHub, it mostly everybody has their own fork for Sprig. Sprig has a branch call feature/kohana3.1 which is compatible with Kohana3.x validation model. It also has some code which added back filter and callback but it doesn’t work at all because of wrong implement.
Since we should not change core code of Sprig, it will be better to extends Sprig_Core class. Create a new file application/clases/sprig.php and override method check().
<?php
public function check(array $data = NULL) {
if ($data === NULL) {
// Use the current data set
$data = $this->changed();
}
$data = Validation::factory($data);
$alter_data = array();
foreach ($this->_fields as $name => $field) {
if (!$data->offsetExists($name)) {
// Do not add any rules for this field
continue;
}
$data->label($name, $field->label);
if ($field->filters) {
foreach ($field->filters as $filter => $whoknows) {
if (is_callable($filter)) {
$alter_data[$name] = call_user_func($filter, $data[$name]);
} elseif (is_callable($whoknows)) {
$alter_data[$name] = call_user_func($whoknows, $data[$name]);
} else {
throw new Kohana_Exception('Filter is Invalid');
}
}
}
if ($field->rules) {
foreach ($field->rules as $rule => $rule_data) {
if ($rule_data[0]) { // if the rule has parameters
$data->rule($name, $rule, $rule_data);
} else {
$data->rule($name, $rule);
}
}
}
if ($field->callbacks) {
foreach ($field->callbacks as $callback) {
$data->rule($name, $callback, array(':validation', ':field'));
}
}
}
if (!$data->check()) {
throw new Validation_Exception($data);
}
return Arr::overwrite($data->as_array(), $alter_data);
}
Also, timestamp field has some wrong implement since it convert date/time to UNIX timestamp instead of correct timestamp data of mysql. Becauseof that, Timestamp field of Sprig extends Sprig_Field_Integer. Correct implement should be:
<?php
class Sprig_Field_Timestamp extends Sprig_Field_Char {
public $auto_now_create = FALSE;
public $auto_now_update = FALSE;
public $default = NULL;
public $format = 'Y-m-d G:i:s';
public $mysql_time = TRUE; //Use mysql timestamp or timestamp of PHP
public function value($value) {
if (TRUE === $this->mysql_time) {
if (is_integer($value)) {
return date($this->format, $value);
}
return parent::value($value);
}
if ($value AND is_string($value) AND !ctype_digit($value)) {
$value = strtotime($value);
}
return parent::value($value);
}
public function verbose($value) {
if (is_integer($value)) {
return date($this->format, $value);
} else {
return $value;
}
}
}
For Hasmany field, it should return an array of data.
Original implement:
<?php
public function value($value)
{
if (empty($value) AND $this->empty)
{
return array();
}
elseif (is_object($value))
{
$model = Sprig::factory($this->model);
// Assume this is a Database_Result objecta
$value = $value->as_array(NULL, $model->pk());
}
else
{
// Value must always be an array
$value = (array) $value;
}
if ($value)
{
// Combine the value to make a mirrored array
$value = array_combine($value, $value);
foreach ($value as $id)
{
// Convert the value to the proper type
$value[$id] = parent::value($id);
}
}
return $value;
}
Correct implement:
public function value($value) {
if (empty($value) AND $this->empty) {
return array();
} elseif (is_object($value)) {
$model = Sprig::factory($this->model);
// Assume this is a Database_Result object
$pk = $model->pk();
if (is_string($pk)) {
$value = $value->as_array(NULL, $pk);
} else {
$numOfRecord = $value->count();
$rows = array();
foreach ($pk as $col) {
$rows[$col] = $value->as_array(NULL, $col);
}
$result = array();
for ($i = 0; $i < $numOfRecord; $i++) {
foreach ($pk as $col) {
if (empty($result[$i])) {
$result[$i] = array();
}
$result[$i][$col] = $rows[$col][$i];
}
}
return $result;
}
} else {
// Value must always be an array
$value = (array) $value;
}
if ($value) {
// Combine the value to make a mirrored array
$value = array_combine($value, $value);
foreach ($value as $id) {
// Convert the value to the proper type
$value[$id] = parent::value($id);
}
}
return $value;
}
20
Mar 12
PHP 5.4
PHP 5.4 added lots of shorthand code:
1. You now can access property, method righ after creating an instance:
(new Foo)->bar().
2. Class::{expr}() syntax is now supported. This will be very handle. Before I used call_user_func for this purpose.
3. = is now always available, regardless of the short_open_tag php.ini option. You can use it in your template instead echo
4. Function array dereferencing has been added, e.g. foo()[0].
Also, PHP’s webserver is official so we are no loger worry about any web server to get familiar with PHP. Just grab PHP and start to hack code
Trait is supported too, PHP dev who loves Ruby will love this feature (just like me).
I did’t have a chance to review about performance. But overview IMO this PHP version is quite worth to install in production environment.
19
Feb 12
How to recovery mysql root password
For some reason if you lost your Mysql root pass, u can recover MySQL database server password with following five easy steps.
The idea is to start MySql server without checking for permission. In that mode, anyone can connect without a password.
Step # 1: Stop the MySQL server process: rc.d stop mysqld
Step # 2: Start the MySQL (mysqld) server/daemon process with the –skip-grant-tables option so that it will not prompt for password.
Step # 3: Connect to mysql server as the root user.
Step # 4: Setup new mysql root account password i.e. reset mysql password.
Step # 5: Exit and restart the MySQL server.
19
Feb 12
Major Update for Postgresql
If you made a major update for Postgresql, you are going to get in trouble because incompatible data between major versions http://www.postgresql.org/docs/current/static/pgupgrade.html
Everything looks easy when you just need to run some command to update it but it’s so confuse at least to me about old and new data folder.
The key thing is you must make a copy of current data folder, then remove it& start Postgresql. You cannot simply restart without removing current data folder because when you installed new version of Postgresql, it could not start because of incompatible data “The data directory was initialized by PostgreSQL version 9.0, which is not compatible with this version 9.1.1″.
Once you removed old data folder, then start Postgresql, it will start to crerate empty data folder for you for new postgresql verison.
At that time you can start to run command:
pg_upgrade -d /var/lib/postgres/olddata/ -D /var/lib/postgres/data -b /opt/pgsql-9.0/bin/ -B /usr/bin/
Assume that /opt/pgsql-9.0 is folder contains old postgresql version and new Postgresql binary is in /usr/bin.
Once it completed, you can remove everything about old Postgresql.
Notice: if you got some complaint about locale, make sure you initialize new database with the same local as old system then re-init db as following:
initdb –locale=C -D /var/lib/postgres/data/
17
Sep 11
Simple mail server for sending mail only
I used Google App for my email and it’s working great. The problem is I used a VPS and I need to send email on my system. I can configure to send email via google smtp. But somehow google stops to sending email when my system send email every 5 minutes. And sometimes Gooogle delays to delivery emails too.
Finally I decided to install a mail server for my own using. All I need is mail sending only. Receiving email is taken care by google app.
I used Arch Linux. All I need is to configure postfix, IMHO Postfix configuration is so complex to understand all of its aspects. Luckily we just want to send email so it should be simple
pacman -S postfix
Next, open /etc/postfix/main.cf, add these value (change to your own domain):
myhostname = www.axcoto.com myorigin = axcoto.com
Add postfix daemon to DAEMON in /etc/rc.conf.
DAEMONS=(syslog-ng !network netfs crond dbus @alsa wicd httpd mysqld vsftpd postgresql !hwclock ntpd <strong>postfix</strong>)
That’s all for sending email
. Please don’t ask more about Postfix
. I don’t know haha. This is just I got to sent out email
.
16
Jul 11
My development tools
Nowadays, we are no longer rely on local computer or work alone! Everything must be able to share, or in other words, be accessible universally! For example, client wants to know, or keep tracking of working progress! Or other friends want to give you a hand in project,..
In this post, I put together some useful tools I use daily
- Code Version Control: I use github for open source project! For private project, I use bitbucket! BitBucket is really great, only drawback is its Mercurial using! Recently I found unfuddle.com. Guess what..Iit supports GIT too
. But the best one I love is beanstalkapp.com! Because of using free package so I’m allowed only one project! Beanstalk can auto deploy your app to s/ftp server. Easy to integrate with other services such as: Basecamp, campfire, lighthouse, fogbuzz,…! - Project Management: Freedcamp.com, BitBucket, Acunote! I create Project in FreedCamp (unlimited), invite client, use discussion board to chat/discuss with client about requirement instead of using traditional email
! And trust me, this works great and save lots of time for you! After gather requirement, I then create task on FreedCamp and track time! For BitBucket, I create Mile Stone, create ticket as bug, enhancement, proposal,…! - Bug Tracking: FreedCamp, BitBucket, Acunote
- File Sharing: I used dropbox! Besides I used Arch Linux so I also use zimagez to store/share screenshot! I just press Printscreen button! And the rest is magic!
- Email: Of course google app
! Besides I used SSMTP on local computer to route mail sending to google! - Support Tool: I haven’t use any support/helpdesk software but I’m in love with tenderapp, zendesk, Assistly, Uservoice! Acutally, I’m building my own support platform with Kohana!
- Testing Tools: I used notableapp, usabilla, verifyapp, ! Imagine that you give it an URL, it captures web page, client see it then note feedback in it itself! How useful…
- DNS: My VPS has very low RAM 256MB… At this time, I must run lots of service in it! I know I should get a more powerful VPS but my money is really thin
! So, I use dnsmadeeasy to manage myDNS
9
Jul 11
Redirect in WordPress plugin
Ok, if you are a WordPress plugin dev, sooner or later you will got into trouble when trying redirecting! For example, you have a custom plugin page, after saving information into database, you want to redirect to other page! Certainly you will think of wp_redirect()!
Unfortunately, in most of case when use this function, it doesn’t work! The reason is WordPress already sent header before your plugin get call and running! Not only header of HTTP also header of html page too! So bad, you can work around using JavaScript redirect, or you can try to hook wp_init function and put ob_start() prevent printing out header! It does work! But it has a better way! WordPress has an extra option will will prevent sending header, even remove header and footer of whole WordPress admin page! You just need to append ?noheader=true
You can try to manually append above parameter to url to see how it goes! You will got the page without header and footer! And in this case, WordPress will not header of HTTP too! So, you can perform your plugin task and call wp_redirect()
!