Installing WordPress from the shell
0I just setup WordPress in a few minutes, and for all of you who are still struggling I decided I’d write a quick post how I managed to do this. As a disclaimer I must say I didn’t read anything about WordPress so probably this is already covered a million times.
- Login to your server using SSH
- cd to your web root directory (e.g. cd /var/www/mydomain.com/http-docs/)
- Type: wget http://wordpress.org/latest.tar.gz
- Type: tar xvf latest.tar.gz
- Optionally: mv wordpress/* my_desired_directory/
- ls -las and take note of the owner of the . file
- chown -R username:groupname my_desired_directory/ take note that the username and groupname should be the name you saw in step 6
- Setup a MySQL database with it’s own user and pass (make sure that the user is able manage tables in the database)
- Point your browser to http://mydomain.com/my_desired_directory/ and WordPress will take it over from there
As you can see; in less than 10 steps you can easily setup WordPress, all in all it took me longer to write this small blogpost than the setup itself and I only did the setup twice in my life. So please give the WordPress crew and community a big applause for keeping things simple!
Up and running!
1Ok everyone, this will be a small first post; I got a server up and running now after what I call “The big crash”. I have given the hardware maintenance to Strato who already did a very good job for setting up my server.
Although I could’ve switched from OpenSuse 11 with Plesk 9 to a Debian system, I decided I’m going to give this approach a try. And with some Googling I must say that Plesk has made good progress in giving control back to users who know what they are doing. Most of my wishes still had to be implemented by means of workarounds but I don’t mind much as the goal of Plesk is also easy maintenance for non-administrators.
Just a small tutorial for catch-all domains:
1. Setup your domain in the Plesk control panel (uncheck the WWW for the domain name)
2. Setup a CNAME record in the Plesk control panel (*.mydomain CNAME mydomain)
3. Login through SSH
4. vi /srv/www/vhosts/mydomain/conf/vhost.conf
5. Add just the line you need, thus in my case: ServerAlias *.mydomain
6. /usr/local/psa/admin/sbin/websrvmng -av
7. service apache2 restart
And there you go, all subdomain mishaps now redirect to your main domain.
I know the text above still looks awful, as soon as I get more into WordPress I will edit this post and fix that.
phpBenelux 2010 Conference report
0Last saturday (january 30th) it was finally there, the phpBenelux 2010 conference. I had high expectations and I can say that I was more than satisfied!
Friday-evening: we packed our bags, booked a last-minute hotel room in Edegem at the conference area and left. After unpacking we went into Antwerp and everything went wrong there for us (you know beer…..loads of it)
Saturday 08:00 – Woke up with a tremendous headache, took a shower and ate my breakfast like a man.
08:45 – Went to the conference area to sign in, although I wasn’t on the list that small issue was quickly resolved by the organisation. I was extremely satisfied.
09:00 – Opening of the conference by Stefan Koopmanschap and the first talk by Derick Rethans named “The PHP Universe”. A very insightful talk about not only the php core, but also open libraries as PEAR and PECL (pronounced as ‘pickle’). Also a small note to the developers reporting bugs to not just rant about an error but make proper reports with as much information as possible. I could only nod yes to that as bug-reports coming in at my desk often only say “It doesn’t work…” and my first question then is “What doesn’t work?” followed by “Could you give me the error message shown?”
10:15 – “Living with legacy code” by Rowan Merewood, this talk was the one I was definitly waiting for. Working with someone else’s code can sometimes give me a week full of heachache. And Rowan had some useful tips. The ones I picked up the most are using phpdoc and a nifty program called bouml which looked very useful to see dependancies of classes. The other hint was how to treat ‘scripted code’ to convert it to a nice OO MVC way. And a fair warning that you have to stay in the middle of a complete rewrite or just a dirty hack to fix a bug. Very useful presentation, and certainly one of my personal favorites.
11:30 – “Getting the most out of Solr” by Paul Borgermans. I’ve seen Paul at several phpBenelux meetings and although I never talked to him I have this feeling that he is the guy who is extremely knowledgeable and everyone can learn a whole lot from him. This was the same feeling I had when watching the presentation on Solr, there are so many ways to do searches, it is a world which I need to explore a whole lot more. At the end of the session I was inspired and lost at the same time, and it feels like I need to study this subject in detail to find my way in it. I hope I will get to it soon, but my list of things to discover is quite large at the moment.
12:30 – “PHP applications/environments monitoring: APM & Pinba” by Patrick Allaert and Davide Mendolia. A talk which I have seen before at PHP Vikinger, but I was curious about the recent changes so I decided to have a look at it again. Unfortunatley not all demo’s went smooth and I really felt sorry for the guys because they really have a hidden gem with APM. And also Pinba is a very nice tool for your kit. Luckily they could show us quite some things and the changes since the last thing I’ve seen are really nice. I will also try experimenting soon.
13:30 – Lunch, a great lunch with soup and sandwiches brought by the sponsors was served. I had the time to catch up a bit with people who I hadn’t seen for a while. But time was short, and so was the chatting.
14:45 – “PHPillow, CouchDB and PHP” by Kore Nordmann. Also a talk which I have seen at PHP Vikinger. But it’s a subject which was quite hard to understand for me, so I decided to attend again and discuss with my collegues afterwards. The talk hasn’t changed a whole lot, much about CouchDB which still feels as an odd approach, but there are situations which seem useful to me. And in the end a small part about how PHPillow will be the extension of choice to communicatie with CouchDB.
16:00 – “Passing the Joel test in the PHP world” by Lorna Mitchell. Another one of my favorites for the day. I was surprised by how many times I agreed on every single highlight in the presentation. The Joel test doesn’t only provide what is good for your development proces, but also how you keep your developers happy. In my opinion this talk shouldn’t only be given to developers, but also to managers. Absolutely fabulous!
17:15 – “Generating PDF’s using Zend Framework and Java Bridge” by Eric Ritchie. Unfortunatly due to the weather Eric wasn’t able to attend the conference in person, but the internet really saved his talk as he was able to do it from home. After a lot of Zend-talk (which I do respect), my attention got caught by how easy it is to use Java objects in a PHP application by bridging. I started seeing new possibilities right away and I have this pretty high on my list of new experiments. The PDF part was pretty hard if you don’t know the exact specifications of the document itself, but for a further future this might also be of interest to me.
17:45 – “Open Teams” by Cal Evans. I have a lot of respect for Cal, I always saw him as a real developers manager. He knows what developers want, and how to keep them satisfied. And on the other hand Cal has all the technical knowledge to foresee how things need to be done. This talk was quite different though. It was more about how developers can work in a more free environment (like from home) and how to manage them. Very interesting, and I also found various highlights which I agree on without a doubt. Although I still like to see my coworkers in person and solve a certain programming problem side by side.
19:00 – The conference ended with an Open Social sponsored by iBuildings, I wasn’t able to stay for too long. But long enough to have a laugh about 2 coworkers winning something and losing it right the same minute because they weren’t at the venue anymore. You betcha I’d rubbed that in!
Although one of them was feeling ill so I spared him a bit.
And like many other blogs I bring you the slides collected from the internet;
Some are still missing I’ll add them as soon as they come available, or drop me a comment if you have a link to the slides.
Stop the var_dump-ing and microtiming, Xdebug all the way
0Many people still rely on var_dump, print_r or echo’s to debug their code. Ofcourse this will do the job for you, but if you really want to take debugging to a new height I can only recommend to start using a debugger. In this post I will collaborate on using Xdebug.
Xdebug is a PHP extension and can be installed through several ways. I would recommend using the PEAR/PECL package as this will most probably fulfill your needs. Just login to your server and execute
pecl install xdebug
open up your php.ini and add the line
zend_extension="/usr/local/php/modules/xdebug.so"
(ofcourse using the path of your xdebug.so).
After restarting your http-server you will immediatly see a few changes in your var_dump’s; you won’t need your <pre> tags anymore. Also error messages now contain a stack trace so you can trace what path your code took while running.
Many of these features can be adjusted in your php.ini a full documentation is available on the Xdebug website.
The next step is getting rid of the var_dumps, to achieve this you will need to make a few decisions first.
Am I working on a server with multiple developers at the same time? If the answer is yes than you will need a debug proxy. Derick Rethans has written an excellent blog post about this.
If you are the only developer on the box or working on a localhost than the usual configuration settings will suffice.
Does my IDE support debugging (and in this case; Xdebug)? You will need to check your IDE documentation if debuggers are supported and how to connect to them. If you are still looking for an IDE which supports these features I can recommend Netbeans PHP and Eclipse PDT, they are both free and do an excellent job at this and more.
Debugging
Once you have your IDE set up to connect to the debugger it’s time to start adding breakpoints these are nothing more than signals to the debugger to pause code execution and show you the current state of your application (you could compare it to var_dump-ing all your variables available). If you have not found your bug yet you can continue executing your code to your next breakpoint or to the end of the execution, depending on the number of breakpoints set.
Another neat feature of debugging is stepping; your code will halt at the breakpoint, but instead of pressing the button to continue running the code you can step over to see the state of your code after the next line, or step into to go into the function your calling and continue debugging that code line by line until you get to the point where you might find your bug.
The final piece of debugging equipment are watches certain variables can be added to your watch list, you could see this as the argument you would pass to var_dump. Now you will get a list of variables you would like to watch instead of the whole bunch of all available variables.
Profiling
The other neat feature from Xdebug is profiling, if you use a profiler the execution of your code will log a certain amount of data. Using an application to open these logs will give you some insight of where bottlenecks in your code might be found.
It will show you how many times a certain function or method has been called and how much time it took to run (per call or average, you can adjust these reports in the application).
Common programs to read Xdebug profiling logs are;
WinCacheGrind – for Windows users
KCacheGrind – for Linux users
MacCallGrind – for Mac users
WebGrind – for webservers / browsers
Many more can be found on the Zend Developer Zone, but if you run into any problems or see any mistakes in the post just leave a comment.
Importing HTML strings in the SPL simpleXMLIterator
1Fairly small post I’d like to share:
Today I came accross an issue where I wanted to make use of the SimpleXMLIterator (from the SPL) with an HTML string. After giving it some thought I came up with the following solution:
function simplexmliterator_load_htmlstring($htmlString){
$DOMDoc = new DOMDocument('1.0');
$DOMDoc->loadHTML($htmlString);
$sxmlIterator = new SimpleXMLIterator($DOMDoc->saveXML());
$sxmlIterator->rewind();
return $sxmlIterator;
}
The function takes a string as an argument and passes it to the PHP DOMDocument extension, which turns the DOM into valid XML. This valid XML gets imported into the SimpleXMLIterator and returned back to your code.
Zend Framework; a solution for common problems
0As I am working more and more with Zend Framework I also noticed that I’m becoming an advocate of it at the office. This week many developers walked up to my desk to ask if we had a ready made solution for a certain problem. Most of these questions could be answered with “Zend Framework has a solution, as soon as it is adopted I do have one”.
As I posted this on Twitter, tomvm mentioned that it would be a great title for a blogpost. So here goes… I’m going to try an point out a few of the problems for which I had a plain simple solution if Zend Framework was already adopted. These are not full code-solutions, but should guide you in the right direction if you have the same sort of question.
1. I want to paginate a certain collection of data which is not the default our CMS returns. You could have a look at Zend Paginator it can take an array and additional options to make pagination very easy.Combined with Zend_db you could even set a resultset straight to the pagination, but this is more work when implementing it in an existing application.
2. I want to create an RSS feed but I don’t feel like building a whole script again, can’t this be done in a simpler way? Ofcourse this is possible, Zend_Feed provides lots of options to create or read RSS feeds. It takes a pre-defined array and from there on you can save the feed to disk or send the output directly to the end-user. 3. 4. & 5. Are we still using PHP Mailer? / Which version of PHPMailer are we using? / The PHPMailer provided doesn’t work on Apple Mail, do we have anything else available?Why not use Zend_Mail? It’s almost identical in usage to PHPMailer but personally I have more trust in the maintenance of this component as many more people are using it and it is part of a highly QA’d framework. 6. I need a soap client, which version of NuSOAP do we use?Well if we have Zend Framework available we could take advantage of Zend_Soap_Client, now we use various versions of NuSoap and we have to maintain the updates ourselves and check backwards compatibility with each update. Zend Framework provides backwards compatibility for each mini release. 7. I want a ready-made captcha class, could you provide me with one?Sure, Zend_captcha can take care of business, gives you more time to worry about the flow of the application after submitting the form. I have been fiddling around for just a little with it, but I’d love to have a further look. 8. I want to connect to certain Google services to retrieve data and put it in my own layout or website, are there full PHP classes for this? Although it still depends on what you want to do, Google has a lot to offer and so has Zend Framework. If you take a look around in Zend_GData you will see lots of examples for communicating with YouTube, Google Calendar or even Picasa. As you can see Zend Framework has a lot to offer, and there is even more. Start of browsing through the documentation at http://framework.zend.com/manual/en/ if you run into a problem that is probably solved a 1000 times before. Big chance that there is already a solution which has been tested, proven and built on best practices. I use Zend Framework daily at home, and think it won’t take long before it will also be adopted at the place I work. It saves a lot of time which you can use for the harder issues and makes all repetitive work easier and more maintainable.
phpBenelux Meeting; PHP and Microsoft Technologies
0Yesterday another phpBenelux meeting about a rather controversional subject; PHP & Microsoft technologies.
The meeting started around 07:00PM at the top-floor of the glass Real Dolmen building. Unfortunatly not many of the community members showed up as this was a wonderful oppertunity to get an update on Microsoft’s effort to support the open source community.
The first presentation (by Maarten Balliauw and Kevin Dockx) was aimed at using Silverlight and how to combine this with PHP. The presentation caught my attention due to seeing the features of Silverlight (/ Moonlight for linux based OS’s). On the other hand I did not see what this had to do with PHP, the only type of connection was a service based one (SOAP/JSON/XML/REST etc..) which we all know and love. Ofcourse the connection was made using Zend_Soap from the also very well beloved Zend Framework.
To manage connections and on which transportation protocols they should run, a Silverlight developer can make use of the Windows Communication Foundation.
An example of a beer-order-application in a cafe was used during the presentation, the concept was straightforward; a customer orders a beer and the bartender gets the order on screen.
The frontend was completely build using MXML with C# code behind it to make it all work. MXML could be seen as the equivanlent of Adobe Flex, C# can be seen as the equivalent of ActionScript 3 (for all the flash-minded people).
It was quite funny how easily a developer could place a button in a button and change it’s properties (not the best example, but it is possible..) using nested MXML tags. When looking at the internal structure of the button tag we could see that it is also build up using other MXML tags (Squares, Labels etc etc).
The Microsoft minded people were also in for a surprise, they brought up wonderful design patterns and solutions like for Observers, Singletons etc etc…. Untill Michaelangelo van Dam interfered and told them that the PHP SPL library recently also added these features (Observer php-example), a conclusion was quickly made; PHP has grown up.
For developing the front end several tools are available; Visual Studio, Microsoft Blend or even Eclipse4SL
The second presentation (by Katrien De Graeve) was aimed at what Microsoft is doing to support the PHP community. To me the most appealing were;
- Every PHP release should be considered stable for Windows before releasing.
- FastCGI for IIS 7 (it always was a choice between ISAPI or CGI installation. ISAPI was seen as unstable while CGI was quite slow, fast-CGI will solve the latter)
- Native MS SQL driver; the equivalent of the mysql_* driver, but used for MS SQL
- Application layer for Windows Azure (pricing for the Azure platform in europe will be available soon).
Windows Azure was quickly demo’ed, very interesting to see the possibility to deploy applications, and also very good to see that Microsoft is cooperating in Simple Cloud for cloud computing management.
At the end one copy of Windows 7 Ultimate was raffled, and I got lucky
Thanks to everyone for another great meeting, this is what keeps us developers up to speed on all the great technologies available, and I would like to encourage everyone to attend as many as possible and join the community!
Long time no blog
0It’s been a long time since I’ve created a new blog item. And I must say I’ve been quite busy though. The good news is that I have found new challenges and lots of inspiration in the PHP Benelux user group.
- The why equal doesn’t equal quiz
- Symfony components
- Gearman
- PHP and the Cloud
- Performance tuning
PHP Vikinger report (May 30 – Leuven, Belgium)
0On May 30 I have attended the PHP Vikinger event in Leuven. The event was an unconference meaning that it had an open program and anyone who stood up could speak out. This is a very fresh and interesting approach for getting the best talks.
I arrived at Cafe Sport on the martelarenplein in Leuven at 09:15 and all was still dark. So I started checking if I wasn’t there on the wrong day. But while I was checking the first people came walking in and the cafe was opened.
At 10:00 we were all setup and ready to inventorize all the subjects people wanted to talk about. After that we all voted (by raising hand) on which speeches we would like to here, the list after this voting looked as following:
Nooku 5
XSLT 8
PCRE 5
CLI & PCNTL 9
Dependancy Injection 13
Eclipse PDT 7
MVC 7
APM 20
Testfest 7
Run-tests 3
PDM 18
Search 10
PHPillow 12
Some people still had to prepare their talks so we worked through the list by readyness and interest.
10:30 CLI & PCNTL
The first presentation was given by Thijs Feryn about CLI & PCNTL, he shortned the presentation quite some bits because the set time for each presentation would be approximatley 1,5 hour. The main focus was on how to utilize PHP as a command line tool for things which would normally be put in a cron using wget or lynx which is a bad pratice (I know because I found out the hard way….). The presentation is the one below:
11:15 XSLT Templating
The next session was all about XSLT templating by Thomas Weinert, how clean and dynamic things can get by using XSLT as a weapon of choice. Although I voted for this session it still felt as a bridge too far. Maybe this is also due to the complexity and my non-interest for front end work. I do think there will be advantages (because I had just seen them), but SMARTY still works great for me. Maybe I’ll just dig into this subject once more when I have some time for it.
12:10 Testfest results
Just before lunch got served we had a small presentation by Zoe Slattery, she gave some insight on how bad the code coverage was in the past and how PHP is improving on covering it’s code by the community. She also summed up some ups and downs from previous Testfest events given by local PHP communities.
12:30 LUNCH!
Had a great lunch (a smos martino to live up to my name) and talked to some great people about the added value of XSLT and project development cycles. I also met up with someone who went to the same school as I did back in 1999. We just never been in the same class (as in classroom, and classmates, not an instantiatable class).
13:45 Search
The first session after lunch was given by Derick Rethans and was about search, an interesting talk about tokenizing and working with different languages. This is something I usually don’t pay enough attention to. I still work by searching in the most simple ways. So it works, but isn’t intuitive. I’m deffinitly going to look into this further.
14:30 APM
The next session also made all my senses tingle, it was given by Patrick Allaert about his new extension called APM (Alternative PHP Monitor). It should become the Zend Platform killer for debugging and monitoring applications on production servers. It’s main focus is on performance and usage. Keep an eye open for this project via http://code.google.com/p/peclapm/ I have a feeling this is going to be HUGE.
15:15 Break
At 15:15 we went outside for some time for a break. After looking together with Cal Evans how a bunch of belgian cyclists jammed up the traffic (while they held an event for getting enthousiasm for cycling) I went back inside to process some of the info I just took to me.
15:45 PDM
The following session was about the PDM (to continue on the acronyms) which stands for the PHP Developers Meeting. Derick Rethans and Scott MacVicar gave us some insight on what PHP 5.3′s status is and what is upcoming for PHP 5.4 or 6 (it’s still uncertain if 5.4 is going to be 6 or not, it depends on the development time).
16:25 PHPillow
The final session by Kore Nordmann was about PHPillow a wrapper for CouchDB, the session started off by giving more insight about what CouchDB is and ended in what PHPillow can do to ease the tasks of maintaining the CouchDB. You can view the complete presentation at http://kore-nordmann.de/talks/09_05_phpillow_couchdb.pdf
I’ll try to find some time to expand my report a bit, but as I am very busy this week I cannot make any promises. I would like to thank everyone for the great day at PHP Vikinger, I’ve seen and learned a whole lot again on this day.
My first actively developed singleton design pattern
0This week for the first time in my life I have created a component for which I use the Singleton design pattern actively.
Some of you might want to know what a Singleton design pattern is, well the defenition is;
Ensure a class has only one instance and provide a global point of access to it.
It achieves this by only creating a new instance the first time it is referenced, and thereafter it simply returns the handle to the existing instance. So this made it perfect for a crumbpath component.
The class looks as follows:
class crumbpath {
private static $instance;
private static $crumbArray = array();
private function __construct() { }
public static function getInstance(){
if (!isset(self::$instance)) {
$classname = __CLASS__;
self::$instance = new $classname;
}
return self::$instance;
}
public function addCrumb($name, $link){
$this->crumbArray[] = array(
“name” => $name,
“link” => $link
);
}
public function retrieveCrumbs(){
return $this->crumbArray;
}
public function __clone(){
throw new Exception(‘Cloning of’.__CLASS__.’ is not allowed.’);
}
}
Now if you want to use this class you could use the following code:
$crumbPath = crumbpath::getInstance();
$crumbPath->addCrumb(‘Home’, ‘/index.html’);
$crumbPath->addCrumb(‘Listing page’, ‘/list.html’);
And if you want to further append the crumb from anywhere else in your code:
$crumbPath2 = crumbpath::getInstance();
$crumbPath2->addCrumb(‘Item detail’, ‘/detail.html’);
You will notice that even though the $crumbPath is out of scope, it will still return the same object with the same state during runtime of your script.