How to re-create your config.php file

Occasionally I have a client whose config.php file gets deleted. This happened most recently to a client using GoDaddy for their hosting.

It’s hard to say why GoDaddy deleted it, but it wasn’t recoverable. If I had to guess, it’s because like most web hosts GoDaddy assumes everyone is running WordPress, which means phpBB gets short shrift.

Anyhow, it was gone and needed to be re-created but she had no idea how to do it. She did figure out its purpose. The config.php file sits in your phpBB root folder and its primary purpose is to connect your phpBB board with the correct database. So it’s absolutely essential and phpBB won’t work without it.

Start with an example file

Unfortunately, the config.php file is empty when setting up phpBB and gets created when you run the installation wizard. But here’s an example of a properly configured config.php file:

<?php
// phpBB 3.3.x auto-generated configuration file
// Do not change anything in this file!
$dbms = 'phpbb\\db\\driver\\mysqli';
$dbhost = 'localhost';
$dbport = '';
$dbname = 'phpbb';
$dbuser = 'forum';
$dbpasswd = 'password123';
$table_prefix = 'phpbb_';
$phpbb_adm_relative_path = 'adm/';
$acm_type = 'phpbb\\cache\\driver\\file';

@define('PHPBB_INSTALLED', true);
@define('PHPBB_ENVIRONMENT', 'production');
// @define('DEBUG_CONTAINER', true);

You can use your web host’s file manager to copy and paste this text. Obviously it will need some editing. You can also create it on your computer and upload it when done.

Check your database management system

Most phpBB boards are installed on a mySQL or MariaDB database management system. If so, leave the $dbms line unchanged. MariaDB is virtually identical to mySQL so it will use mySQL drivers. Otherwise you need to change this line to use your database management system. Use the following values:

$dbms = 'phpbb\\db\\driver\\mysqli'; // Use for mySQL or MariaDB
$dbms = 'phpbb\\db\\driver\\postgres'; // Use for Postgres
$dbms = 'phpbb\\db\\driver\\oracle'; // Use for Oracle
$dbms = 'phpbb\\db\\driver\\sqlite3'; // Use for SQLite
$dbms = 'phpbb\\db\\driver\\mssqlnative'; // Use for Microsoft SQL Server Native Driver
$dbms = 'phpbb\\db\\driver\\mssql_odbc'; // Use for Microsoft SQL Server ODBC Driver
$dbms = 'phpbb\\db\\driver\\mssql_base'; // Use for Microsoft SQL Server Base Driver

Check your host name

Generally, you don’t need to change your $dbhost line from localhost. If your database exists on a machine separate from the webserver, you’ll have to change it. You can often get this information in your web host control panel.

If all the other information is correct and you cannot connect, you will know this line has to be changed. Ask your web host the exact machine name if necessary. On my DreamHost hosting, it’s on a different machine, mysql.phpbbservices.com in my case. Simply edit the line if needed placing the machine name between the single quotes. You should not preface the machine name with http:// or https://.

Check your database port

You generally leave the $dbport line unchanged. The default database port for the database management system is used. For example, with mySQL it’s 3306. If the null string is set, the default port will be used. You can ask your web host if necessary if a different port should be used, but this is extremely unusual.

Find your database name

Generally you can use a web host control panel program like phpMyAdmin to browse your databases and determine the database name. Be careful. You may have old phpBB databases and you want to choose the right one. You can look at the number of rows in the posts table using a utility like phpMyAdmin to help you decide. Generally the database with the most rows in this table is the correct database to use. Replace the $dbname line with the correct database name, placing it between the single quotes.

Find your database user

The database user is not (usually) the same username you use to login to your board. This is the user that has privileges to access the database name found in the last step. Usually you can get this from your web host control panel.

In the most typical case, there is a MySQL databases icon you can click on. Find your database and see the username associated with the database. Replace the $dbuser line with the correct database user name, placing it between the single quotes.

This database user must have all privileges granted to your board’s database. You can check this in the same web interface.

If you have only command line access to your database, a short SQL query will show this information. For the configuration above and a mySQL database, for example, once logged into the database this command would work:

show grants for 'phpbb'@'localhost';

Set the database user’s password

If you don’t know the database user’s password, your web host control panel usually has an interface to change the database user’s existing password. Change it in this interface and replace $dbpasswd with the correct password, placing it between the single quotes.

Check the table prefix

If you used a utility like phpMyAdmin to browse your board’s tables, the $table_prefix line is easily discerned. All phpBB tables must have the same prefix. The default is phpbb_. If yours is different, replace it with the correct prefix, placing it between the single quotes.

Save the file and test

Generally at this point you save the file. To test, simply run index.php on your board and it should come up. Any errors that come up will hopefully point to where the problem is.

Occasionally, you may need to manually purge the cache to bring up your board. Delete all files in the /cache/production folder using a tool like FTP or your web host’s file manager. If queue.php exists, deleting this will remove any emails scheduled to go out, so you may not want to delete this file. Then refresh the index.php page in your browser.

You may notice other lines at the bottom of the config.php line. Generally these are left alone. But if you moved certain folders from their default location you might have to change these lines.

Check the config.php files permissions

This file must not be publicly writeable, so minimally its permissions should be set to 644 on Linux-based systems. You can use FTP or your web host control panel file manager to change its permissions.

Leave a Reply

Your email address will not be published. Required fields are marked *