I passed the Zend PHP 5 Certification exam today. After spending a couple of weeks studying to make sure I passed it I’m thrilled at the result.
February, 2007
...now browsing by month
I'm now a ZCE
Tuesday, February 27th, 2007OSDC 2007 going to Brisbane
Saturday, February 24th, 2007Since it started OSDC has been held in Melbourne. At LCA 2007 there were rumors that a group from Brisbane were trying to move it there. According to a post on Arjen’s blog they’ve been successful. Congratulations to everyone involved.
Perhaps 2008 can be in Sydney?
Installing PDO for PHP5 on Ubuntu
Monday, February 19th, 2007For some reason there aren’t any PDO packages for PHP 5 on Ubuntu 6.10. They’re pretty easy to install from PECL but you might need to install the dev version of your database client libraries. Below is what I had to type to install PDO with the MySQL driver.
% sudo apt-get install libmysqlclient15-dev % sudo pecl install pdo % sudo pecl install pdo_mysql
You then need add the following to the end of your php.ini file(s). Depending on which version of PHP you installed they’ll be /etc/php5/apache2/php.ini, /etc/php5/cgi/php.ini and /etc/php/cli/php.ini.
extension=pdo.so extension=pdo_mysql.so
Update: Before you can install any PECL extensions you need to install the php5-dev package. For information see my post about Using PECL with Ubuntu.
Ubuntu SBS: MySQL Database Server
Monday, February 19th, 2007I’ll be using MySQL to store user information for the small business server. This could be done with an LDAP server and many people will tell you that it should be. I chose MySQL over LDAP because it’s easier to understand, easier to use and you’ll probably require it anyway.
Installing MySQL
Once more apt-get makes installing services trivial
sudo apt-get install mysql-client-5.0 mysql-server-5.0 mysql-common
That’s it!! You don’t need to do anything else in this post. I’ll cover creating a schema for users and adding a few in my next post.
Ubuntu SBS: Reverse DNS
Sunday, February 18th, 2007In the last post I explained how to configure forward DNS (turning the name into an IP address). In this post I’ll tell you how to configure BIND so that it turns an IP address into a name. I’ll also explain the SOA information at the top of the zone files.
Reverse DNS
We’re using the 192.168.x.x network so I’ll use the file /etc/bind/db.192.168. Change the name of the file as appropriate for your network. Copy the following into your file
;
; BIND reverse data file for local network
;
$TTL 604800
@ IN SOA localhost. root.localhost. (
1 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS localhost.
You now need to add entries for each IP address in the form
xxx.yyy IN PTR sbs.example.com.
This turns the IP number 192.168.yyy.xxx into the name sbs.example.com.
Once you have created the zone file you need to add it to /etc/bind/bind.conf.local
zone "168.192.in-addr.arpa" in{
type master;
file "/etc/bind/db.192.168";
allow-update{none;};
};
To hide this from people outside of the network I included it in the “external” view created in the previous post. Restart bind and you should now be able to resolve IP numbers into names.
Start of Authority – SOA
The SOA record is the first thing that appears in the zone file. The format is
<domain.name.> IN SOA <hostname.domain.name.> <mailbox.domain.name>
<serial-number>
<refresh>
<retry>
<expire>
<minimum-ttl>
Serial-number is the serial number for this version of the file. You need to increment this each time you make a change to the zone file. A good idea is to use the current date and a number in the format YYYYMMDDnn where nn is a unique number for that day. So the first zone file for today would have 2007021801.
Refresh is how many seconds to wait before polling the primary name server to see if the serial number has changed.
Retry is how many seconds to wait if a refresh fails before trying again.
Expire is the number of seconds after both a refresh and retry fail before the domain name server stops serving the domain.
Minimum-TTL is the minimum time for an entry to live.
Next time I’ll cover setting up MySQL.
Top 6 framework gripes
Saturday, February 17th, 2007I just read a post by Andrei Zmievski pleading for people to stop releasing their own frameworks. As someone who has my own (unreleased) framework I wanted to answer why don’t I use an existing framework. It’s simple really, typically they’re slow, bloated and love to provide wrappers for PHP functions.
Here are my top 6 framework gripes:
- Using their own database abstraction layer.
- Using the Active Record design pattern in production applications.
- Using a template engine instead of PHP.
- Using XML to store configuration information.
- Adding code until the framework can be used in every imaginable situation.
- Including classes that provide rarely used functionality in the core framework.
Active Record design pattern talk
Friday, February 16th, 2007At the next Sydney PHP Users Group meeting I’ll be doing a talk on the Active Record design pattern. Design patterns are simply a template for how to solve commonly occurring problems. In fact, you’re probably using them now without even knowing it.
The Active Record design pattern allows you to access a database table using CRUD (Create, Retrieve, Update & Delete) without needing to write any database code. How cool is that!!
Ubuntu SBS: Domain Name Server
Saturday, February 10th, 2007The domain name server is an important part of the small business server allowing us to connect to other computers using friendly names instead of IP addresses. Because my client has a static IP address and an ISP willing to operate the slave domain name server I configured their domain name server as the master DNS for their domain. If your ISP isn’t willing to do this then you can use a service like no-ip.com or easyDNS.
Installing the domain name server
Installing the domain name server is a simple process thanks to apt-get. Simply log into the server and type in the following command.
% sudo apt-get install bind9
Configuring DNS
Because of our network setup the domain name server needs to resolve names to IP addresses differently for internal and external clients. To do this we use “views” so that internally names resolve directly to the servers IP address while externally they resolve to the routers IP address which will port forward to the server. We will also use views so some names resolve internally but not externally.
Start by creating a new file called /etc/bind/db.example.com-external (using your domain instead of example.com) and copy the following into it.
;
; BIND data file for example.com
;
$ORIGIN example.com.
$TTL 604800
example.com. IN SOA example.com. root.example.com. (
1 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
IN NS xxx.xxx.xxx.xxx.
IN NS ns1.my-isp.com.
IN NS ns2.my-isp.com.
;
example.com. IN A xxx.xxx.xxx.xxx
;
@ IN MX 10 sbs.example.com.
;
;
localhost IN A 127.0.0.1
sbs IN A xxx.xxx.xxx.xxx
www IN CNAME sbs
mail IN CNAME sbs
This zone file will be used when resolving names for requests from outside of our network. It should never return an internal IP address and should only contain entries we want visible externally. Make the following changes to suite your environment.
- Change root.example.com to the email address of the person responsible for your DNS replacing the @ with . (hence root@example.com becomes root.example.com)
- Change example.com to your domain
- Change sbs to the name of your small business server
- Change xxx.xxx.xxx.xxx to the public IP address of your router
- Change ns1.my-isp.com and ns2.my-isp.com to the names of the slave name servers
Now copy that file to /etc/bind/db.example.com-internal (remember to use your domain instead of example.com).
% sudo cp /etc/bind/db.example.com-external /etc/bind/db.example.com-internal
This zone file will be used when clients inside our network make DNS queries. You’ll need to change all of the external IP adresses to internal IP addresses. You may also want to add entires for internal devices such as other computers, network printers and your gateway. It’s safe to put these here because they won’t be visible from outside of your network. These entries will look something like:
pc1 IN A xxx.xxx.xxx.xxx pc2 IN A xxx.xxx.xxx.xxx printer IN A xxx.xxx.xxx.xxx gateway IN A xxx.xxx.xxx.xxx
Now edit /etc/bind/named.conf.local and copy the following into it.
view "internal" {
match-clients { 192.168.1.0/8; };
zone "example.com" {
type master;
file "/etc/bind/db.example.com-internal";
};
};
view "external" {
match-clients { any; };
zone "example.com" {
type master;
file "/etc/bind/db.example.com-external";
allow-transfer {
xxx.xxx.xxx.xxx;
};
};
};
Then make a couple of changes to suite your environment:
- example.com should be changed for your domain name
- Replace xxx.xxx.xxx.xxx with the IP address for the server acting as the slave for your domain. You can add multiple lines here.
- Change 192.168.1.0/8 to suite your subnet
Finally restart the domain name server
% sudo /etc/init.d/bind9 restart
Port forwarding
To make your domain name server visible from outside of the network configure your router to forward UDP/TCP port 53 to the server.
Testing the domain name server
You should now test your DNS is configured properly by using the dig command. This needs to be done both inside and outside your network so you know each location is getting the correct result. Example queries are:
% dig @localhost example.com.au ns % dig @localhost example.com.au a % dig @localhost example.com.au mx % dig @localhost sbs.example.com.au a % dig @localhost www.example.com.au a % dig @localhost www.example.com.au mx % dig @localhost mail.example.com.au a % dig @localhost mail.example.com.au mx
From outside your network simple change locahost for your routers IP address. This will also tell you if port forwarding is working correctly.
Tip: If your queries timeout then check /var/log/syslog for the error messages.
Making it live
When you’re ready to make the your DNS server live it’s a fairly simple process.
- Configure your slave domain name servers to use your master. Your ISP or DNS hosting company can help you with this.
- Get your domain registrar to change your primary, secondary and (optionally) other DNS servers.
As you can use any of the domain name servers as the primary and secondary servers it might make sense to use your ISP/DNS hosting company’s server for this as they’ll have a faster connection.
I’ll finish the domain name server in the next post when I cover the reverse lookup.
Ubuntu SBS: Static IP address
Friday, February 9th, 2007This is just a quick post before the one about configuring the DNS server. On my clients network the server gets it’s IP address from the DHCP server. If you’re doing this then it’s important that your DHCP server always issues the same address to the server. How you do this will depend on your router.
Another option is to configure your server with a static IP address. To do this edit the /etc/network/interfaces file. You will be looking for a line like
iface eth0 inet dhcp
Once you have found that line replace it with the following (remember to change the IP address, subnet mask and gateway so they’re right for your network).
iface eth0 inet static
address 192.168.1.2
netmask 255.255.255.0
gateway 192.168.1.1
You should now restart the network interface
sudo ifdown eth0 sudo ifup eth0
If your network stops working then make sure you put in the right values. Oh, and remember to use an IP address that your DHCP server won’t try giving to another computer.
Setting up the domain name server will be out later today
This site contains my personal ramblings on Linux, PHP, Java, .NET and anything else that I feel is important.