Building a CMS

We will explain step-by-step how to build a content management system, using PHP for the programming language and XML or MySQL to store the data. This is not a simple tutorial but a real project to build a tool usable in production.

Why to build a CMS?

There are several hundreds of free CMS available around, why to build another one?
This project is different because we want both build a tool and explain how to build the tool. We believe that Web applications are starting now to replace desktop ones and also to replace classical website made of simple HTML pages built with an HTML editor. Now website trend to be more and more sophisticated and are made of powerful technologies and we have to know how these tools are working.
The replacement of desktop applications by web applications does not mean necessarily that we will work only online in the future but that we will use applications that are designed for the web: they can work locally also.
Another reason to know how to build a CMS is that current public products are intended only to publishing documents, if you want perform some processing on data before to publish them, you need for your own tool.

Benefits of the final CMS

Once built, this CMS will allow any user to add content to a website without any knowledge of the technologies used to let it work. Any contributors will be able to write articles with a wysiwyg editor (not in infamous bbCode or similar), and the webmaster will be able to manage articles, comments, news, etc... with no more knowledge.


The tool will require for the programmer:
- a PHP powered hosting to test the demos,
- a HTML editor,
- the Scriptol compiler to generate the biggest pieces of PHP code,
- and optionally some external LGPL tools to extend the CMS (with a forum for example).
The webmaster of the website will need only to install the final CMS and extensions on a PHP and MySQL powered hosting.

How to build the CMS: the design

We have started a project that is both a tutorial and a really functional tool. We will add tools after tool and each one comes belong a tutorial that explain how it is build, how it works and how to extend it.
The final CMS will be a set of modules that assume these features:
- Editing of articles is performed with an external wysiwyg editor.
- Exchanges with the server will be performed in Ajax (not a surprise!).
- CSS is used for presentation and for templating the CMS.
- Texts are processed to fill a template and then stored directly as HTML files, not into a database.
- Management information is stored into XML or JSON.
- User information should be stored into coded XML or into a database.
- Comments of readers are allowed for each article. They may be integrated into the HTML page (with a dynamic display at request) or stored into additional XML files.
- Contributors may be allowed to add articles also. Articles contributed are first displayed into a "proposals" category.
- RSS, forum / FAQ, news and directory will be added as extensions.

Building a Blog

Technically, a blog is a web page with a list of articles, in reversed chronological order. The main difference with a portal site is that several texts are displayed on a same page, but if we are allowed to define the number of entries in a page, we have just to set this number to 1 to convert a blog to a portal, providing this is displayed on the main page beside a permanent part that describes and links to the content of the website.
A blog must have also special tools to retrieve the texts and the ability for users to add comments, features we intend to add to our CMS.

Details of the components

Most of these steps are independent and could be achieved in any order.

Adding a wysiwyg editor to create the pages

We have to create articles with the editor, on any computer once we have entered a password.
The page are not registered directly but they are processed by an interpreter that fill a template with the content the webmaster or a contributor has entered.

Managing the menus

The page we have created should not remain orphan. A link to the file has to be created. We should be able to build menus with categories and sub-categories and add to a link to each new page coming on the site.
The name of a category is given when a text is entered and we will also be able to edit the menu.

Contributor authentication

A form will allow to enter a login and a password, prior to have right to add a content to the site. If the site allows multiple contributors, we need for a manager to give permissions and save profiles.
This will preferably make use of MySQL.

Allowing comments to the articles

The readers will be able to post comments and add replies to comments of other surfers. This turns the site into a forum and require some management. The administrator must be able to delete comments. And we have to built a system to store the comments, display them as a list or as a tree with expand and collapse commands. XML is well-suited to store a such structure.


We have to design a panel for the administrator to manage the site:
- creating or editing articles,
- deleting articles or comments,
- managing users,
- configuring the system.


A RSS feed should be created from a selection of pages or the last pages added to the site. It should work as a first input first output list (FIFO), older pages are removed first to leave room for newer articles.


A sitemap will be automatically generated. Ideally the sitemap should be updated when a new article is added. Since the standard sitemap file is an XML document, we can use this file directly to hold the list of pages, and the article manager accessible from the administering panel will be using this file.

The code