Wordpress FAMP - Wordpress application on FAMP (FreeBSD, Apache, MySQL & PHP) stack
This assumes a FAMP stack has already been installed/configured ready for Wordpress installation and configuration.
Wordpress requires the PHP modules php56-xml
, php56-hash
, php56-gd
, php56-curl
, php56-tokenizer
, php56-zlib
and php56-zip
to be installed. It also requires the php56-mysql
port, however this port should of been installed as part of the FAMP stack. To installed the required ports (tip: use whereis
to find the location of a port i.e. whereis php56-xml
will return php56-xml: /usr/ports/textproc/php56-xml
):
cd /usr/ports/textproc/php56-xml && sudo make config-recursive install distclean
cd /usr/ports/security/php56-hash && sudo make config-recursive install distclean
cd /usr/ports/graphics/php56-gd && sudo make config-recursive install distclean
cd /usr/ports/ftp/php56-curl && sudo make config-recursive install distclean
cd /usr/ports/devel/php56-tokenizer && sudo make config-recursive install distclean
cd /usr/ports/archivers/php56-zlib && sudo make config-recursive install distclean
cd /usr/ports/archivers/php56-zip && sudo make config-recursive install distclean
If mpm_event_module
is being used for Apache, OpenSSL also needs a seperate install on PHP:
cd /usr/ports/security/php56-openssl && sudo make config-recursive install distclean
OR
Use FreeBSD's PHP extensions ports to select and install all the common PHP modules (using the mouseclick to choose what gets installed) with:
cd /usr/ports/lang/php56-extensions && sudo make config-recursive install distclean
Note: To remove the installation of ports for the php extensions port, use the command cd /usr/ports/lang/php56-extensions && sudo make deinstall distclean && sudo make rmconfig-recursive
and then follow the previous command to reconfigure/install once again.
Restart Apache after installation of PHP extensions:
sudo apachectl graceful
Enter the MySQL CLI replacing [username]
with the MySQL username previously setup (default is root
) and enter password when prompted:
mysql -u [username] -p
Create a database for the application, replacing [application]
for the application's database name:
CREATE DATABASE [application];
Create a MySQL user for the application, replacing [application_user]
with the username and [application_user_password]
with the password:
CREATE USER [application_user]@localhost IDENTIFIED BY '[application_user_password]';
Grant access for the new user to the new database (replacing [application]
for the application's database name and [application_user]
with the username used previously):
GRANT ALL PRIVILEGES ON [application].* TO [application_user]@localhost;
Flush all priveledges for this to take effect:
FLUSH PRIVILEGES;
Exit MySQL CLI:
exit
Open up the Apache config file:
sudo ee /usr/local/etc/apache24/httpd.conf
Uncomment rewrite_module
module by removing the #
so it looks like this:
LoadModule rewrite_module libexec/apache24/mod_rewrite.so
Corrent file routing for Wordpress can be setup in two ways, using htaccess files or
This allows htaccess files to be put in web directories and perform directory specific overrides, however it does slow down Apache as Apache needs to look for where these htaccess files are. Currently PHP-FPM does not support this method.
Find the <Directory "/usr/local/www/apache24/data">
section, then find AllowOverride None
and change None
to All
, like so:
AllowOverride All
OR
This means htaccess files will not be read in web directories, this is a slightly less in-flexible method but is faster for Apache as it does not need to look for .htaccess files. Currently PHP-FPM can only support this method.
Find the <Directory "/usr/local/www/apache24/data">
section, then find AllowOverride None
and enter the following below it to route Wordpress URIs correctly (note: any data normally put inside a htaccess file for Wordpress will be put in the http.d
file instead):
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Save, exit and then restart Apache with:
sudo service apache24 restart
If an SFTP client is going to be used to interactive with files, having a user with root
priveledges via the wheel
user group can cause issues with the default folder permissions 755
because these do not run sudo
commands. Changing the permission to grant rwx access to everyone who is in the folder's group (wheel
) will prevent permissions issues from these programs:
sudo chmod -R 775 /usr/local/www/apache24/data
Wordpress's /uploads
folder needs to be writable by the server (Apache) to allow Wordpress to write to that folder. Apache uses the user account www
on FreeBSD, thus adding this folder to the www
group, keeping ownership to the root admin (or what it currently is) and changing permissions to both group and owner allows both the users to operate on the directory:
sudo chown -R <root_or_current_owner_user>:www path/to/wordpress/project/uploads && chmod -R 775 path/to/wordpress/project/uploads
Some plug-ins or frameworks require additional PHP extensions and/or Apache modules to be installed to operate. Here is a list of some Wordpress additional softwares and the required additional dependencies.
Requires c-type PHP extension:
cd /usr/ports/textproc/php55-ctype && sudo make config-recursive install distclean
Requires filter and JSON PHP extensions:
cd /usr/ports/security/php56-filter && sudo make config-recursive install distclean
cd /usr/ports/devel/php56-json && sudo make config-recursive install distclean
Create Wordfence logs file and set permissions to Apache:
sudo mkdir /usr/local/www/apache24/data/web/app/wflogs && sudo chown www:www /usr/local/www/apache24/data/web/app/wflogs
Requires filter PHP extension:
cd /usr/ports/security/php56-filter && sudo make config-recursive install distclean
Requires additional PHP extensions and Apache modules.
Install the following PHP extensions:
cd /usr/ports/databases/pecl-memcache && sudo make config-recursive install distclean
cd /usr/ports/www/php5-tidy && sudo make config-recursive install distclean
cd /usr/ports/www/php56-opcache && sudo make config-recursive install distclean
Ensure PHP extensions are added to the extensions.ini
(although these might be automatically added) (???):
/usr/local/etc/php/extensions.ini
Open up php.ini
:
sudo ee /usr/local/etc/php.ini
Add the following to the php.ini
(if not already present) to enable opcache
, save and exit (Note W3 Total Cache doesn't seem to recognise this?):
opcache.enable=1
opcache.enable_cli=1
Next to configure Apache so all of the required modules are active, open the httpd.conf
:
sudo ee /usr/local/etc/apache24/httpd.conf
Ensure mod_deflate
and mod_expires
are uncommented by removing #
at the start of their corresponding lines (if present) so they look like the following:
LoadModule deflate_module libexec/apache24/mod_deflate.so
...
LoadModule expires_module libexec/apache24/mod_expires.so
Restart Apache after installation of PHP extensions and/or Apache modules with:
sudo apachectl graceful
If using PHP-FPM, restart PHP-FPM after installation of PHP extensions with:
sudo service php-fpm restart