<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Kwatog &#38; Co &#187; PHP</title>
	<atom:link href="http://kwatog.com/category/blog/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://kwatog.com</link>
	<description>tech notes and general nonsense</description>
	<lastBuildDate>Fri, 04 May 2012 07:34:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>SpotVPS First Impressions</title>
		<link>http://kwatog.com/blog/spotvps-first-impressions/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=spotvps-first-impressions</link>
		<comments>http://kwatog.com/blog/spotvps-first-impressions/#comments</comments>
		<pubDate>Thu, 01 Dec 2011 07:57:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Hosting]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[NGINX]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Unix]]></category>

		<guid isPermaLink="false">http://kwatog.com/?p=706</guid>
		<description><![CDATA[After the unfortunate incident last week with NordicVPS, I decided to look for a new VPS host. As usual, I went to lowendbox and get the reviews in webhostingtalk. It&#8217;s there where I stumbled upon a promo from SpotVPS. As it turns out, SpotVPS is a low-cost VPS offering of ComfortHost.NET. And who are they?&#8230;]]></description>
			<content:encoded><![CDATA[<p>After the unfortunate incident last week with NordicVPS, I decided to look for a new VPS host. As usual, I went to lowendbox and get the reviews in webhostingtalk. It&#8217;s there where I stumbled upon a promo from <a href="http://www.comforthost.net/billing/aff.php?aff=115">SpotVPS</a>. As it turns out, SpotVPS is a low-cost VPS offering of ComfortHost.NET.</p>
<p>And who are they? Here&#8217;s what they say about themselves.</p>
<blockquote><p>
ComfortHost.NET have been here since 2004 offer high quality web hosting solutions. All SpotVPS nodes are fully owned hardware and are colocated. All servers used by SpotVPS have been bought with internal cash. Our only monthly cost for these servers are the actual colocation. We are financially healthy and profitable since day one. We are NOT going out of buisness any time soon. We are in it for the long run!
</p></blockquote>
<p>ComfortHost on http://www.webhostingtalk.com/showthread.php?t=1110770</p>
<p>Here&#8217;s the plan that I got.<br />
$6.99/mo Ultimate Plan<br />
Memory: 2048mb (2gb)<br />
HD Space: 50gb (50,000mb)<br />
Bandwidth: 1,000gb (1TB)<br />
Monthly Price: $6.99/mo<br />
Setup Fee: FREE!<br />
FREE GIGABIT PORT &#8211; FREE WEEKLY BACKUPS &#8211; FREE HARDWARE RAID<br />
Location: Orlando, FL at DimeNOC<br />
Test IP Address: 72.29.87.105</p>
<p>2GB RAM for $6.99. That&#8217;s sweet. Want to try it yourself? <a href="http://www.comforthost.net/billing/aff.php?aff=115">ORDER NOW</a></p>
<p>Word of caution,though. This plan (and all other dirt-cheap vps that I know of) comes with very limited support. You are usually given your VPS, IP and OS install and you have to do the rest. I installed mine with NGiNx, PHP, MySQL and it&#8217;s already up and running for 7 days straight now. </p>
<p>Here&#8217;s the result of the test I made on my VPS.<br />
<code><br />
[root@vps ~]# dd if=/dev/zero of=test bs=64k count=16k conv=fdatasync<br />
16384+0 records in<br />
16384+0 records out<br />
1073741824 bytes (1.1 GB) copied, 14.9939 seconds, 71.6 MB/s</p>
<p>[root@vps ~]# wget cachefly.cachefly.net/100mb.test<br />
--2011-11-24 18:10:35-- http://cachefly.cachefly.net/100mb.test<br />
Resolving cachefly.cachefly.net... 205.234.175.175<br />
Connecting to cachefly.cachefly.net|205.234.175.175|:80... connected.<br />
HTTP request sent, awaiting response... 200 OK<br />
Length: 104857600 (100M) [application/octet-stream]<br />
Saving to: `100mb.test'</p>
<p>100%[==============================================================================================================================>] 104,857,600 66.8M/s in 1.5s<br />
2011-11-24 18:10:36 (66.8 MB/s) - `100mb.test' saved [104857600/104857600]<br />
</code></p>
<p>I&#8217;ll try to come up with a review together with my other hosting providers. <img src='http://kwatog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://kwatog.com/blog/spotvps-first-impressions/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>LAMP Install on VPS : CentOS5+Apache+MySQL+suPHP</title>
		<link>http://kwatog.com/apache/lamp-install-on-vps-centos5/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=lamp-install-on-vps-centos5</link>
		<comments>http://kwatog.com/apache/lamp-install-on-vps-centos5/#comments</comments>
		<pubDate>Sun, 24 Jul 2011 15:50:14 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://kwatog.com/?p=627</guid>
		<description><![CDATA[Here&#8217;s the work-in-progress instructions for setting up a LAMP. It&#8217;s been sitting on my draft for ages and I have to publish it because a few of my friends need it. **** NOTE : If you notice, it&#8217;s still a draft. It came from a number of sources but these are the steps I use.&#8230;]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s the work-in-progress instructions for setting up a LAMP. It&#8217;s been sitting on my draft for ages and I have to publish it because a few of my friends need it. </p>
<p>**** NOTE : If you notice, it&#8217;s still a draft. It came from a number of sources but these are the steps I use. So I know it works. **********</p>
<p><span id="more-627"></span></p>
<p>update apache<br />
yum -y update </p>
<p>install utilities and compiler<br />
yum -y install zip nmap fileutils gcc-c++ acl</p>
<p>install make<br />
yum -y install make</p>
<h3>MySQL Installation</h3>
<p><code><br />
yum -y install mysql mysql-devel mysql-server<br />
chkconfig --levels 235 mysqld on<br />
mysqld start<br />
/usr/bin/mysql_secure_installation<br />
</code></p>
<h3>Install PHP</h3>
<p><code>yum -y install php php-devel php-gd php-imap php-ldap php-mysql php-odbc php-pear php-xml php-xmlrpc curl curl-devel perl-libwww-perl ImageMagick libxml2 libxml2-devel<br />
</code><br />
Upgrade PHP to 5.3<br />
<code>rpm -Uvh http://repo.webtatic.com/yum/centos/5/latest.rpm<br />
yum --enablerepo=webtatic update php</code></p>
<h3>Install ProFTP</h3>
<p><code>yum -y remove vsftpd   --to remov vsftpd if it's existing<br />
cd /tmp<br />
wget --passive-ftp ftp://ftp.proftpd.org/distrib/source/proftpd-1.3.3e.tar.gz<br />
tar xvfz proftpd-1.3.3e.tar.gz<br />
cd proftpd-1.3.3e<br />
./configure --sysconfdir=/etc; make; make install<br />
cd /tmp; rm -rf ./proftpd-1.3.3*<br />
ln -s /usr/local/sbin/proftpd /usr/sbin/proftpd<br />
touch /etc/init.d/proftpd<br />
chmod 755 /etc/init.d/proftpd<br />
vi /etc/init.d/proftpd<br />
</code></p>
<p>Paste the following settings and then save.<br />
<code><br />
#!/bin/sh<br />
# $Id: proftpd.init,v 1.1 2004/02/26 17:54:30 thias Exp $<br />
#<br />
# proftpd This shell script takes care of starting and stopping<br />
# proftpd.<br />
#<br />
# chkconfig: - 80 30<br />
# description: ProFTPD is an enhanced FTP server with a focus towards<br />
# simplicity, security, and ease of configuration.<br />
# It features a very Apache-like configuration syntax,<br />
# and a highly customizable server infrastructure,<br />
# including support for multiple 'virtual' FTP servers,<br />
# anonymous FTP, and permission-based directory visibility.<br />
# processname: proftpd<br />
# config: /etc/proftp.conf<br />
# pidfile: /var/run/proftpd.pid</p>
<p># Source function library.<br />
. /etc/rc.d/init.d/functions</p>
<p># Source networking configuration.<br />
. /etc/sysconfig/network</p>
<p># Check that networking is up.<br />
[ ${NETWORKING} = "no" ] &#038;&#038; exit 0</p>
<p>[ -x /usr/sbin/proftpd ] || exit 0</p>
<p>RETVAL=0</p>
<p>prog="proftpd"</p>
<p>start() {<br />
echo -n $"Starting $prog: "<br />
daemon proftpd<br />
RETVAL=$?<br />
echo<br />
[ $RETVAL -eq 0 ] &#038;&#038; touch /var/lock/subsys/proftpd<br />
}</p>
<p>stop() {<br />
echo -n $"Shutting down $prog: "<br />
killproc proftpd<br />
RETVAL=$?<br />
echo<br />
[ $RETVAL -eq 0 ] &#038;&#038; rm -f /var/lock/subsys/proftpd<br />
}</p>
<p># See how we were called.<br />
case "$1" in<br />
start)<br />
start<br />
;;<br />
stop)<br />
stop<br />
;;<br />
status)<br />
status proftpd<br />
RETVAL=$?<br />
;;<br />
restart)<br />
stop<br />
start<br />
;;<br />
condrestart)<br />
if [ -f /var/lock/subsys/proftpd ]; then<br />
stop<br />
start<br />
fi<br />
;;<br />
reload)<br />
echo -n $"Re-reading $prog configuration: "<br />
killproc proftpd -HUP<br />
RETVAL=$?<br />
echo<br />
;;<br />
*)<br />
echo "Usage: $prog {start|stop|restart|reload|condrestart|status}"<br />
exit 1<br />
esac</p>
<p>exit $RETVAL<br />
</code></p>
<p>vi /etc/proftpd.conf<br />
<code><br />
Group nobody<br />
DefaultRoot ~<br />
IdentLookups off<br />
ServerIdent on "FTP Server ready."<br />
</code></p>
<p>chkconfig &#8211;levels 235 proftpd on</p>
<h3>Install suPHP</h3>
<p>cd /tmp<br />
wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.i386.rpm<br />
rpm &#8211;import http://apt.sw.be/RPM-GPG-KEY.dag.txt<br />
rpm -K rpmforge-release-0.5.2-2.el5.rf.*.rpm<br />
rpm -i rpmforge-release-0.5.2-2.el5.rf.*.rpm<br />
yum -y install htop<br />
yum -y install mod_suphp<br />
edit /etc/suphp.conf<br />
make sure these lines are there:</p>
<p>webserver_user=apache<br />
x-httpd-php=&#8221;php:/usr/bin/php-cgi&#8221;<br />
x-suphp-cgi=&#8221;execute:!self&#8221;</p>
<p> edit /etc/httpd/conf.d/suphp.conf (which is the global configuration for suPHP).<br />
vi +/suPHP_Engine /etc/httpd/conf.d/suphp.conf</p>
<p>change it to suPHP_Engine off</p>
<p>6) Set suPHP to work with VirtualHost, add these few lines inside <virtualhost> </virtualhost> tag.</p>
<p>suPHP_Engine on<br />
suPHP_UserGroup username groupname<br />
AddHandler x-httpd-php .php .php3 .php4 .php5<br />
suPHP_AddHandler x-httpd-php</p>
<p>Example :<br />
<VirtualHost 75.235.323.55:80><br />
    ServerAdmin support@yourdomain.com<br />
    DocumentRoot /usr/kitty/yourdomain.com<br />
    ServerName yourdomain.com<br />
    ServerAlias *.yourdomain.com<br />
    suPHP_Engine on<br />
    suPHP_UserGroup kitty kitty<br />
    AddHandler x-httpd-php .php .php3 .php4 .php5<br />
    suPHP_AddHandler x-httpd-php<br />
    ErrorLog logs/yourdomain.com-error_log<br />
    CustomLog logs/yourdomain.com-access_log common<br />
