<?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>Wes Ray &#187; PHP</title>
	<atom:link href="http://www.wessray.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.wessray.com</link>
	<description>Just another idiot with a blog</description>
	<lastBuildDate>Fri, 12 Nov 2010 09:21:28 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Configuring Fedora 13 PHP/ MySQL Server with Nginx and reverse proxy to Apache</title>
		<link>http://www.wessray.com/php/configuring-fedora-13-php-mysql-server-with-nginx-and-reverse-proxy-to-apache/</link>
		<comments>http://www.wessray.com/php/configuring-fedora-13-php-mysql-server-with-nginx-and-reverse-proxy-to-apache/#comments</comments>
		<pubDate>Fri, 12 Nov 2010 00:04:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[fedora]]></category>
		<category><![CDATA[nginx]]></category>

		<guid isPermaLink="false">http://www.wessray.com/?p=120</guid>
		<description><![CDATA[
		
		
		
		Ok so I&#8217;m going to make this article quick, simple and to the point.  Fuck the bullshit, lets get ya&#8217;ll setup with nginx with a  reverse proxy to apache in less than an hour.   Now this article is made for VPS type system such as linode or slicehost.  We&#8217;re starting at the point in which [...]]]></description>
			<content:encoded><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;">
		<script type="text/javascript">
		<!--
		digg_url = "http://www.wessray.com/php/configuring-fedora-13-php-mysql-server-with-nginx-and-reverse-proxy-to-apache/";
		digg_bgcolor = "";
		digg_skin = "";
		digg_window = "";
		digg_title = "Configuring+Fedora+13+PHP%2F+MySQL+Server+with+Nginx+and+reverse+proxy+to+Apache";
		digg_media = "";
		digg_topic = "";
		digg_bodytext = "";
		//-->
		</script>
		<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script></div><p>Ok so I&#8217;m going to make this article quick, simple and to the point.  Fuck the bullshit, lets get ya&#8217;ll setup with <strong>nginx </strong>with a  reverse proxy to <strong>apache </strong>in less than an hour.   Now this article is made for VPS type system such as linode or slicehost.  We&#8217;re starting at the point in which you have Fedora 13 actually installed, base system.  So lets get started.</p>
<h2>Install Nginx</h2>
<p>Lets start by installing nginx, start the service and configure it to start at boot.</p>
<pre class="brush: bash;">
yum install nginx
service nginx start
chkconfig nginx on
</pre>
<h2>Now lets install php, mysql and some dependencies.</h2>
<p>Was going to use fast-cgi but it crashes so often, so I created a reverse proxy into apache.</p>
<pre class="brush: bash;">
yum install httpd httpd-devel php php-cli php-devel mysql php-mysql mysql-server php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-magickwand php-magpierss php-mbstring php-mcrypt php-mssql php-shout php-snmp php-soap php-tidy sendmail
</pre>
<h2>Configuring nginx</h2>
<pre class="brush: bash;">
nano /etc/nginx/nginx.conf
</pre>
<p>Once inside the file, change these two values</p>
<pre class="brush: bash;">
worker_processes  5;
keepalive_timeout  2;
</pre>
<p>Similar to apache you can set virtual hosts.  First lets start by editing the example in the nginx.conf file.</p>
<p>You can define the vhost in server {} containers. Now lets modify the default vhost:</p>
<p>server_name _; makes this a default vhost ( so lets change this to specify a certain domain e.g. www.something.com).</p>
<p>In the location / part, add index.php to the index line. root <strong>/usr/share/nginx/html;</strong>
<p>
This is your DocumentRoot in an apache virtual host, so you can change it to whatever you want..I prefer the /var/www/ directories.
<p>The important part for PHP is the location <strong>~ \.php$ {}</strong> container. You need to uncomment it to enable it. Change the root line to the web site&#8217;s document root (e.g. root /usr/share/nginx/html; or whatever you directory you chose.).  Be sure to pass .php to <strong>127.0.0.1:8080</strong> to proxy php files to apache (we&#8217;ll edit httpd.conf later).</p>
<h2>Apache as proxy</h2>
<pre class="brush: bash;">
nano /etc/httpd/conf/httpd.conf
</pre>
<p>Pass through to apache port 8080</p>
<pre class="brush: bash;">
Listen 127.0.0.1:8080
</pre>
<p>configure the virtualhost to reflect the same path as the nginx vhost.</p>
<h2>Install and configure MySQL</h2>
<p>Make sure its ready for startup and start it up</p>
<pre class="brush: bash;">
chkconfig mysqld on
/etc/init.d/mysqld start
</pre>
<h3>Now lets install MySQL securely</h3>
<pre class="brush: bash;">
mysql_secure_installation
</pre>
<p>
>Enter Current Root Password : <strong>Hit Enter</strong><br />
>Set Root Password : </strong>Hit Enter</strong><br />
Now enter your password twice<br />
The rest are your choice, I hit enter all the way through.
</p>
<h2>Install APC and other Dev Tools</h2>
<p>Lets install some dependencies, most are just needed on a dev server anyway, so group install.  Fail2ban is to keep users from attacking your site, they will be banned after 5 failed attemps to login for 10 mins.  You can change the configuration in /etc/fail2ban/</p>
<pre class="brush: bash;">
yum groupinstall 'Development Tools'
yum groupinstall 'Development Libraries'
yum install php-pecl-apc
yum install fail2ban
yum install mlocate

chkconfig fail2ban on
chkconfig httpd on
chkconfig nginx on
chkconfig mysqld on
updatedb
</pre>
<p> In the fail2ban configuration file you can change additional settings, they are very self explanatory. To edit fail2ban configuration go to:</p>
<pre class="brush: bash;">
nano /etc/fail2ban/jail.conf
</pre>
<p><strong>Now guess what, you&#8217;re done.  If you have any questions, just leave a comment and I&#8217;ll be sure to answer it, enjoy the nginx server.</strong></p>
<h2> Feeling Generous??</h2>
<p>Sign up for a linode VPS, I pay $20 a month and it fucking rocks</p>
<p>My <a href="http://www.linode.com/?r=2bf9ae77ecd8e759a2b79bf1011e1c3147d93525" target="_blank">Linode.com</a> Referral Code <strong>2bf9ae77ecd8e759a2b79bf1011e1c3147d93525</strong></p>
<p>-<strong>Wes</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.wessray.com/php/configuring-fedora-13-php-mysql-server-with-nginx-and-reverse-proxy-to-apache/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Kohana 3 Name Spacing with Underscores in Controller Classes</title>
		<link>http://www.wessray.com/php/kohana-3-name-spacing-with-underscores-in-controller-classes/</link>
		<comments>http://www.wessray.com/php/kohana-3-name-spacing-with-underscores-in-controller-classes/#comments</comments>
		<pubDate>Sun, 02 May 2010 22:44:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Kohana]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ko3]]></category>

		<guid isPermaLink="false">http://www.wessray.com/?p=111</guid>
		<description><![CDATA[
		
		
		
		So, I&#8217;ve been working with Kohana 2.3.4 lately and its absolutely beautiful.  A much improved version of what Codeigniter should have been.  Now they released Kohana 3 which is similar, yet very different.  One of the &#8220;gotchas&#8221; I noticed in KO3 (Kohana 3) is the auto loading of controller classes and the [...]]]></description>
			<content:encoded><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;">
		<script type="text/javascript">
		<!--
		digg_url = "http://www.wessray.com/php/kohana-3-name-spacing-with-underscores-in-controller-classes/";
		digg_bgcolor = "";
		digg_skin = "";
		digg_window = "";
		digg_title = "Kohana+3+Name+Spacing+with+Underscores+in+Controller+Classes";
		digg_media = "";
		digg_topic = "";
		digg_bodytext = "";
		//-->
		</script>
		<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script></div><p>So, I&#8217;ve been working with Kohana 2.3.4 lately and its absolutely beautiful.  A much improved version of what Codeigniter should have been.  Now they released Kohana 3 which is similar, yet very different.  One of the &#8220;gotchas&#8221; I noticed in KO3 (Kohana 3) is the auto loading of controller classes and the name spacing with underscores.  Here is an example of what I&#8217;m talking about.</p>
<h1>All underscores are converted to slashes</h1>
<p>In Kohana 2 you could name a class with underscores and there would be no problem</p>
<p>now the underscores are converted to slashes</p>
<p>
notice the <strong>Controller_</strong> is in the front now which translates to controller/
</p>
<p>
Within the classes folder in application you notice there is classes/controllers to keep for instance a file extending off template.
</p>
<p>
So a template in controllers would need to be named <strong>defaulttemplate.php</strong> which would become <strong>Controller_DefaultTemplate</strong>, BUT if you wanted it to be Controller_Default_Template it would have to be in a sub folder called Default in controllers then <strong>template.php</strong>
</p>
<p>
Its a bit confusing in the beginning but you&#8217;ll get used to it.  The entire system is a helluva improvement.  Look forward to a few articles i&#8217;ll be writing on using the ORM.
</p>
<p>Cheers,<br />
<strong>-Wes</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.wessray.com/php/kohana-3-name-spacing-with-underscores-in-controller-classes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Remove Non Ascii Characters using PHP and Regular Expressions</title>
		<link>http://www.wessray.com/php/strip-and-remove-non-ascii-characters-using-php-regular-expressions/</link>
		<comments>http://www.wessray.com/php/strip-and-remove-non-ascii-characters-using-php-regular-expressions/#comments</comments>
		<pubDate>Fri, 18 Dec 2009 21:12:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.wessray.com/?p=66</guid>
		<description><![CDATA[
		
		
		
		So there I was taking forever to fix content from a Word Perfect document converted to Word then pasted as HTML.  I was spending a while removing all the bullshit non Ascii Characters and I thought to myself and said&#8230;Wes, you idiot, you are a programmer, do this the right way and filter it [...]]]></description>
			<content:encoded><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;">
		<script type="text/javascript">
		<!--
		digg_url = "http://www.wessray.com/php/strip-and-remove-non-ascii-characters-using-php-regular-expressions/";
		digg_bgcolor = "";
		digg_skin = "";
		digg_window = "";
		digg_title = "Remove+Non+Ascii+Characters+using+PHP+and+Regular+Expressions";
		digg_media = "";
		digg_topic = "";
		digg_bodytext = "";
		//-->
		</script>
		<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script></div><p>So there I was taking forever to fix content from a Word Perfect document converted to Word then pasted as HTML.  I was spending a while removing all the bullshit non Ascii Characters and I thought to myself and said&#8230;Wes, you idiot, you are a programmer, do this the right way and filter it out.  So I did and here is a simple way of doing it through regular expressions and php.</p>
<pre class="brush: php;">

&lt;?php
//Your nasty string of word and non ascii chars
$Contentz = &quot;These are shitty chars â€ž and we dont like them nor want them.&quot;;

//Array of content I want to make a space
$badContent = array(&quot;&amp;nbsp;&quot;);

//Replace the bad arrays with a space
$Contentz = trim(str_replace($badContent,&quot; &quot;,$Contentz));

//Specific string replaces for ellipsis, etc that you dont want removed but replaced
$theBad = 	array(&quot;“&quot;,&quot;”&quot;,&quot;‘&quot;,&quot;’&quot;,&quot;…&quot;,&quot;—&quot;,&quot;–&quot;);
$theGood = array(&quot;\&quot;&quot;,&quot;\&quot;&quot;,&quot;'&quot;,&quot;'&quot;,&quot;...&quot;,&quot;-&quot;,&quot;-&quot;);
$Contentz = str_replace($theBad,$theGood,$Contentz);

//Whatever might be left over...
//Remove all non ascii chars (aka: bad Microsoft Word and Word Perfect Shit shit)
$Contentz = preg_replace('/[^(\x20-\x7F)\x0A]*/','', $Contentz);

echo $Contentz;
?&gt;
</pre>
<p><strong>$Contentz will show up removing the characters.</strong></p>
<p>Cheers,<br />
 <strong>Wes S .Ray</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.wessray.com/php/strip-and-remove-non-ascii-characters-using-php-regular-expressions/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Configuring PHP Web server on Fedora 11</title>
		<link>http://www.wessray.com/php/configuring-php-mysql-web-server-on-fedora-11/</link>
		<comments>http://www.wessray.com/php/configuring-php-mysql-web-server-on-fedora-11/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 18:25:02 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://wessray.com/?p=19</guid>
		<description><![CDATA[Creating a Fedora 11 Web server for php, mysql, apache, ]]></description>
			<content:encoded><![CDATA[<div style="float: right; width: 42px; padding-right: 10px; margin: 0 0 0 10px;">
		<script type="text/javascript">
		<!--
		digg_url = "http://www.wessray.com/php/configuring-php-mysql-web-server-on-fedora-11/";
		digg_bgcolor = "";
		digg_skin = "";
		digg_window = "";
		digg_title = "Configuring+PHP+Web+server+on+Fedora+11";
		digg_media = "";
		digg_topic = "";
		digg_bodytext = "";
		//-->
		</script>
		<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script></div><p>This is going to be a quick and simple tutorial on how to setup a Fedora 11 Linux Server with PHP, MySQL, Apache and phpmyadmin.  Now I&#8217;m assuming you already have the OS installed on your machine.  Most of you will be using cloud servers, mine is from <a href="http://www.linode.com/?r=2bf9ae77ecd8e759a2b79bf1011e1c3147d93525" target="_blank"><em><strong>Linode.com</strong></em></a>.  You will need to have shell access to your server.  If you have very little experience with linux I suggest you brush up and learn a <strong><a href="http://howtoforge.com/" target="_blank"><em>little syntax</em></a></strong> so you aren&#8217;t shooting in the dark.</p>
<p>Ok, so lets get started with the actual configuration of the server.   At this point I AM ASSUMING you have the operating system installed and its just a bare canvas.</p>
<h3>Here we go, hold on kids.</h3>
<p>The first step that is needed to taken is open up your terminal, I personally use <strong><a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/" target="_blank"><em>PuTTY</em></a></strong>, a free telnet/ssh client.  One you are logged in make sure you have full access to the system, whether it be <strong>root </strong>or <strong>sudo</strong>.</p>
<p>Now lets install PHP and MySQL. These will be commands you type in the terminal.  We will be installing the apache, mysql and php and configuring them.</p>
<ul> <code> </code></p>
<li><strong>yum -y install httpd php mysql mysql-server php-mysql</strong></li>
</ul>
<p>We set chkconfig so that when rebooted the servers will start automatically, and we do this like so.</p>
<ul> <code> </code></p>
<li><strong>chkconfig httpd on</strong></li>
<li><strong>chkconfig mysqld on</strong></li>
</ul>
<p>Now that Apache and MySQL are starting with the server, we can configure MySQL</p>
<ul>
<li><strong>mysqladmin -u root &#8216;root_pw_of_your_choice&#8217;</strong></li>
</ul>
<p>Now lets install phpMyAdmin, a mysql database management tool.</p>
<ul> <code> </code></p>
<li><strong>yum install phpMyAdmin.noarch</strong></li>
</ul>
<p>Since that has been taken care of let, lets open up the phpmyadmin config.</p>
<ul>
<li><strong>nano /etc/httpd/conf.d/phpMyAdmin.conf</strong></li>
</ul>
<p>At this point what we need to do is comment out a certain section. Notice that I have a # which denotes comment out</p>
<p><strong>#&lt;Directory /usr/share/phpMyAdmin/&gt;<br />
#   order deny,allow<br />
#   deny from all<br />
#   allow from 127.0.0.1<br />
#&lt;/Directory&gt;</strong></p>
<p>Next we are going to jump into the httpd.conf, otherwise known as the Apache Config File</p>
<ul>
<li><strong>nano /etc/httpd/conf/httpd.conf</strong></li>
</ul>
<p>Once in there you are going to want to change a section</p>
<p><strong>&lt;Directory /&gt;<br />
Options FollowSymLinks<br />
<span style="color: #000000; background-color: #00ff00;">AllowOverride All</span><br />
&lt;/Directory&gt;</strong></p>
<p>You will want to set it to AllowOverride All, by default it should be set to none, but we dont want that.</p>
<p>Now at the end of the file add these to make your IP address directly or URL go directly to phpMyAdmin unless you set a virtualhost otherwise.  You need to put all of this at the bottom of your<strong> httpd.conf</strong> file</p>
<p><strong>&lt;VirtualHost your.ip:80&gt;<br />
ServerAdmin youremail@server.com<br />
DocumentRoot /usr/share/phpMyAdmin/</p>
<p>ServerName yourIP<br />
ServerAlias yourIP</p>
<p>ErrorLog logs/home-error_log<br />
CustomLog logs/home-access_log common<br />
&lt;/VirtualHost&gt;</p>
<p>Include /etc/httpd/conf/sites-production/*<br />
Include /etc/httpd/conf/sites-development/*</strong></p>
<p>Save and close the conf file and finally create your folders than you included, e.g</p>
<ul>
<li><strong>mkdir /etc/httpd/conf/sites-production</strong></li>
<li><strong>mkdir /etc/httpd/conf/sites-development</strong></li>
</ul>
<p>Now that the config file directories are made, lets make the place holders for the actual website content</p>
<ul>
<li><strong>/var/www/sites-production</strong></li>
<li><strong>/var/www/sites-development</strong></li>
</ul>
<p>That about sums it up for the base server setup on fedora 11 for a linode VPS.  If you want more PHP Packages just run this command and you should have everything you need.</p>
<p><strong>yum install php php-devel php-gd php-imap php-ldap php-mysql php-odbc php-pear php-xml php-xmlrpc php-eaccelerator php-magickwand php-magpierss php-mapserver php-mbstring php-mcrypt php-mhash php-mssql php-shout php-snmp php-soap php-tidy curl curl-devel perl-libwww-perl ImageMagick libxml2 libxml2-devel</strong></p>
<p>If you need any MySQL help for setting up users, I reccomend this site</p>
<p><a href="http://www.databasef1.com/tutorial/mysql-create-user.html" target="_blank"> http://www.databasef1.com/tutorial/mysql-create-user.html</a></p>
<p>If any help is needed feel free to leave comments and I will respond.  Good luck!</p>
<h2> Feeling Generous??</h2>
<p>Sign up for a linode VPS, I pay $20 a month and it fucking rocks</p>
<p>My <a href="http://www.linode.com/?r=2bf9ae77ecd8e759a2b79bf1011e1c3147d93525" target="_blank">Linode.com</a> Referral Code <strong>2bf9ae77ecd8e759a2b79bf1011e1c3147d93525</strong></p>
<p>-<strong>Wes</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.wessray.com/php/configuring-php-mysql-web-server-on-fedora-11/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

