How To Install WordPress with Apache on FreeBSD 10.1

How To Install WordPress with Apache on FreeBSD 10.1

PostedJanuary 14, 2015 24.4kviews WORDPRESS LAMP STACK FREEBSD

Introduction

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 10.1.

Prerequisites

Before you begin this guide, you must have a FAMP (FreeBSD, Apache, MySQL, and PHP) stack server setup. This WordPress installation tutorial is based on this FAMP tutorial: How To Install an Apache, MySQL, and PHP (FAMP) Stack on FreeBSD 10.1.

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 index.html file).

If you do not already have a FAMP setup, follow the linked guide before continuing with this tutorial. Note that this tutorial, like the linked FAMP guide, uses PHP 5.6.

Step One — Install Additional PHP Modules

Although you already have PHP 5.6 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.6 modules:

sudo pkg install php56-mysql \
 php56-xml \
 php56-hash \
 php56-gd \
 php56-curl \
 php56-tokenizer \
 php56-zlib \
 php56-zip

Each of these modules allows WordPress to use various functions in order to perform certain tasks. For example, php56-gd provides libraries for image handling, and php56-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 php56-mysql, 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 ofpassword. 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:

FLUSH PRIVILEGES;

Now exit the MySQL prompt:

exit

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:

rm latest.tar.gz

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 wordpress directory:

cd ~/wordpress

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:

vi wp-config.php

The only modifications we need to make are to the MySQL settings. We must update the values of the following parameters:

  • DB_NAME
  • DB_USER
  • DB_PASSWORD

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 cp command:

sudo cp -rp ~/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. For example, we will use “example.com” here:

http://example.com

The first time you visit your WordPress site, you will be prompted by a Language Select screen. Select your preferred language, and click the Continue button:

1