<?xml version="1.0" encoding="iso-8859-1" standalone="yes" ?>
<rss version="2.0">
<channel>
<title>OSResources - Unix, Linux and BSD Guides - The five questions posted most recently:</title>
<description>Computer science tutorials and HOW-TOs for open-source system administration and programming</description>
<link>http://www.osresources.com</link>	<item>
		<title><![CDATA[How can I add more CentOS repositories?]]></title>
		<description><![CDATA[<p>
After installing CentOS, your system has only a few repositories, therefore offering a limited range of applications. It is possible and easy to add more repositories that are unofficial but trusted by the community. By doing so, you will access a wide range or applications for your CentOS system.
</p>
<p>
You have two ways to add more Centos repositories:
</p>
<ul>
	<li>Drop .repo files into your /etc/yum.repos.d/ directory</li>
	<li>Add a repository entry in your /etc/yum.conf file</li>
</ul>
<p>
In this example, we will use yum.conf only, for more consistency.
</p>
<h3>Adding official CentOS repositories</h3>
<p>
Here is the list of official repository entries that you can add to your /etc/yum.conf file:
</p>
<pre>
[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&amp;arch=$basearch&amp;repo=os
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos4
enabled=1
#released updates 
[update]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&amp;arch=$basearch&amp;repo=updates
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos4
enabled=1
#packages used/produced in the build but not released
[addons]
name=CentOS-$releasever - Addons
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&amp;arch=$basearch&amp;repo=addons
#baseurl=http://mirror.centos.org/centos/$releasever/addons/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos4
enabled=1
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&amp;arch=$basearch&amp;repo=extras
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos4
enabled=1
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&amp;arch=$basearch&amp;repo=centosplus
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos4
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&amp;arch=$basearch&amp;repo=contrib
#baseurl=http://mirror.centos.org/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos4
</pre>
<h3>Additional third-party CentOS repositories</h3>
<p>
The following repositories don&#39;t belong to the CentOS project but are trustworthy and provide additional software:
</p>
<pre>
[dries]
name=Extra Fedora rpms dries - $releasever - $basearch
baseurl=http://ftp.belnet.be/packages/dries.ulyssis.org/redhat/el4/en/i386/dries/RPMS
gpgcheck=1
enabled=1
[dag]
name=Dag RPM Repository for Red Hat Enterprise Linux
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag
gpgcheck=1
enabled=1
[kbs-CentOS-Extras]
name=CentOS.Karan.Org-EL$releasever - Stable
gpgcheck=1
gpgkey=http://centos.karan.org/RPM-GPG-KEY-karan.org.txt
enabled=1
baseurl=http://centos.karan.org/el$releasever/extras/stable/$basearch/RPMS/
[kbs-CentOS-Misc]
name=CentOS.Karan.Org-EL$releasever - Stable
gpgkey=http://centos.karan.org/RPM-GPG-KEY-karan.org.txt
gpgcheck=1
enabled=1
baseurl=http://centos.karan.org/el$releasever/misc/stable/$basearch/RPMS/
[kbs-CentOS-Misc-Testing]
name=CentOS.Karan.Org-EL$releasever - Testing
gpgkey=http://centos.karan.org/RPM-GPG-KEY-karan.org.txt
gpgcheck=1
enabled=1
baseurl=http://centos.karan.org/el$releasever/misc/testing/i386/RPMS/
[atrpms]
name=Fedora Core $releasever - $basearch - ATrpms
baseurl=http://dl.atrpms.net/fc$releasever-$basearch/atrpms/stable
gpgkey=http://ATrpms.net/RPM-GPG-KEY.atrpms
gpgcheck=1enabled=1
</pre>
<p>
To use the above repositories, you need to add their GPG key for authentication:
</p>
<pre>
$ su -
# rpm --import http://centos.karan.org/RPM-GPG-KEY-karan.org.txt
# rpm --import http://dries.ulyssis.org/rpm/RPM-GPG-KEY.dries.txt
# rpm --import http://dag.wieers.com/packages/RPM-GPG-KEY.dag.txt
# rpm --import http://ATrpms.net/RPM-GPG-KEY.atrpms
</pre>
<p>
With all these repositories, you should be able to find most applications you need.
</p>
]]></description>
		<link>http://www.osresources.com/content/11/6/en/how-can-i-add-more-centos-repositories.html</link>
		<pubDate>Mon, 01 Sep 2008 13:13:00 GMT</pubDate>
	</item>
	<item>
		<title><![CDATA[How to verify the integrity of a file using SHA-512?]]></title>
		<description><![CDATA[<p>
You can use SHA for a number of tasks including checking if a file has been altered from its source and its destination. Checking file integrity can be done easily on Unix systems.
</p>
<p>
1. First, install sha if you don&#39;t have it on your system. On PC-BSD and FreeBSD:
</p>
<pre>
$ 
$ su -
# pkg_add -r sha
</pre>
<p>
On CentOS and RPM-based systems:
</p>
<pre>
$ su -
# yum install sha
</pre>
<p>
From the manual of sha, you can use several levels of cryptography:
</p>
<ul>
	<li>-1  Uses SHA-1, which produces a 160-bit hash (40-hex digits);</li>
	<li>-2  Uses SHA-256, which produces a 256-bit hash (64-hex digits);</li>
	<li>-3  Uses SHA-384, which produces a 384-bit hash (96-hex digits);</li>
	<li>-5  Uses SHA-512, which produces a 512-bit hash (128-hex digits).</li>
</ul>
<p>
2. Let&#39;s use the strongest encryption. We are going to create a hash of a file called "ports":
</p>
<pre>
$ ls
ports
$ sha -5 ports &gt; myports.sha5
$ ls
ports	myports.sha5
$ 
</pre>
<p>
3. Now let&#39;s see how we can check integrity of a file. To do so, we need the hash file provided by the author of the file, and the hash file created from the file we have on our computer. We use the cmp tool to compare the two hash files bit by bit:
</p>
<pre>
$ ls
ports	myports.sha5	authorports.sha5
$ cmp myports.sha5 authorports.sha5
$
</pre>
 
<p>
If both files are equal, your downloaded file is unchanged, the cmp tool will not return any error message and will return the exit 0 signal to the system. If both hash files are different, cmp will tell you where they are different and will return the exit 1  signal to the system:
</p>
<pre>
$ ls
ports	myports.sha5	authorports.sha5
$ cmp myports.sha5 ports
myports.sha5 ports differ: char 1, line 1
$ cmp myports.sha5 authorports.sha5
$
</pre>
 
<p>
This way, you can make sure your file is not corrupted, like you would do using MD5.
</p>
]]></description>
		<link>http://www.osresources.com/content/10/4/en/how-to-verify-the-integrity-of-a-file-using-sha_512.html</link>
		<pubDate>Mon, 01 Sep 2008 13:12:00 GMT</pubDate>
	</item>
	<item>
		<title><![CDATA[How to make web applications faster?]]></title>
		<description><![CDATA[<p>
One of the biggest  hurdles of web applications is that they are considered slow. <a href="http://mail.google.com/mail/help/about.html">Gmail</a> is faster than <a href="http://www.squirrelmail.org/about.php">Squirrelmail</a>, but <a href="http://www.opera.com/products/desktop/m2/">Opera M2</a> is faster than Gmail. Yet, web applications are experiencing a real boom and rapid adoption. Web applications are more and more snappy, the Internet is faster and faster with broadband, and web application slowness is less and less an issue to the point that more and more users are switching their desktop applications for web applications because:
</p>
<ul>
	<li>Web applications can be accessed anywhere with a connection to the Internet</li>
	<li>They can be used is various browsers and platforms</li>
	<li>You don&#39;t have duplication of data, all your data is concentrated on your server</li>
	<li>You don&#39;t have to worry about backing up your data, it is backed up by your web host</li>
</ul>
<p>
This said, as a developer, you may find interesting to design fast applications for the web used as a development platform. Designing great web applications is above all using javascript and common sense extensively. We can distinguish client-side scripting and server-side technologies. Let&#39;s analyze both of them.
</p>
<h3>Client-side optimization</h3>
<p>
As a rule of thumb, load as much information as you can when the person is loading the web application.  Load even the content and the windows that the user will not see in the beginning and hide them. When you need to show this content and these windows, just change their CSS property on the fly to be visible, it&#39;ll take one tenth of a second instead of 2-3 seconds.
</p>
<p>
Use as much <a href="http://en.wikipedia.org/wiki/JavaScript">Javascript</a> (aka. <a href="http://en.wikipedia.org/wiki/Ajax_(programming)">Ajax</a>) as you can, especially when loading remote content: instead of having your user waiting and wondering if he should click one more time on the button, disable the button right after clicking, and change the text of the button from "Submit" to "Sending...". Your user will understand that he can&#39;t click one more time, and that the application is not frozen, it&#39;s just querying some data:
</p>
<pre>
&lt;input type="button" value="Submit" onclick="this.value=&#39;Sending...&#39; this.disabled=&#39;true&#39; return false;" /&gt;
</pre>
<p>
 
</p>
<p>
This doesn&#39;t <em>turn</em> your web application faster, but it makes the wait acceptable, and it makes the application more user-friendly, this is what in important.
</p>
<p>
Querying the server as low as possible is crucial in web applications. Only query what you need and when you need it. Don&#39;t reload the whole page every time there is new content, but rather use <a href="http://en.wikipedia.org/wiki/XMLHttpRequest">xmlHttpRequest</a> to query the new content and  put it only in the area of your window where it is supposed to be.
</p>
<p>
Use Javascript alert, confirm and prompt boxes for user interaction instead of opening a pop-up window, it&#39;s faster and easier to implement:
</p>
<pre>
&lt;input type="button" value="Alert box" onclick="alert(&#39;This is an alert box&#39;); return false;" /&gt;
&lt;input type="button" value="Confirm box" onclick="confirm(&#39;Would you like to continue after this confirm box?&#39;); return false;" /&gt;
&lt;input type="button" value="Prompt box" onclick="prompt(&#39;Please enter your name&#39;,&#39;Enter your name here&#39;); return false;" /&gt;
</pre>
<p>
When you are waiting for the server output after a query, or right after sending a query, it is a good idea to let your user know what is going on. A little message in the top-right corner of the window in bold with white text and a red background à la Gmail will do the trick to display messages such as "Sending..." or "Loading...":
</p>
<p>
<img src="files/optimizing-speed/loading.png" alt="Loading..." />
</p>
<p>
Optimizing your CSS code is very important as well. Using CSS doesn&#39;t necessarily mean your page will load much faster than using legacy table-based code, if you have lots of useless or redundant lines of CSS code. CSS has a myriad of shortcuts that can be used. Yesterday I converted a 12KB bloated CSS file into an optimized 2K CSS code that had the same rules, but optimized. Import your CSS code from an external file instead of including the code inside your web page - You&#39;ll need to load the CSS code just once. Also, for each selector, just use one line of code, you&#39;ll save a few bits. Every bit helps, in the end you may save on download time and bandwidth. These are a few tips for you to optimize your CSS files:
</p>
<pre>
p {
margin: 0px 0px 0px 0px;
}
p {
margin-top:	0px;
margin-right:	0px;
margin-bottom:	0px;
margin-left:	0px;
}
</pre>
<p>
In this case, you have the same value for all directions, and the value is 0px, in other words "0", be it in pixels, in ems or in pts is still "0", so the above can be abreviated to: 
</p>
<pre>
p { margin: 0; }
</pre>
<p>
Here&#39;s another shortcut. Suppose you have:
</p>
<pre>
p {
margin: 0px 5px 0px 5px;
}
</pre>
<p>
The above means you have no margin on top and at the bottom, and you have a 5px margin on both sides. When you have the same value on top and at the bottom, on the one hand, on both sides, on the other hand, you can define only 2 values, the first being to define the value for top &amp; bottom, and the 2nd value being for left &amp; right. Additionally, "0px" can be changed to just "0". The above can be changed to: 
</p>
<pre>
p { margin:	0 5px; }
</pre>
<p>
These shortcuts are true for both padding and margin. Here&#39;s one more shortcut. Suppose you have a top padding of "0", a right and a left padding of 10px, and a bottom padding of 5px. You could do:
</p>
<pre>
p {
margin: 0px 10px 5px 10px;
}
</pre>
<p>
But you can save a few bits! If you declare only 3 values, the first value goes for the top, the second value goes for both left and right, and the third value is used for the bottom. The above declaration can be summed up to: 
</p>
<pre>
p { margin: 0px 10px 5px; }
</pre>
<p>
The font property also can be simplified dramatically. The following snippet:
</p>
<pre>
body {
font-family: Arial, &#39;Nimbus Sans L&#39; sans-serif;
font-size: 12px;
font-style: italic;
font-weight: bold;
}
</pre>
<p>
Can be summed up to
</p>
<pre>
body { font: italic bold 12px Arial, &#39;Nimbus Sans L&#39; sans-serif; }
</pre>
<p>
That simple :) Let&#39;s see how we can simplify a background property. The following example:
</p>
<pre>
body {
background-color: #CCFF00;
background-image: url(map.png);
background-position: left center;
background-repeat: repeat-x;
}
</pre>
<p>
Can be simplified too. First, the color has 3 sets of 2 similar letters that can be simplified from #CCFF00 to #cf0, left can be changed to 0, as the distance from the left boundary will be "0", center can be changed to 50%, as the distance will be 50% from the top, and the background declarations can be merged into just one single line:
</p>
<pre>
body { background: #cf0 url(map.png) 0 50% repeat-x; }
</pre>
<p>
And last, but not least, let&#39;s give the border property a diet. Here&#39;s a big, big declaration that has a lot of redundant code:
</p>
<pre>
body {
border-top-width: 1px;
border-top-style: solid;
border-top-color: #000000;
border-right-width: 1px;
border-right-style: solid;
border-right-color: #000000;
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: #000000;
border-left-width: 1px;
border-left-style: solid;
border-left-color: #000000;
}
</pre>
<p>
The above amount of code that you will find in a number of web sites can be summed up into a single line:
</p>
<pre>
body { border: 1px solid #000; }
</pre>
<p>
If you follow these simple rules and if you don&#39;t use many images and graphics, you should have a pretty fast web application. For web applications, the effort is really focused on the client-side because what really makes it an application is the fact that it acts as such, and not as a web page that loads one page after the other. Server-side optimization is important too, but if you don&#39;t optimize your server-side technology and application, you still can invest into a more robust server. If you can avoid this, better yet, so let&#39;s see how you can get the most out of your server.
</p>
<h3>Client-side optimization</h3>
<p>
Optimizing your code is important. It has been discussed which server-side technology is faster. Truth is that they are are pretty close to each other. Code in what you feel more comfortable, and your application will probably benefit from your expertise and be faster. Java (JSP) is known to be resource-hungry while mod_php and mod_python are very lightweight and fast.
</p>
<p>
<a href="http://en.wikipedia.org/wiki/Apache_HTTP_Server">Apache</a> and <a href="http://en.wikipedia.org/wiki/Lighttpd">LightTPD</a> (aka. Lighty) are the two most robust web servers, LightTPD using less memory. If you use PHP, you can either use:
</p>
<ul>
	<li> mod_php and Apache</li>
	<li>php-cgi  and LightTPD both compiled with <a href="http://en.wikipedia.org/wiki/Fastcgi">FastCGI</a> support</li>
</ul>
<p>
Both have very similar performance under heavy load. An alternative to FastCGI is <a href="http://en.wikipedia.org/wiki/SCGI">SCGI</a>, they both keep code in cache and make execution much faster. These are the most common configurations these days with more recent technologies such as:
</p>
<ul>
	<li><a href="http://en.wikipedia.org/wiki/Ruby_on_Rails">Ruby on Rails</a> and FastCGI</li>
	<li><a href="http://en.wikipedia.org/wiki/Django_web_framework">Django</a> and FastCGI</li>
</ul>
<p>
Your choice for the database can be either <a href="http://www.postgresql.org">PostgreSQL</a> or <a href="http://www.mysql.org/">MySQL</a>. PostgreSQL is know to outperform MySQL under heavy load, while MySQL is know to work great in a <a href="http://www.mysql.com/products/cluster/faq.html">cluster</a> environment. Both share the same standard SQL synthax. With either of these server-side technologies, you should be good to go. Fast web sites use these technologies - They&#39;re free of charge and open-source, with excellent support on forums and mailing lists, you can&#39;t go wrong.
</p>
<p>
With all this in mind, you can go one step further improving the speed and quality of your web applications and more and more users will hardly  feel any difference between a desktop application and your web application. 
</p>
<h3>Go further! </h3>
<ul>
	<li>Usenet channel <a href="http://groups.google.com/group/comp.lang.javascript">comp.lang.javascript</a></li>
	<li>comp.lang.javascript <a href="http://jibbering.com/faq/">FAQ</a></li>
	<li>Cross-Browser <a href="http://www.scss.com.au/family/andrew/webdesign/xmlhttprequest/">XMLHttpRequest</a></li>
	<li><a href="http://www.json.org/js.html">JSON in JavaScript</a></li>
	<li><a href="http://amix.dk/index.py/permanentLink?id=161">RND - fast and simple JS template system</a></li>
	<li><a href="http://script.aculo.us/">Scriptaculous</a></li>
	<li><a href="http://jibbering.com/2002/4/httprequest.html">Using the XML HTTP Request object</a></li>
	<li><a href="http://www.webreference.com/javascript/reference/core_ref/contents.html">Core JavaScript Reference</a></li>
	<li><a href="http://www.webreference.com/programming/javascript/">WebReference JavaScript Articles</a></li>
</ul>
]]></description>
		<link>http://www.osresources.com/content/9/3/en/how-to-make-web-applications-faster.html</link>
		<pubDate>Mon, 01 Sep 2008 13:11:00 GMT</pubDate>
	</item>
	<item>
		<title><![CDATA[How can I edit the DNS entries in Linux or BSD?]]></title>
		<description><![CDATA[<p>
Both Linux and BSD  have a file that lists one name server per line for your computer to resolve domain names. Please note that you need to set your <a href="http://en.wikipedia.org/wiki/Domain_name_system">DNS</a> servers only if you don&#39;t use <a href="http://en.wikipedia.org/wiki/DHCP">DHCP</a> to connect to the Internet, in other words, if you  have a fixed IP address such as 192.168.0.2 in your home network, then this tutorial will help you. If you don&#39;t define a specific IP address for your <a href="http://en.wikipedia.org/wiki/Network_card">NIC</a>, then you don&#39;t have to worry about configuring your DNS. Configuring your DNS means basically pasting 2 IP addresses into a file and saving.
</p>
<p>
Prior to editing this file, you need to find out what the name servers of your <a href="http://en.wikipedia.org/wiki/Internet_service_provider">ISP</a> are. To find out, you have 3 possibilities:
</p>
<ul>
	<li>Connect to the Internet using DHCP, and have a look at the content of your /etc/resolv.conf file using the command cat /etc/resolv.conf</li>
	<li>Ask a friend of yours who uses Unix and who uses the same ISP as you</li>
	<li>Call the tech support of your ISP and ask for the 2 name servers or ask for the DNS so that you can set up your network</li>
</ul>
<p>
Once you have the 2 IP addresses, log in as root and issue the following commands:
</p>
<h3>On BSD: </h3>
<pre>
ee /etc/resolv.conf
</pre>
<h3>On Linux: </h3>
<pre>
nano -w /etc/resolv.conf
</pre>
<p>
And add the DNS entries in your file, for instance:
</p>
<pre>
nameserver		201.10.120.2
nameserver		201.10.128.3
</pre>
<p>
Now save, and let&#39;s see if your network is properly configured. Open your terminal and issue:
</p>
<pre>
ping 201.239.39.104
</pre>
<p>
You should see  on your screen a new line per second showing the time it took for your packet to go back and forth from your computer to the remote machine. If you get a "<em>Destination Host Unreachable</em>" message, you first need to set up your network prior to configuring your DNS.
</p>
<p>
Then let&#39;s see if your DNS are properly set up. Issue in your terminal:
</p>
<pre>
ping google.com
</pre>
<p>
Again, you should see  on your screen a new line per second showing the time it took for your packet to go back and forth from your computer to the remote machine. If you get a "<em>Destination Host Unreachable</em>" message, you but if in the previous test worked fine, your DNS are not properly configured. Make sure your /etc/resolv.conf file is saved with the correct name servers. If you pass this test, you can access the Internet normally, using a web browser for instance. 
</p>
]]></description>
		<link>http://www.osresources.com/content/8/2/en/how-can-i-edit-the-dns-entries-in-linux-or-bsd.html</link>
		<pubDate>Mon, 01 Sep 2008 13:09:00 GMT</pubDate>
	</item>
	<item>
		<title><![CDATA[How to install a server with lighttpd, PHP 5 and MySQL 5 on FreeBSD?]]></title>
		<description><![CDATA[<p>
With the advent of light-weight server-side software and agile web applications, more and more people are using lighttpd as their web server because it uses very few resources. Let&#39;s see how to install a complete developer environment on a <a href="http://www.freebsd.org">FreeBSD</a> or <a href="http://www.pcbsd.org">PC-BSD</a> system. To begin with, I assume you have your ports up-to-date. Let&#39;s start installing lighttpd.
</p>
<h2>Installing lighttpd</h2>
<p>
Open your terminal and issue:
</p>
<pre>
$ su -
# cd /usr/ports/www/lighttpd
# make install clean
</pre>
<p>
And compile lighttpd with MySQL support when prompted. Now, let&#39;s create a directory to put our .php and .html files, and change the owner to you (change charles to your username):
</p>
<pre>
# mkdir -p /usr/local/www/data
# chown -R charles:charles /usr/local/www/data
# ln -s /usr/local/www/data ~charles/Desktop/www
</pre>
<p>
We&#39;ll create a PHP test file:
</p>
<pre>
# vi /usr/local/www/data/index.php
</pre>
<p>
Now, let&#39;s put the following content to our index.php file:
</p>
<pre>
&lt;? phpinfo(); ?&gt;
</pre>
<p>
And save. Let&#39;s also allow read/write of log files (if they don&#39;t exist yet, create these files) so that lighttpd doesn&#39;t complain:
</p>
<pre>
# chown www:www /var/log/lighttpd.access.log
# chown www:www /var/log/lighttpd.error.log
</pre>
<p>
Now, let&#39;s configure lighttpd.conf:
</p>
<pre>
# vi /usr/local/etc/lighttpd.conf
</pre>
<p>
You will need to:
</p>
<ul>
	<li>Uncomment mod_fastcgi under server.modules</li>
	<li>Make sure server.document-root is set to /usr/local/www/data</li>
	<li>Make sure server.event-handler    is set to freebsd-kqueue and is uncommented </li>
	<li>Make sure server.port is either commented or set to a common port such as 80</li>
	<li>Make sure server.username and server.groupname are both defined as www</li>
	<li>Uncomment the whole fastcgi.server section and set the full path to php-cgi such as:  </li>
</ul>
<pre>
fastcgi.server             = ( ".php" =&gt;
( "localhost" =&gt;
(
"socket" =&gt; "/tmp/php-fastcgi.socket",
"bin-path" =&gt; "/usr/local/bin/php-cgi"
)
)
)
</pre>
<p>
When you&#39;re done, save your file. If, for some reason, you erased or corrupted your file, download a copy <a href="files/lighttpd-freebsd/lighttpd.conf">here</a>. On FreeBSD, lighttpd doesn&#39;t know explicitely where his configuration file is, so what we&#39;re going to do is create a wrapper to launch lighttpd and to pass automatically the configuration file as a parameter, launching lighttpd will be easier as well, and we will make the file executable:
</p>
<pre>
# vi /usr/bin/lighttpd
#!/bin/sh
/usr/local/sbin/lighttpd -f /usr/local/etc/lighttpd.conf $@
# chmod +x /usr/bin/lighttpd
</pre>
<p>
Save. Optionally, if you would like lighttpd to start together with FreeBSD during bootup, issue the following command:
</p>
<pre>
# echo &#39;lighttpd_enable="YES"&#39; &gt;&gt; /etc/rc.conf
</pre>
<p>
You have the following options to control lighttpd: start, stop, and restart. Now, let&#39;s start lighttpd:
</p>
<pre>
# lighttpd start
</pre>
<p>
That&#39;s it for lighttpd. Let&#39;s install PHP with the PHP extensions.
</p>
<h2>Installing PHP</h2>
<p>
A common use of PHP on Apache is mod_php which is fast, as Apache loads the module into memory when starting. With lighttpd, you will use PHP-CGI with FastCGI to have the same speed and performance. FastCGI basically uses cache, which make PHP-CGI a lot faster than regular CGI (hence the name "FastCGI"!). Let&#39;s install PHP 5 with FastCGI support. Open your terminal and issue:
</p>
<pre>
# cd /usr/ports/lang/php5
# make install clean
</pre>
<p>
During compilation, you will be ask to choose and to check several options. Make sure FastCGI is selected. After PHP is installed, let&#39;s see if FastCGI support is here:
</p>
<pre>
# /usr/local/bin/php-cgi -v
PHP 5.1.6 (cgi-fcgi) (built: Sep 17 2006 23:27:28)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies
</pre>
<p>
It should read cgi-fcgi somewhere in the description as seen above. Let&#39;s install the PHP Extensions now and select the extensions you need for your development such as GD, PDF, etc:
</p>
<pre>
# cd /usr/ports/lang/php5-extensions
# make config
# make install clean
</pre>
<p>
Now that you are done installing lighttpd and PHP with FastCGI support, open <a href="http://localhost/">http://localhost/</a> to see our phpinfo() page. It should work! The last application we need is MySQL server and client, which is pretty straight-forward.
</p>
<h2>Installing MySQL</h2>
<p>
We&#39;ll now install MySQL from the ports. Just issue:
</p>
<pre>
# cd /usr/ports/databases/mysql51-server
# make install clean
</pre>
<p>
The full path to MySQL server is too long, let&#39;s make it shorter. We&#39;ll create a shortcut:
</p>
<pre>
# cd /usr/local/bin
# vi mysql-server
#!/bin/sh
/usr/local/etc/rc.d/mysql-server start $@
</pre>
<p>
Save your file. The MySQL server also has 3 options: start, restart, stop. To start the MySQL server, you will do:
</p>
<pre>
# mysql-server start
</pre>
<p>
 If you want the MySQL  server to start each time FreeBSD is booted, issue the following command:
</p>
<pre>
# echo &#39;mysql_enable="YES"&#39; &gt;&gt; rc.conf
</pre>
<p>
To use MySQL through the terminal, just issue:
</p>
<pre>
# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2 to server version: 5.1.6-alpha
Type &#39;help;&#39; or &#39;\h&#39; for help. Type &#39;\c&#39; to clear the buffer.
mysql&gt;
</pre>
<p>
To exit, type exit. Here&#39;s a few more information that will help you to get started quickly:
</p>
<p>
To create the MySQL root password, you will do:
</p>
<pre>
# mysqladmin -u root password my_password_here
</pre>
<p>
To log into MySQL:
</p>
<pre>
# mysql -u root -p  
</pre>
<p>
To create a new database:
</p>
<pre>
# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2 to server version: 5.1.6-alpha
Type &#39;help;&#39; or &#39;\h&#39; for help. Type &#39;\c&#39; to clear the buffer.
mysql&gt; create database name_of_my_database_here
</pre>
<p>
To grant permissions to a user over a particular database:
</p>
<pre>
# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2 to server version: 5.1.6-alpha
Type &#39;help;&#39; or &#39;\h&#39; for help. Type &#39;\c&#39; to clear the buffer.
mysql&gt; grant usage on name_of_my_database_here.* to name_of_user_here@localhost;
</pre>
<p>
This is it! If you try to install a popular PHP script such as phpBB, it should work just fine:
</p>
<p>
<img src="files/lighttpd-freebsd/phpbb.png" alt="" />
</p>
<p>
To learn more about MySQL, feel free to read the excellent <a href="http://dev.mysql.com/doc/">documentation</a>. Now you should have a full development environment on a strong and robust operating system with state of the art open-source applications.
</p>]]></description>
		<link>http://www.osresources.com/content/5/11/en/how-to-install-a-server-with-lighttpd-php-5-and-mysql-5-on-freebsd.html</link>
		<pubDate>Mon, 01 Sep 2008 13:07:00 GMT</pubDate>
	</item>
</channel>
</rss>