Setup a FreeNAS 9.2 LAMP Jail

We'll assume for the moment that you have already setup a 'portjail' in freenas, and can SSH in to it to run these commands.

# Grab the ports download, about 75MB (November 2016)
portsnap fetch

# Extract the compressed file
portsnap extract

# Just in case you already have the ports collection installed
# and the about two commands give you errors

portsnap fetch update

# Add the Nano file editor, less of a learning curve than the Vi editor
cd /usr/ports/editors/nano

make config install distclean

# Install the bash shell for scripting, the default 'tcsh' shell is harder to script for
# Alternatively, you can just use the 'sh' shell that is installed by default
cd /usr/ports/editors/bash
make config install distclean

# Install an update to the package manager, otherwise you can't install the Apache24 port
cd /usr/ports/ports-mgmt/pkg

make config-recursive deinstall reinstall distclean

# Install Apache 2.4 web server
cd /usr/ports/www/apache24

make config-recursive install distclean

# So that you can start the Apache web server, a line needs to be added to the /etc/rc.conf file
echo "apache24_enable=YES" > /etc/rc.conf

# Start the Apache web server to make sure it installed correctly
# You will probably get a warning about the server name, it can be ignored.
# There are plenty of guides on how to fix this warning
service apache24 start

# Point your web browser to the host name or IP address of the FreeBSD
# host you’ve installed Apache on and you should see the “It works!” output
# If you get errors here you'll need to do some searching to fix the problem.
# If you managed to install the previous ports ok, then your internet connection
# works, so it may be a configuration error in Apache, the configuration
# file can be found at /usr/local/etc/apache24/http.conf

# Install the mysql56-server port. The mysql57-server port is broken in
# freebsd 9.2, so use mysql56-server

cd /usr/ports/databases/mysql56-server
make config-recursive install distclean

# A line needs to be added to /etc/rc.conf to allow the Mysql server to start
echo "mysql_enable=YES" > /etc/rc.conf

# Check that the Mysql server starts ok
service mysql-server start

# There is currectly no password for the Mysql root user, which really should
# be changed for security purposes
mysqladmin -u root password NEWPASSWORD

# Install PHP 7.0
cd /usr/ports/lang/php70

make config-recursive install distclean

# Install the Apache PHP module
cd /usr/ports/www/mod_php70

make config-recursive install distclean

# Install extensions for PHP. If you are unsure here, use the defaults as you can
# always 'make config', then 'make reinstall' the PHP extensions port again with
# modified extensions
cd /usr/ports/lang/php70-extensions/

make config-recursive
make install distclean

# A good way to graphically manage Mysql is by using PHPMyAdmin
cd /usr/ports/databases/phpmyadmin/

make config-recursive install distclean

# Use a copy of the PHP development configuration as your normal configuration
cp /usr/local/etc/php.ini-development /usr/local/etc/php.ini

# Open the file /usr/local/etc/apache24/httpd.conf and look for the following line:
# DirectoryIndex index.html

# And change it so it reads as follows:
# DirectoryIndex index.html index.php

# Then append the following lines to the end of the file in order to support PHP files as well as phpMyAdmin, which normally lives outside of the Apache document root. Note: if you elected not to install phpMyAdmin, then you need only add the FilesMatch directives.

# Files match directives
<FilesMatch "\.php$">

    SetHandler application/x-httpd-php
<FilesMatch "\.phps$">
    SetHandler application/x-httpd-php-source

# PHPMyAdmin settings
Alias /phpmyadmin "/usr/local/www/phpMyAdmin"

<Directory "/usr/local/www/phpMyAdmin">
Options None
AllowOverride None
Require all granted

# Restart the Apache web server to use the new settings
service apache24 restart

# Next we will configure PHPMyAdmin
# Crerate a directory for the PHPMyAdmin configuration
mkdir /usr/local/www/phpMyAdmin/config && chmod o+w /usr/local/www/phpMyAdmin/config

# Make the config readable
chmod o+r /usr/local/www/phpMyAdmin/

# Go to http://your-hostname-or-IP-address/phpmyadmin/setup where you will see the phpMyAdmin setup Overview page.
# Select “New server” and then select the “Authentication” tab.
# Under the “Authentication type” choose “cookie” from the drop-down list and remove “root” from the “User for config auth”.

# Now select “Apply” and you will be returned you to the Overview page where you should see a new server listed.
# Select “Save” in the Overview page to save your configuration as /usr/local/www/phpMyAdmin/config/
# Now move that configuration file up one directory to /usr/local/www/phpMyAdmin where phpMyAdmin can use it.

mv /usr/local/www/phpMyAdmin/config/ /usr/local/www/phpMyAdmin

# Go to http://your-hostname-or-IP-address/phpmyadmin where you will be able to log in.
# Use “root” and the MySQL password you set up previously, then you should be directed
# to the phpMyAdmin administration page.

# We no longer need the /usr/local/www/phpMyAdmin/config directory so let’s remove it for security reasons,
# as well as the read permission we
added previously to /usr/local/www/phpMyAdmin/

rm -r /usr/local/www/phpMyAdmin/config
chmod o-r /usr/local/www/phpMyAdmin/

# Restart both Apache and Mysql just to amke sure we are using our latest config changes
service apache24 restart

service mysql-server restart

# Add a link from the base directory to web root so it's quicker to change to the web root directory
ln -s /usr/local/www/apache24/data/ /www