Data Centers

Create a news portal site with PHP-Nuke

If you need to have a news portal site up and running quickly, PHP-Nuke might be your champion. In this Daily Drill Down, Vincent Danen gets you up to speed with this handy tool.

In a previous Daily Drill Down, ”Create a news portal site with phpWebLog,” we took a look at phpWebLog, a system for delivering news content via your Web site. With news sites becoming more popular, there was a need to create high-quality, yet easy-to-administrate, sites for the Web that allow new and veteran Webmasters to easily and efficiently install, configure, and maintain news portal sites.

PhpWebLog is an ideal news site system because it is written in PHP, which makes it portable. It is also slim and fast, without lots of extra features. Unfortunately, phpWebLog is also lacking in some features that some people might find necessary; the primary one is user logins, a means for users to log in to the site, configure certain site preferences, and possibly gain access to areas of the site normally not available to anonymous visitors.

Another news portal system written in PHP is PHP-Nuke, which does provide user logins and a whole host of other features that you may find necessary for your news site, along with some little frills you might find entertaining.

PHP-Nuke, available at its official site, supports common features such as news postings, which are done in a Slashdot-like manner, as well as a voting booth and topical blocks. You can define customized pages within PHP-Nuke with little to no knowledge of HTML. PHP-Nuke supports more than 23 languages, including English, Spanish, German, French, Dutch, and Japanese. It includes a forum interface for topical discussions, which is different from the comments that can be posted under the various news stories. It even comes with a file manager so you can allow file downloads from your site in a simplified manner. It has an internal banner rotation program so you can sell advertising space on your site. PHP-Nuke has many free and readily available themes to choose from. It includes a search engine, moderation for users and administrators, even a scoring system for articles. It can use high-encryption authentication, and it is user-based, meaning that users can log in to gain personal statistics, change the look of the site to suit their tastes, and configure more personal options. Most importantly, all of this can be done through a comprehensive administrative interface.

Installing PHP-Nuke
The current version of PHP-Nuke is 5.2; it’s available on the PHP-Nuke Web site from the Downloads section. The file is called PHP-Nuke-4.4.1a.tar.gz. Save this file to your /var/www directory, assuming that you are using /var/www as your Web site root directory. On older systems, you may still be using /home/httpd as the default root location for your Apache Web server.

To run PHP-Nuke, you will need to have a Web server like Apache, PHP version 3 or higher, and MySQL or PostgreSQL for the database back end. Ideally, to have the most efficient PHP-Nuke site, you should be running Linux as the operating system as well, although PHP-Nuke will run under Windows, FreeBSD, OS/2, MacOS, and any other operating system that is capable of running a Web server, PHP, and MySQL or PostgreSQL.

To unpack the archive, change to the /var/www directory where you saved PHP-Nuke-5.2.tar and execute as root:
tar xvzf PHP-Nuke-5.2.tar

You will have two new subdirectories: html/ and sql/, as well as a number of informational files in your /var/www directory. Change to the sql/ directory now. Notice a file there called nuke.sql, which contains the database structure and some default entries for the database that PHP-Nuke will use.

You need to create a new database in MySQL for PHP-Nuke to use. Let’s call this database nuke and create it using the following:
mysqladmin -u root -p create nuke

You can then create the tables in the database that are defined in nuke.sql by using:
mysql -u root -p nuke <nuke.sql

Now your database is created and almost ready. You need to set some permissions on files and directories in the html/ directory. If you want to use the integrated File Manager, you will have to change the permissions of all files to 666 and all directories to 777. For obvious reasons, this isn't a very good security policy, so I highly recommend that you do not use the integrated File Manager. If you need to edit or modify files, you should do so via a login shell and not through the Web interface.

If you wish to use the Headlines feature in PHP-Nuke, you need to change the permissions of the html/cache directory to mode 777. With the Headlines feature, you can easily add the headlines from a variety of news sites to your system. Your site can offer in a topic box the headlines for Slashdot or Linux.com, for example. To change the permissions of the html/cache directory, use the following commands:
cd /var/www/html
chmod 777 cache


Finally, you’ll edit the config.php file in your /var/www/html directory. This is the file where you will set the database options that PHP-Nuke will use.

Near the top of the file, you’ll see some variables that need definitions. The $dbhost variable contains the name of the host running MySQL, which will usually be localhost, unless your MySQL database is located on another system. The $dbuname variable is the user name that should be used to log in to the MySQL database. The $dbpass variable contains the password for the defined user. The $dbname variable contains the name of the database containing the PHP-Nuke structures. For example, if you created the nuke database above, $dbname would have a value of nuke. If you used any other database name, use that name here. The last variable, $system, should be 0 for a Linux or UNIX system or 1 for a Windows system.

You can either continue to edit the config.php file to set the other system parameters, or you can save your changes, exit, and use the Web interface to configure the file further. The file needs to be writable by the user running the Web site (usually apache or nobody if you are running Apache), or you’ll give it a mode of 666 by using:
chmod 666 config.php

on the command line. We will opt for the Web interface in this example, so change the permissions of the file after saving it.

Before going further, you must grant the user you defined in config.php access to the MySQL database. Let's assume for a moment that you defined $dbuname as phpnuke and $dbpass as nuke4all. You would then log in to MySQL as root to give the user phpnuke with the password nuke4all access to the nuke database by using:
mysql -u root -p