</VirtualHost></p>
<p>Source : <a href="http://wiki.centos.org/AdditionalResources/Repositories/RPMForge" rel="nofollow">CentOS Additional Packages</a></p>
]]></content:encoded>
			<wfw:commentRss>http://kwatog.com/apache/lamp-install-on-vps-centos5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automatically Convert Emails to NoSpam</title>
		<link>http://kwatog.com/blog/automatically-convert-emails-to-nospam/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=automatically-convert-emails-to-nospam</link>
		<comments>http://kwatog.com/blog/automatically-convert-emails-to-nospam/#comments</comments>
		<pubDate>Wed, 18 May 2011 15:28:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://kwatog.com/?p=549</guid>
		<description><![CDATA[To prevent spam comments on one of the sites that I maintain, I send for approval any comment with at least one URL or email address in it. In that way, manual spammers will find no incentive on leaving comments on the site. At the same time, email addresses left by commenters will not be&#8230;]]></description>
			<content:encoded><![CDATA[<p>To prevent spam comments on one of the sites that I maintain, I send for approval any comment with at least one URL or email address in it. In that way, manual spammers will find no incentive on leaving comments on the site. At the same time, email addresses left by commenters will not be displayed in the site until it is sanitized. However, the amount of comments in the site in question is so many and manually sanitizing comments with emails is becoming a pain.<br />
<span id="more-549"></span><br />
So I decided to write a hook to filter the comments and auto-convert the emails into NoSpam format. That is, replacing the @(at sign) and . (dot) in the email. So here&#8217;s the purpose of this auto-conversion.</p>
<ol>
<li>auto-approve legitimate comments even if it has emails in it</li>
<li>prevent email scrapers from harvesting email addresses left by the commenters</li>
<li>send for manual approval any comment with one or more URL other than emails</li>
</ol>
<p><!--more--><br />
Just place the code below anywhere on your template&#8217;s functions.php.<br />
<code><br />
function Kwatog_NoSpamEmail($text){<br />
    $pattern = '/([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*@([a-z0-9])'.'(([a-z0-9-])*([a-z0-9]))+'.'(.([a-z0-9])([-a-z0-9_-])?([a-z0-9])+)+/i';<br />
	preg_match_all($pattern, $text, $emails);<br />
	$symbols = array("@", ".");<br />
	$safeChars = array("[at]", "[dot]");<br />
    foreach ($emails[0] as $email){<br />
         $emailsafe = str_replace($symbols, $safeChars, $email);<br />
          $text = str_replace($email, $emailsafe, $text);<br />
	}<br />
    return $text;<br />
}</p>
<p>add_filter('comment_text','Kwatog_NoSpamEmail');<br />
add_filter('pre_comment_content', 'Kwatog_NoSpamEmail');<br />
</code></p>
<p>Here&#8217;s the sample output after I put in this code.<br />
<img src="http://kwatog.com/wp-content/uploads/2011/05/Screen-shot-2011-05-17-at-PM-11.43.3111.png" alt="" title="NoSpam Email Auto Convert" width="660" height="163" class="alignnone size-full wp-image-550" /></p>
<p>The code is not actually foolproof but it will be able to trap 90% of the scenarios. Also, the auto-change is applicable for existing and new comments.</p>
<p>I have no intention as of this time to convert snippet into a WordPress plugin so feel free to create one if you feel like it.</p>
]]></content:encoded>
			<wfw:commentRss>http://kwatog.com/blog/automatically-convert-emails-to-nospam/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Upgrading to PHP 5.3 for CentOS</title>
		<link>http://kwatog.com/blog/upgrading-to-php-5-3/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=upgrading-to-php-5-3</link>
		<comments>http://kwatog.com/blog/upgrading-to-php-5-3/#comments</comments>
		<pubDate>Sat, 14 May 2011 18:37:26 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://kwatog.com/?p=531</guid>
		<description><![CDATA[I wanted to try WordPress 3.2 beta but realized that it requires at least PHP 5.2 and I&#8217;m still with 5.1.6 (the one that comes with CentOS). Here&#8217;s what I got from the interwebs. Step 1: Get webtatic PHP 5.3 Repository rpm -Uvh http://repo.webtatic.com/yum/centos/5/latest.rpm Step 2: Update PHP yum --enablerepo=webtatic update php Step 3: Verify&#8230;]]></description>
			<content:encoded><![CDATA[<p>I wanted to try WordPress 3.2 beta but realized that it requires at least PHP 5.2 and I&#8217;m still with 5.1.6 (the one that comes with CentOS).  Here&#8217;s what I got from the interwebs. </p>
<p><strong>Step 1: Get webtatic PHP 5.3 Repository</strong><br />
<code>rpm -Uvh http://repo.webtatic.com/yum/centos/5/latest.rpm</code></p>
<p><strong>Step 2: Update PHP</strong><br />
<code>yum --enablerepo=webtatic update php</code></p>
<p><strong>Step 3: <a href="http://kwatog.com/blog/linux/how-to-get-apache-php-version-in-shell/">Verify PHP version</a></strong><br />
<code>php -v</code></p>
<p>Expected result should be like below<br />
<code><br />
PHP 5.3.6 (cli) (built: Mar 19 2011 08:30:07)<br />
Copyright (c) 1997-2011 The PHP Group<br />
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies<br />
</code></p>
<p>*** NOTE ***<br />
Though webstatic stated that the repository is created for CentOS 64bit, it still worked for my 32-bit installation.</p>
<p>Source:</p>
<p>http://www.webtatic.com/packages/php53/</p>
]]></content:encoded>
			<wfw:commentRss>http://kwatog.com/blog/upgrading-to-php-5-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shopping Cart Always Empty</title>
		<link>http://kwatog.com/apache/shopping-cart-always-empty/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=shopping-cart-always-empty</link>
		<comments>http://kwatog.com/apache/shopping-cart-always-empty/#comments</comments>
		<pubDate>Sun, 21 Nov 2010 08:28:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[NGINX]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://kwatog.com/?p=439</guid>
		<description><![CDATA[After using suPHP on my Apache webserver and NGINX on another server, I realized that my cart systems are no longer working. Here are the symptoms I noticed. AJAX Carts does not display items When clicking checkout, the cart becomes empty After clicking update, the cart becomes empty If you look at the symptoms, you&#8217;ll&#8230;]]></description>
			<content:encoded><![CDATA[<p>After using suPHP on my Apache webserver and NGINX on another server, I realized that my cart systems are no longer working. Here are the symptoms I noticed.</p>
<ol>
<li>AJAX Carts does not display items</li>
<li>When clicking checkout, the cart becomes empty</li>
<li>After clicking update, the cart becomes empty</li>
</ol>
<p>If you look at the symptoms, you&#8217;ll notice that every time you move to another page of your website, the cart is emptied. It only mean that the session data is not being saved. And with that, you&#8217;ll have to check your PHP save_path session settings in PHP.INI. Most often than not, the current value is /etc/php/sessions. You&#8217;ll have to check the folder permission. On my case, the folder is owned by root and the group is apache.<br />
<span id="more-439"></span><br />
Since in suPHP, I use users other than apache and for nginx, I&#8217;m using user nginx, PHP cannot write into the folder. So a quick fix that I did was to add my users to apache group. Just like below.</p>
<p><code>usermod -a -G apache <strong>kwatog</strong></code></p>
<p>That solved the problem but there&#8217;s a catch. Since the user (in the example, kwatog) has read+write access to the session folder, he can then read the session files that other users have in that same folder. For me, that&#8217;s not a problem because only me has access on my VPS. But for others, this could pose a problem. The solution proposed here is by overriding the save_patch settings via .htaccess. Here&#8217;s the code.</p>
<p><code>php_value session.save_path "tmp"</code></p>
<p>However, I haven&#8217;t tried it. Actually, I did but it failed and I don&#8217;t have time to investigate. Since the usergroup fix solves the initial problem, I&#8217;ll just get back to this at a later time.</p>
<p>By the way, if you don&#8217;t know where your PHP.INI is, it is most like in /etc/php.ini. However, in case you&#8217;ve installed it somewhere else, then you better read my <a href="kwatog.com/blog/linux/how-to-find-php-ini-path/">How to Find PHP.INI Path</a></p>
]]></content:encoded>
			<wfw:commentRss>http://kwatog.com/apache/shopping-cart-always-empty/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NGINX &#8211; 502: Bad Gateway</title>
		<link>http://kwatog.com/blog/nginx-502-bad-gateway/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=nginx-502-bad-gateway</link>
		<comments>http://kwatog.com/blog/nginx-502-bad-gateway/#comments</comments>
		<pubDate>Thu, 21 Oct 2010 16:00:14 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[NGINX]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://kwatog.com/?p=431</guid>
		<description><![CDATA[One of my VPS on NordicPVS went down today and after restarting, I got a number of weird errors. Apparently, the contents of my VPS were wiped-out. Though I managed to solve most of the problems (mostly by restoring the backup), I kept getting the 502: Bad Gateway error. I told myself that this can&#8217;t&#8230;]]></description>
			<content:encoded><![CDATA[<p>One of my VPS on NordicPVS went down today and after restarting, I got a number of weird errors. Apparently, the contents of my VPS were wiped-out. Though I managed to solve most of the problems (mostly by restoring the backup), I kept getting the <strong>502: Bad Gateway</strong> error. I told myself that this can&#8217;t happen because I restored the whole system from the backup already. </p>
<p>After going through a checklist, I found out that PHP CGI is not running. All I had to do is jumpstart it and everything is working as before.<br />
<code><br />
/etc/init.d/php_cgi start<br />
</code><br />
<span id="more-431"></span></p>
<p>The experience thought me some valuable lessons. I list some below.</p>
<ol>
<li>Make a regular backup. This saved me from a lot of trouble. If I didn&#8217;t have the backup, all the data will be gone. And make sure you have an offsite backup.</li>
<li>Keep your system updated. I found out that my nginx is outdated(I installed using the repository). If possible, compile instead of install</li>
<li>Create a checklist of things so that in times of fuckups like what happened earlier today, you have a guide on what to check</li>
<li>Schedule essential programs in the startup. When I setup my vps, I just followed someone else&#8217;s procedure. Unfortunately, the chkconfig portion was omitted. And being a noob, I didn&#8217;t know how to set that up. So, RTFM.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://kwatog.com/blog/nginx-502-bad-gateway/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Datetime value to string in PHP</title>
		<link>http://kwatog.com/blog/datetime-value-to-string-in-php/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=datetime-value-to-string-in-php</link>
		<comments>http://kwatog.com/blog/datetime-value-to-string-in-php/#comments</comments>
		<pubDate>Sat, 07 Aug 2010 07:09:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[strtotime]]></category>

		<guid isPermaLink="false">http://kwatog.com/?p=379</guid>
		<description><![CDATA[This one escapes me everytime I need which results to much googling. The function is to convert SQL datetime value to human-readable format. /*  *   Converts the likes of '2010-08-01 14:57:15' to 'August 1, 2010, 2:57 pm'  */   $datetime_value ="2010-08-01 14:57:15"; echo date(  "F j, Y, g:i a", strtotime( $datetime_value ) );   Here&#8217;s another example which you will see on some of my templates. &#60;?php echo date('Y-m-d', strtotime('next month')); ?&#62; For more formats, go head to&#8230;]]></description>
			<content:encoded><![CDATA[<p>This one escapes me everytime I need which results to much googling. The function is to convert SQL datetime value to human-readable format.</p>
<p><code><br />
/* <br />
*   Converts the likes of '2010-08-01 14:57:15' to 'August 1, 2010, 2:57 pm' <br />
*/  <br />
$datetime_value ="2010-08-01 14:57:15";<br />
echo date(  "F j, Y, g:i a", strtotime( $datetime_value ) );  <br />
</code></p>
<p>Here&#8217;s another example which you will see on some of my templates.<br />
<code><br />
&lt;?php echo date('Y-m-d', strtotime('next month')); ?&gt;<br />
</code></p>
<p>For more formats, go head to <a href="http://php.net/manual/en/function.date.php">PHP Doc</a>.</p>
<p>Reference:</p>
<p>http://php.net/manual/en/function.date.php</p>
]]></content:encoded>
			<wfw:commentRss>http://kwatog.com/blog/datetime-value-to-string-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Get Apache &amp; PHP version in Shell</title>
		<link>http://kwatog.com/blog/linux/how-to-get-apache-php-version-in-shell/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-get-apache-php-version-in-shell</link>
		<comments>http://kwatog.com/blog/linux/how-to-get-apache-php-version-in-shell/#comments</comments>
		<pubDate>Thu, 05 Aug 2010 13:45:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://kwatog.com/?p=239</guid>
		<description><![CDATA[Aside from using phpinfo(), you can also use some shell commands to view the apache or php versions you are using. NOTE: This is in CentOS 5. Syntax to get Apache Version httpd -v Sample: [root@vps ~]# httpd -v Server version: Apache/2.2.3 Server built: May 28 2009 12:50:07 Syntax to get PHP Version php -v&#8230;]]></description>
			<content:encoded><![CDATA[<p>Aside from using <strong>phpinfo()</strong>, you can also use some shell commands to view the apache or php versions you are using. </p>
<p>NOTE: This is in CentOS 5.<br />
<span id="more-239"></span><br />
<strong>Syntax to get Apache Version</strong><br />
<code><br />
httpd -v<br />
</code></p>
<p>Sample:<br />
<code>[root@vps ~]# httpd -v<br />
Server version: Apache/2.2.3<br />
Server built:   May 28 2009 12:50:07</code></p>
<p><strong>Syntax to get PHP Version</strong><br />
<code><br />
php -v<br />
</code></p>
<p>Sample:<br />
<code><br />
[root@host ~]# php -v<br />
PHP 5.0.5 (cli) (built: Apr 26 2006 09:47:41)<br />
Copyright (c) 1997-2004 The PHP Group<br />
Zend Engine v2.0.5, Copyright (c) 1998-2004 Zend Technologies<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://kwatog.com/blog/linux/how-to-get-apache-php-version-in-shell/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Adding New Array Key in PHP</title>
		<link>http://kwatog.com/blog/php/adding-new-array-key-in-php/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=adding-new-array-key-in-php</link>
		<comments>http://kwatog.com/blog/php/adding-new-array-key-in-php/#comments</comments>
		<pubDate>Sat, 03 Apr 2010 00:34:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[array_fill_keys]]></category>
		<category><![CDATA[array_key_exists]]></category>
		<category><![CDATA[array_merge]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://kwatog.com/?p=250</guid>
		<description><![CDATA[In adding a new array key, we&#8217;ll need to know two array functions called array_key_exists and array_merge. First, let&#8217;s take a look at array_keys. It&#8217;s a function that returns an array containing the keys of an array. &#60;?php $a = array("foo"=>"1","bar" => "2"); $keys = array_keys($a); print_r($keys); ?&#62; Second, of course, is array_merge. As the&#8230;]]></description>
			<content:encoded><![CDATA[<p>In adding a new array key, we&#8217;ll need  to know two array functions called <em>array_key_exists</em> and <em>array_merge</em>.</p>
<p>First, let&#8217;s take a look at <strong>array_keys</strong>. It&#8217;s a function that returns an array containing the keys of an array.<br />
<code><br />
&lt;?php<br />
    $a = array("foo"=>"1","bar" => "2");<br />
    $keys = array_keys($a);</p>
<p>   print_r($keys);<br />
?&gt;<br />
</code></p>
<p>Second, of course, is <strong>array_merge</strong>. As the name implies, it just merge the two array.<br />
<code><br />
&lt;?php<br />
  $a = array("foo" => "1", "bar" = "2");<br />
  $b = array("name" => "Juan", "gender" => "male");<br />
  $c = array_merge($b, $a);</p>
<p> print_r($c);<br />
?&gt;<br />
</code></p>
<p>So here&#8217;s the final code we have.<br />
<code><br />
&lt;?php<br />
  $a = array("foo" => "1", "bar" = "2");<br />
  // keys to be added<br />
  $b =array("name" => "Juan");<br />
  $c =array("gender" => "male");  </p>
<p>  $a = array_merge($a, $b, $c);</p>
<p>  print_r($a);</p>
<p>?&gt;<br />
</code></p>
<p>The code above is too simplistic ( <em>we didn&#8217;t even use the array_keys function</em>) but if you are not certain with the keys you of the array to be merged, then this functions become handy. Example as below.<br />
<code><br />
&lt;?php<br />
  $a = array("foo" => "1", "bar" = "2");<br />
  /* let's say $b comes from a function that returns<br />
     array with (i.e, array("name" => "Juan", "gender" => "male"))<br />
  */<br />
  $b = my_function_ret_array();</p>
<p>  $keys = array_keys($b);<br />
  foreach($keys as $key){<br />
      if(array_key_exists($key, $a){<br />
          $a[$key] = $b[$key];<br />
       }<br />
      else {<br />
          $a = array_merge($a, array($key => $b[$key]));<br />
     }<br />
  }</p>
<p>  print_r($a);</p>
<p>?&gt;<br />
</code></p>
<p>Again, I must remind my readers that there might be better way of doing this. It all depends on the situation and for the time being, this is the functions I used. If you want to suggest a new one, please share it in the comment box.</p>
]]></content:encoded>
			<wfw:commentRss>http://kwatog.com/blog/php/adding-new-array-key-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Find PHP.INI Path</title>
		<link>http://kwatog.com/blog/linux/how-to-find-php-ini-path/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-find-php-ini-path</link>
		<comments>http://kwatog.com/blog/linux/how-to-find-php-ini-path/#comments</comments>
		<pubDate>Sun, 06 Sep 2009 04:36:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://kwatog.com/?p=143</guid>
		<description><![CDATA[If you can&#8217;t find it in /etc/php.ini, then you have to use ssh and execute the command below. php -i &#124; grep php.ini The command will return something like Configuration File (php.ini) Path => /etc/php.ini]]></description>
			<content:encoded><![CDATA[<p>If you can&#8217;t find it in /etc/php.ini, then you have to use ssh and execute the command below.<br />
<code>php -i | grep php.ini</code></p>
<p>The command will return something like<br />
<strong>Configuration File (php.ini) Path => /etc/php.ini<br />
</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://kwatog.com/blog/linux/how-to-find-php-ini-path/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

