Building Websites with PHP/Nuke
上QQ阅读APP看书,第一时间看更新

Configuring PHP-Nuke

We need to tell PHP-Nuke where to get its data from, and how to get that data. This requires us to provide the name of the database and the database user we just created. We add this information into the config.php file located in the html folder of your PHP-Nuke installation.

To do this, open the config.php file in your favorite text editor (Notepad or Wordpad will do fine).

Scroll down to find these five consecutive lines:

$dbuname = "root ";
$dbpass = "";
$dbname = "nuke";
$prefix = "nuke";
$user_prefix = "nuke";

These five lines are PHP variable definitions that determine the username and password of the database user account that will access the database, and the name of the database that we will be accessing, and the table name prefix. PHP-Nuke uses these to connect to its database, so they had better be correct.

The first thing we will do is change the database username and database password to those of the database user we created earlier. Edit the lines as follows:

$dbuname = "nuker";
$dbpass = "No0kPassv0rd";

Next, we should set the database name by changing the variable assigned to $dbname to the name of the database we just created. We have named our database the same as the one specified here, nuke. If we had chosen a different name for the database, we would have had to set the value of the $dbname variable to that name.

The $prefix variable holds the value of the table name prefix, which by default, is set to nuke. We discussed the table name prefix earlier, and how all the table names in the standard setup are prefixed with nuke_. (The _ character does not need to be included in the $prefix variable). Whenever there is any attempt to access a table from within the PHP-Nuke code, the $prefix variable is used. We set the value of the $prefix variable to our changed prefix, dinop:

$prefix = "dinop";

The fifth variable, $user_prefix, is also a table prefix. There is a pair of tables in the PHP-Nuke database, nuke_users and nuke_users_temp (with the default prefix) that hold information about each user and users waiting to be registered on the site respectively. Whenever these tables are queried in the code of PHP-Nuke, the $user_prefix variable is used to get their table prefix rather than the $prefix variable. This means that these tables could have a different table prefix from the rest of the tables in the PHP-Nuke database. A consequence of this is that you could have several PHP-Nuke sites stored in the same database, each with different table prefixes, but the user prefix could be the same. This would mean that a user could have a single user account valid across all these sites. This is a more advanced use of PHP-Nuke that we won't have the space to go into any greater detail.

For now, we set the $user_prefix variable to be the same as the $prefix variable:

$user_prefix = "dinop";

For completeness, we will make a change to another configuration variable, the site key. This is a long string used in the random generation of the graphical security code that prevents automated registration or login attempts to your site. The site key can just be a random string of text, provided you don't add any quotes. The default value is this:

$sitekey = "S·kQSd5%W@Y62-dm29-.-39.3a8sUf+W9";

Let's change its value with some random pressing of the keyboard to:

$sitekey = "78w f7sys f89s fsd sj hjsg sdfw3p;";

We've told PHP-Nuke the name of the database to use, the prefix of the name of the tables, and also the name and credentials of the database user to access the database with. Our configuration is done, so let's save the file config.php and we are ready to move on.