After you successfully log in to MySQL, use this command to set the permissions.

This will give your defined user access to the database. Using the MySQL root user to log in to and access the database is not recommended.

Now, point your browser to http://www.mydomain.com/admin.php. The default administrator username is God with the password Password. And that's all there is to it. You now have PHP-Nuke installed and ready to configure.

Configuring PHP-Nuke
When you log in to PHP-Nuke for the first time, you must change your administrator password. Because the default is very well known, you’ll want to change this immediately.

In the Administration menu, click on the Edit Admins link. You’ll see a new box listing the admins on the site. Only God is available. You can either modify the information and change the password or you can remove the God user and add a new one. Be sure you add the new user prior to removing God. Also, when you are selecting the new author's permissions, be sure you give him or her Super User access, which is denoted in red text on the screen. This will give root access to the system. At this point, you can log out of the God account, log in under your own new account, and then remove the God account.

You can now begin configuring the site itself. First, configure some of the site defaults in the Preferences section of the Administration menu. This link will take you to a page where you’ll define the site name and the URL pointing to the base directory of the site. You can define the slogan of the site, the date the site was initially set up, and the logo for the site, which you will have to upload or copy into the html/images/ directory.

You’ll also set the administrator e-mail address for the site, which should be your own address. You’ll be able to configure whether anonymous users are able to post stories and comments, as well as the default theme for your site. If you go back to the Downloads section of the PHP-Nuke Web site, you can download a file containing a large number of themes to choose from. You can also set the language for your site; you can obtain more language files from the PHP-Nuke Web site. Finally, you can define the Local Time Format for your system which, if you're in North America, will be en_US.

Under Banner Options, define whether or not your site will use banners. If you use banners, you can enter your own IP address so that it is not counted in the number of hits or views a banner receives.

In the next section within the Banner Options page, you can define a number of customized footers for your Web site.

The next section is Web Links Default Config, where you define some defaults for the link listing on the site. You can define how many hits a site must receive before it is listed as "popular" and how many it needs to receive to be listed as the "best" site. You can also regulate whether or not anonymous users can add new links to the listing. Regardless, all links must be verified by a site administrator before they are publicly available.

The next section deals with whether or not you want new site submissions to be sent to a particular user for moderation. Here, define an e-mail address and the text of the message that will be sent when the site receives a new submission.

Further on, you can configure the type of moderation you want the site to have for comments. You can choose to have comments moderated by other users or administrators, or even disable moderation altogether. You can also define options dealing with the size of comments that can be posted to stories and the default name for anonymous users.

Finally, you can set some options for the voting booth, such as how many options can be defined in a poll and whether or not a user can vote more than once. After that, you can define some defaults for graphics, such as the location for topic images, User menu images, and Administration menu images, the default font for the site, and whether or not to use graphics in the Administration menu. I have found that disabling graphics in the Administration menu makes loading the page much faster, even if it isn't quite as pretty.

You can also define some miscellaneous defaults, such as the number of articles to display in the Administration menu, the minimum length for user passwords, how many users get listed on a page, whether or not comments will be activated in polls, and so on.

When you click the Save Changes button at the bottom of the page, these changes will be saved to your config.php file.

Because PHP-Nuke is such a feature-rich package, we won't look at all of the options in this Daily Drill Down; however, the Preferences section is where the meat of the work is done for important system settings. The rest is mostly cosmetics. In the Administration menu, you can edit the topics for stories by using the Topics Manager link. You can configure the left and right blocks (the little boxes on either side of the main page) by using the Left Blocks and Right Blocks links, respectively.

You can also configure the links on the site by using Web Links. To configure the headlines, which are displayed in blocks on the page, use the Headlines link. If you give everything the permissions that are described in the installation section, you will be able to use the File Manager link to edit and view files. However, I suspect you’re security-conscious and will not give the global read, write, and execute permissions on all files, so you can safely ignore this link. The Surveys/Polls link defines and edits your voting booth questions.

Finally, look around and try things out. There is no real documentation with PHP-Nuke, so it's mostly trial and error. It's well thought-out, however, and relatively straightforward. You should have no difficulty tailoring the site to your tastes once the primary configuration options have been set.

Conclusion
PHP-Nuke is an extremely popular package, and with the recent sponsorship by MandrakeSoft, it may become even more popular. It has had a bumpy history with some security issues, but these have all been corrected in the latest release.

PHP-Nuke is a bit of a beast, as you’ve seen here. Some people prefer a simple and effective news portal system like phpWebLog, which we looked at previously. However, for others, phpWebLog is too simplistic, and PHP-Nuke offers all the bells and whistles they’re looking for.

The best advice I can offer is to take a look at PHP-Nuke, phpWebLog, and any other news portal system you’re considering and weigh the pros and cons of each. PhpWebLog loads and displays pages quickly because of little overhead, while PHP-Nuke is a little slower-loading, due to the many configurable elements. There is a definite trade-off in terms of speed vs. features.

About

Vincent Danen works on the Red Hat Security Response Team and lives in Canada. He has been writing about and developing on Linux for over 10 years and is a veteran Mac user.

Editor's Picks