How To Install WordPress with Apache on Iocage

Okay so it’s been a while since I have posted anything so I thought that I would share how to install WordPress with Apache in a FreeNAS jail (iocage).

For those of you that may be new to this WordPress is a very popular open source content management system. In fact, you are reading this page from what is called a WordPress site. WordPress is extremely easy to use and there is a multitude of plugins and templates that will give your site more fuctionality from a basic blog to a full blown eCommerce site.

In this tutorial you will:

  • Setup an iocage jail
  • Build a FAMP (FreeBSD, Apache, MySQL and PHP) stack server setup .
  • Prepare the MySQL database
  • Download & Configure WordPress

Setup the iocage jail

Click on the Shell Icon as illustrated below

and paste in the following commands:

cd /tmp
git clone --recursive
cp -R iocage/iocage/lib/ /usr/local/lib/python3.6/site-packages/iocage/lib

followed by:

iocage create --name "{Name of Jail}" -r 11.1-RELEASE ip4_addr="vnet0|{Your Chosen IP Address}/24" defaultrouter="{Default Gateway}" boot="on" host_hostname="{Hostname}" vnet="on"

Before you post this command make sure you change the following:

{Name of Jail} – The name of your wordpress site
{Your Chosen IP Address} – Add the IP address manually.
{Default Gateway} – Usually it is but check you router for this.
{Hostname} – I usually name it the same as the jail

After a minute or so you will now see a confirmation that the jail has been started along with the necessary services.

Now enter the following command:

iocage console {Name of Jail}

This will now take you into the jail root where you will carry out the rest of the installation.

Build the FAMP stack server

Installing the Apache Web Server can be achieved by downloading it from the package repository. This can be done by using the following command:

pkg install apache24

Once installed you will need to enable the service with:

sysrc apache24_enable=yes

Make sure you also start the daemons by running:

service apache24 start

You can now test to see if the server is running by entering the jail’s IP address. If all is well then you should see the following.

Next is to install MySQL Server with:

pkg install mysql56-server

Again, you will need to enable the service this time with:

sysrc mysql_enable=yes

Followed by:

service mysql-server start

Now you will need to configure MySQL as at the moment the installation is completely insecure. So to secure it use the following command:


MySQL server will now ask you for a root password. Since you have not set one yet just hit return. Now you will be asked to set a new root password, follow the prompts to enter the new root password. You will also be asked some more questions but you can simply strike the return key to accept the default settings.

Now that you have secured MySQL server you now need to create the database for WordPress. To do this run the following command:

mysql -u root -p

You will now be asked to enter the password you have just set. Once you have logged into MySQL server, you will need to run the following commands to create the database and a password to secure the database.

To create the database use the following comand:


You will now need to create a MySQL Server account with the following command:

CREATE USER wordpressuser@localhost IDENTIFIED BY '{Your Password}'

Remember to change the {Your Password} to a password of your choice. Next you will need to grant all privileges to the wordpressuser account with the following command.

GRANT ALL PRIVILEGES ON wordpressdb.* TO 'wordpressuser'@'localhost';

Flush all existing privileges with:


So that’s MySQL server setup and secured and the wordpress database setup as well. The next step will be to install the necessary PHP modules.

Install the PHP Modules

To install the PHP modules simply use the following command:

pkg install redis php72-ctype php72-dom php72-gd php72-iconv php72-json php72-mbstring php72-posix php72-simplexml php72-xmlreader php72-xmlwriter php72-zip php72-zlib php72-pdo_mysql php72-hash php72-xml php72-session php72-mysqli php72-wddx php72-xsl php72-filter php72-curl php72-fileinfo php72-bz2 php72-intl php72-openssl php72-ldap php72-ftp php72-imap php72-exif php72-gmp php72-memcache php72-opcache php72-pcntl php72 mod_php72

Now you will have to copy the php configuration to /usr/local/etc/ by running the following command:

cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini

Now rehash in order to regenerate the system’s cache which contains information about our newly installed executable files. To rehash run the following command:


The next step is to configure the Apache server so that it know how to handle and execute PHP files. This is achieved by editing/creating the php.conf file by running the following command:

nano /usr/local/etc/apache24/Includes/php.conf

Copy and paste the following code into the file:

<IfModule dir_module>
     DirectoryIndex index.php index.html 
     <FilesMatch "\.php$"> 
         SetHandler application/x-httpsd-php 
     <FilesMatch "\.phps$"> 
         SetHandler application/x-httpsd-php-source 

Save the file with CTRL + X and then restart the server with:

service apache24 restart

You have now successfully configured the  FAMP stack. You are now ready to download WordPress.

Download and configure WordPress

Before you download WordPress you need to change the directory to a temporary directory this is where we will download and unzip the WordPress software. To do this run the following command:

cd /tmp

Next download the latest version of the WordPress software with:


Once downloaded, extract the files with the following command:

tar xvf latest.tar.gz

Finally, you can now copy the newly extracted files to Apache servers webroot. This can be done by using the cp command as outlined below:

cd /tmp/wordpress/
rm -rf /usr/local/www/apache24/data/index.html
cp -pr /tmp/wordpress/* /usr/local/www/apache24/data/

Now change the permissions recursively to the files and directories ownership as www:www using chown so that the Apache server will have full read and write permissions:

chown -R www:www /usr/local/www/apache24/data/

If you have followed the instructions correctly you should be able to access the WordPress web based installation page by pointing your browser to https://ip-address. You should see the following page.

Select you language from the list and click continue and you will see the following screen.

Click on the Let’s go button and you will then be taken to the configuration screen. On this screen you will need to enter the following…

Database Name: wordpressdb
Username: wordpressuser
Password: {Your Password}
Database Host: localhost
Table Prefix: wp_

The final step will be to enter the site information and create an administrator account. When you have entered all of the required information clic on the Install WordPress button.

Once this has been completed you should then see the success page. Simply browse to your WordPress site, enter the administrator username and password and you will be taken to the WordPress dashboard.

Congratulations, you have just installed and setup a FAMP server stack and downloaded and configured a dedicated wordpress site. All you need to do now is use your imagination to create your site content.