WordPress is a popular open source content management system (CMS) that can be used to easily set up a blog. It is a very flexible system, through its plugin and template support, that allows users to extend its functionality to meet their specific needs; WordPress can be customized to support anything from a basic blog to a fully-featured eCommerce site.
In this tutorial, we will show you how to set up WordPress with an Apache web server on FreeBSD 11.0
Before you begin this guide, you must have a FAMP (FreeBSD, Apache, MySQL, and PHP) stack server setup.
This tutorial assumes that you want to serve WordPress from the root of your web site, e.g.
http://example.com/, and that your Apache document root is empty (aside from the default
This article assumes you have a working and configured installation of apache24, mysql57 and php70.
Step One — Install Additional PHP Modules
Although you already have PHP 5.7 installed, WordPress requires additional PHP modules in order to function properly. We will use
pkg to install these required PHP modules.
At the command prompt of your server, use this command to install all of the required PHP 5.7 modules:
pkg install php70-mysqli \ php70-xml \ php70-hash \ php70-gd \ php70-curl \ php70-tokenizer \ php70-zlib \ php70-zip
Each of these modules allows WordPress to use various functions in order to perform certain tasks. For example,
php70-gd provides libraries for image handling, and
php70-curl allows WordPress to download files from external servers for tasks such as plugin updates. Also note that if you followed the prerequisite FAMP tutorial, you should have already installed
php70-mysqli, which allows WordPress to interact with a MySQL database.
Step Two — Prepare MySQL Database
WordPress uses a relational database, such as MySQL, to manage and store site and user information. In this step, we will prepare a MySQL database and user for WordPress to use.
Log into the MySQL administrative account,
root, by issuing this command:
mysql -u root -p
You will be prompted for the password that you set for the MySQL root account when you first installed MySQL. After providing the password, you will enter the MySQL command prompt.
We will now create the MySQL database that WordPress will use to store its data. You can call this whatever you like, but we will call ours
wordpress for our example. At the MySQL prompt, enter this SQL statement to create the database:
CREATE DATABASE wordpress;
Note that every MySQL statement must end in a semi-colon (
;) before it will execute.
Next, we are going to create a MySQL user account that WordPress will use to interact with the database that we just created. For our example, we will call the new user
wordpressuser with a password of
password. You should definitely change the password to something more secure, and you can use a different user name if you wish. This SQL statement will create our example user:
CREATE USER wordpressuser@localhost IDENTIFIED BY 'password';
At this point, you have the MySQL database and user that WordPress will use. However, we must grant the user access to the database. To do this, we will use this SQL statement:
GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost;
Before this change in privileges will go into effect, we must flush the privileges with this SQL statement:
Now exit the MySQL prompt:
The MySQL database and user are now ready for use with a new WordPress installation. Let’s download WordPress now.
Step Three — Download WordPress
Now we must download the WordPress files from the project’s website.
The archive of the latest stable release of WordPress is always available from the same URL. Download it to your home directory with the following commands:
cd ~ fetch http://wordpress.org/latest.tar.gz
Now extract the archive with this command:
tar xvf latest.tar.gz
This extracts the contents of the archive to a directory called
wordpress, in your home directory.
If you wish, you may delete the WordPress archive now:
Step Four — Configure WordPress
Before making WordPress accessible via our web server, we must configure it so that it will able to connect to the database that we created earlier.
First, change to the
To make the configuration simple, let’s base our WordPress configuration on the provided sample configuration,
wp-config-sample.php. Copy the sample to
wp-config.php, the default WordPress configuration file:
cp wp-config-sample.php wp-config.php
Now open the configuration file in an editor. We will use
vi for this purpose, but feel free to use your editor of choice:
The only modifications we need to make are to the MySQL settings. We must update the values of the following parameters:
These correspond to the MySQL database and user that we prepared in an earlier step. Look for the following lines and update the highlighted parts with your database name, user, and password:
// ** MySQL settings - You can get this info from your web host ** // /** The name of the database for WordPress */ define('DB_NAME', 'wordpress'); /** MySQL database username */ define('DB_USER', 'wordpressuser'); /** MySQL database password */ define('DB_PASSWORD', 'password');
Save and exit.
Step Five — Copy Files to Apache Document Root
Now that your WordPress application is configured to connect to your database, we must copy it to Apache’s
DocumentRoot directory, where it can be served to your site’s visitors.
If you followed the prerequisite FAMP tutorial, Apache’s document root will be located at
/usr/local/www/apache24/data—if your document root is located somewhere else, be sure to update the highlighted path in the commands in this section.
Let’s copy the WordPress files to Apache’s document root with the
mv ~/wordpress/ /usr/local/www/apache24/data/
Now change the ownership of the WordPress files to the
www user and group, which is the name of the user that runs the Apache process, so Apache will have appropriate access:
sudo chown -R www:www /usr/local/www/apache24/data/*
Now that the WordPress files are being served by Apache, you are almost ready to start using WordPress.
Step Six — Run WordPress Installation Script
The next step is to run the WordPress installation script. The script will ask you a few questions about your WordPress site, then initialize the database.
In your web browser, navigate to your server’s domain name or public IP address and continue the setup from there!
That’s it, everything should be working fine now!