Home » PHP


Post Archives
Archive for the ‘PHP’ Category

Installing / Updating PHP to PHP 5.4 PHP 5.5 or PHP 5.6 on Webmin / Virtualmin

December 31st, 2014 No comments

We use Webmin / Virtualmin to simplify management of our development and test servers with cPanel used to run the production servers. Most of the php software we develop and CMSes we use either require or prefer to have php 5.4+. However Webmin / Virtualmin come with PHP 5.1 and PHP 5.3 for CentOS 5 and CentOS 6 respectively. Obviously these are VERY outdated version that are end of life and as such should really be updated to something later. The problem is however there is no information on webmin / virtualmin website on how to do this properly. The information is pretty poor on this topic in general.

The reality is this process is extremely simple and there is nothing that special about a CentOS system running Webmin / Virtualmin to help with management compared to a standard CentOS system (at least as far as PHP is concerned).

What you basically need to do is:

  1. Install a yum repo that has php 5.4 or whatever version you are after
  2. Run yum update to update to the appropriate version

The are two up-to-date yum repos out there:

  • Remi – http://blog.famillecollet.com/pages/English-site-introduction
  • Webtatic – https://webtatic.com/

Both websites have information on how to install the repos and if you’ve found yourself here you should take a bit of time and learn about yum repo management and what remi and webtatic are by going to those sites (which is why I’m not copy pasting how to install the repos here).

After that you will need to run yum –enablerepo=appropriate-repo update php\*.  For remi you can read more about it on the following page http://blog.famillecollet.com/post/2014/06/27/PHP-5.4.30-and-5.5.14

Hope this helps someone trying to do the same thing.

Categories: PHP Tags:

WAMP Install Apache Service on Port Different to 80

January 20th, 2012 No comments

Sometimes you want to install more than one webserver on the machine.  WAMP Server is great for running an Apache, PHP, MySQL stack without installing each component manually.  However when you try to install Apache as a service WAMP tries to install it on port 80.  Luckily WAMP is very flexible and it’s easy enough to change so that it installs on a different port (or rather you don’t even check what port you’re installing on).

To do this, simply go into wampmanager.tpl and find the tag [ApacheServiceInstall].  Below it you can see what actions get executed when you run the icon.  The simples thing to do is to comment out the first action, which runs testPortForInstall.php located in the scripts folder.  Alternatively you can modify the php script to test a different port.

Then modify your httpd.conf file and run the Install Apache as a Service from within WAMP.

Categories: PHP Tags:

Yii 1.1 Application Development Cookbook Book Review

September 14th, 2011 1 comment

Yii 1.1 Application Development Cookbook Book Review
It seems like a few other people looking for information on Yii Framework, the folks at Packt Publishing have also stumbled across my blog and thought it was worth reading… As a result they have asked me to review their new book by Alexander Makarov called Yii 1.1 Application Development Cookbook. I only got the book today, so havn’t yet even had a chance to open it, but I already think it’s a great thing that the folks at Packt Publishing recognise the potential of Yii Framework and it’s quickly growing community and the need for good quality documentation and learning material. After all, as nice as the online cookbook is and as good as all the tutorials are, I personally usually prefer to pick-up a hardcopy (or softcopy) and go through the new topic in a more structured way with someone who has experience on the particular topic guiding me through.

My experience with the last Yii Framework book by Packt wasn’t that great as I found that it focused too much on methodology of agile programmign with too much focus on testing instead of a more in-depth discussion of Yii Framework features, but this book looks a lot more promising. Also, I’ve asked Packt Publishing to send me the equivalent books on Zend and CodeIgniter so that in the spirit of comparison (which is what folk are usually looking for) I can not just review the book but also compare the books side-by-side to pass some judgement on the quality of the latest books available for each of these frameworks (with which I’m quite familiar without the need for the books already). One initial observation already is that the Codeigniter book is a bit outdated as CI has moved on to release 2.0 now with quite a few changes including ditching PHP4 support.

Anyways, stay tuned for the full book review, which will appear on this same URL, so feel free to link to it, so that by the time the review is up, folks will be able to easily find it.

Also, you can Buy Yii 1.1 Application Development Cookbook Book by following the link to the Packt Publishing website and if you’d like a sneak peak here’s free chapter on Extending Yii Framework

Categories: PHP MVC Frameworks Tags:

Yii and Zend for PHP = ASP.NET and ASP.NET MVC for C#

January 25th, 2011 2 comments

In the past I have extensively used ASP.NET and ASP.NET MVC in C#.  In C# they are basically the only options and it would be rather crazy to try to come up with your own high-level web framework on top of C# and rightfully so.  However when I moved over to be doing a lot of web development in PHP (see PHP for ASP.NET Developers which I blogged about before) things were not so rosy.  PHP is a great scripting language, many things are very simple to do and well geared towards web development.  However, a bad (and a good in some way) thing about PHP is that it’s a very low level language and doesn’t provide many of the higher-level framework nicities that is provided with ASP.NET and ASP.NET MVC straight out of the box.  By nicities I mean things like structured request routing and handling (with hooks/events), page lifecycle, MVC separation, configuration management (e.g. web.config), logging and so on.  It is also a fact that many PHP developers and participants in open-source projects are not professional programmers with an IT or software engineering degree.  What all of this has lead to is A LOT OF HORRIBLE ARCHITECTURE AND CODE.  Having looked through the source code of many many open source PHP projects, there is only a very very small handful that I would say are very well architected.  In some cases there is no architecture at all, in other cases there is some attempt at architecture but it’s not particularly good and in other cases things are over-architected to the point that making even a small change, let alone a complex change becomes extremely difficult.  For many users of these open-source projects this of course doesn’t matter as they don’t ever have to look at the code, but for anyone looking to make serious changes this is quite a problem indeed.  The best architected open-source applications I’ve seen are OpenCart (has it’s architectural flaws, but not too bad), being a Shopping Cart application, and Drupal (being a CMS).  Some people may say Drupal is not well architected because it’s not PHP5 Object Oriented code, but I don’t think you need to have PHP5 or OO for an application be well architected.  For example in C you can structure your application well, or you can structure it poorly and same goes for PHP.  You don’t have to use the latest technology to structure it well.  Sure there are obviously certain performance factors that come into play when you have load lots and lots of modules just to see if they’re enabled, but such is life when you’re building a configurable system.  Other applications in those classes of applications are not very well architected at all.  Here’s a non-exhaustive list:
Shopping Carts

  • PrestaShop – Pretty ugly architecture, poor file structure, doesn’t use MVC (poor form for a modern application), un-necessary use of Smarty for templating, all the admin code output using echoing directly out of modules instead of using MVC pattern, etc.
  • osCommerce – No programming standards, mix of code and markup, terrible code re-use, and just plain ugly bad design.
  • ZenCart – TERRIBLE design rooted in osCommerce that’s almost impossible to change if you try to make serious modifications as you have to change way too many files.
  • Magento – Over-architected to the point of obscrurity (not unexpected given it is based on Zend Framework) which impacts performance and requires lots and lots of caching.
  • Commercial Carts – This includes CSCart, X-Cart, etc – There is some attempt at decent architecture but often it still comes up short.

CMS / Blogs

  • Joomla – Over-architected MVC design and terrible rigid structure and security model.
  • WordPress – Horrible mix of PHP and HTML, although workable to some degree, it is far from well architected.
  • ModX – Ok-ish architecture but also rather ugly when you look at the code.

Now when it comes to frameworks, which is more the subject of this post, things don’t change much.  Most of the frameworks are also poorly designed and structured with their design patterns firmly rooted in PHP4.  This includes CodeIgniter, Kohana, DooPHP and pretty much every other framework I’ve looked at with the exception of Yii and Zend and perhaps Symfony and a few others (see Choosing the Best PHP Framework).  Ultimately after much research I’ve found Yii and Zend to be by far the best structured (with Zend over-engineered).  What I have found is that Yii Framework is by far the closest thing there is to .NET so I’m finding that any application that I’m looking to write even if it’s a console application is well handled by Yii, even if it’s because it has a decent architecture (which I can’t fault).  I’m finding that even for little PHP scripts without a user interface and simple web applications it’s easier and better for me to use Yii Framework even just because of the database access and configuration capabilities that it provides and of course the structured design.  I do find that it is still lacking a few things that are general framework classes (e.g. HttpClient, Application File System) rather than anything specific to do with web development).

Categories: PHP Tags:

Yii vs Zend vs Code Igniter Comparision

January 6th, 2011 97 comments

Choosing a PHP framework is not an easy task, especially if you have relatively little experience in PHP to know what makes a good framework or and what doesn’t, but choosing the right PHP framework for the job is absolutely critical in the long term as choosing the wrong PHP framework can lead to a number of negatives, such as longer development time, need for more experienced staff who may be hard to find and of course performance problems.  Unluckily (or perhaps luckily) when it comes to PHP there is such a plethora of PHP MVC Frameworks that it’s damn hard to actually boil them down to the final choice.  With ASP.NET for example it’s quite easy (although it’s gotten a little more complicated lately), previously there was only ASP.NET but now there’s also ASP.NET MVC, which is very different development paradigm and has it’s own catches.  However, one thing with .NET is that you need to choose how you’re going to do your data access, etc, but with most PHP Frameworks there is usually only one or two ways and they tend to do the job quite well.  So, now with this brief introduction, here’s the thoughts on Yii Framework (1.1.5) vs Zend Framework (1.11.0) vs Code Igniter (1.7.2).

Read more…

Categories: PHP MVC Frameworks Tags:

PHP for ASP.NET Developers

January 2nd, 2011 1 comment

ASP.NET is very nice to use for developing web applications but also comes with a few cons.  The biggest drawbacks of ASP.NET (including ASP.NET MVC) are that it’s more expensive to host than PHP (and you can’t use certain programming concepts if you want to host on shared servers because they require full trust) and you pretty much need to use Visual Studio to do the development (although you could use the Express edition if you’re doing something basic).

Because of these drawbacks some people (like myself) have looked at other options (of which PHP is one).  In the recent years PHP has matured into a pretty decent OO programming language, but raw PHP is still very low level and doesn’t give you much guidance or have much of a framework for implementing your applications.  This of course requires you to be far more skilled in PHP and application architecture in general and would take much more time.  Having a good IDE is also improtant for productivity.

Luckily there is a very nice solution to this problem.

  1. Use an IDE – There are two mature (and FREE) IDEs you can use to develop PHP.  They are Eclipse PDT and NetBeans.  NetBeans kind of comes with everything there (e.g. SVN and Mercurial support), but I still find that Eclipse PDT is the better option, especially if you’re doing much deployment via FTP (with the Aptana Plug-In).  Eclipse PDT also has much better SVN support than NetBeans when you add the Subclipse or Subversive plugins.
  2. Use a PHP Framework – There are far too many PHP frameworks around, and sadly most are not up to scratch or what one would be used to coming from the ASP.NET environment.  However, there are two awesome frameworks which have a good combination of performance, good architecture and are most similar to ASP.NET.  They are Yii Framework and Zend Framework.  Yii Framework seems to have borrowed may concepts from ASP.NET and is an absolute pleasure to use.  It even solves problems which are still a bit of a pain in ASP.NET (e.g. paging in lists).  It is also significantly faster than Zend Framework and hence is my preferred choice.  Zend Framework is more feature rich than Yii Framework, but it has a degree of complexity and doesn’t perform all that well in shared hosting environments.  If you want to use some Zend Framework features with Yii you can easily do so, so you can get the best of both worlds.

That’s pretty much it… By combining those two concepts you can do pretty much the same thing in PHP as you can in ASP.NET without the associated expense.

Categories: ASP.NET, PHP Tags:

Yii DAO vs Active Record Performance

May 29th, 2010 10 comments

I’m writing a new app using Yii Framework, but one of my concerns with Yii has been the impact of using ActiveRecord and ORM on the application performance, so I decided to actually compare how the two perform and the results are quite interesting…

Read more…

Categories: PHP MVC Frameworks Tags:

Codeigniter Template Layouts

May 28th, 2010 6 comments

All I have to say is WOW… I decided to give CodeIgniter a try as it’s a pretty light weight library and doesn’t try to force you into using ActiveRecord, but guess what?  There isn’t a built-in template layout concept so you can add a consistent header and footer and that’s like the most common thing anyone will do with a website.

Read more…

Categories: PHP MVC Frameworks Tags:

Writing a Fast PHP MVC Framework – Part 1

May 26th, 2010 8 comments

Well, after tossing and turning and considering using Yii and CodeIgniter, I’ve decided to bite the bullet and write my own fast PHP MVC Framework, that’s not bloated with features or compatibility layers I don’t want and takes advantage of PHP5.  Why re-invent the wheel you ask?  Because in my view what’s current out there is bloated and not quite what I want and most importantly ultimately impacts performance, which I very much about.  This framework that I’m writing is going to focus on speed and keeping ways to do something to an absolute minimum and do only what’s required.  For example, Yii is hell-bent on using ActiveRecord for everything and if you look at the code for active record with it’s built in ORM it’s like 2000 lines of code to generate SQL that you can write yourself just as easily.  With or without opcode caching lots and lots of code, lots and lots of files and all the un-necessary logic is still going to slow things down.  In CI’s care it’s nice and all, but it doesn’t play nicely with PHP IDEs atm so you better know the classes and methods pretty well.  Also, I can’t say I see the reason for doing things like defining file extentions (i.e. .php) as a constant, implementing fancy stuff like :any in the router and so on… just un-necessary logic… but as I said the biggest issue is not playing nice with PHP IDEs like NetBeans and Eclipse PDT.  The closest thing I’ve found to what I like has been what Daniel’s implemented in OpenCart which is somewhat based on PHP Pro MVC tutorial.  So to get started…

Read more…

Categories: PHP MVC Frameworks Tags:

ORM vs Code Generation

April 25th, 2010 4 comments

It seems no matter where you look these days everyone is using ORMs.  Every PHP Framework you look at has an ORM and it seems the preferred way to access data and .NET also now has LinqToSql and LinqToEntities which are both just ORMs.

I look at all these ORMs and read about problems with them where they don’t generate some SQL correctly, require you to learn a new language that tries to wrap SQL but doesn’t have the same power and it really makes me sad.  People have just no idea… They are prepared to trade off control and performance for some new concept that doesn’t really add anything good.  The productivity isn’t really increased all that much and you don’t really cut down on code all that much either if you are using code generation.

Now, code generation on the other is sooo much better and I’m really surprised that it hasn’t made it into all the frameworks and environments.  Code generation takes the mundane work out of initially creating lots and lots of similar code for the likes of CRUD operations but then you can quite easily modify it as needed.  Also people have built great big libraries like NetTiers that are based on code generation, but ultimately even those aren’t really needed.  The beauty of code generation is that you can generate really lean code and hence don’t really need all the compexity.

Ultimately I think serious developers will end up going back to good old SQL and code generation after this latest ORM fad is over.  If you want to write less code then just use a code generator, not some black box that does takes up CPU cycles and spits out SQL that isn’t guaranteed to be right.

Categories: PHP MVC Frameworks Tags: