Basic WordPress setup on FreeBSD 9.1
WordPress needs no introduction.
It's simply the most popular blogging software at the moment.
Here's how I got it installed on FreeBSD 9.1
Requirements:
- FreeBSD ports
- Some understanding of MySQL (create a database and a user, although it's also outlined here)
Brief outline of the procedure: 1. Install packages including MySQL 5.5
-
Install Apache from Ports
-
Install PHP and PHP extensions from ports
-
Install WordPress from Ports
-
Setup Apache
-
Setup MySQL
-
Setup VirtualHost for WordPress
-
Setup WordPress
1. Install Packages including MySQL 5.5
Go ahead and install those packages - if you don't they'll have to be installed from ports which takes way too long.
pkg_add -r libXpm png jpeg t1lib expat help2man gmake libXaw bigreqsproto automake automake-wrapper xcmiscproto xtrans inputproto xf86bigfontproto libXau libSM libIce libXp xorg-macros libXmu xf86bigfontproto libtool libltdl libxml2 mysql55-server curl
2. Install Apache from Ports
cd /usr/ports/www/apache24/
make config-recursive
make fetch-recursive
time make install clean
The above takes about 7 minutes
3. Install PHP and PHP extensions from ports
cd /usr/ports/lang/php5
make config-recursive
IMPORTANT: Add "APACHE" to build the apache module
time make install clean
The above took about 6 minutes
Now install the extensions:
cd /usr/ports/lang/php5-extensions
make config-recursive
ADD: GD, MBSTRING, MYSQL, PDO_MYSQL REMOVE: PDO_SQLITE, SQLITE3
time make install clean
^ took about 12 minutes
4. Install WordPress from Ports
cd /usr/ports/www/wordpress && make install clean
time make fetch recursive
^ took less than 30 secs - the above installs wordpress under: /usr/local/www/wordpress/
5. Setup Apache
Make Apache start on FreeBSD boot:
echo "apache24_enable="YES"" >> /etc/rc.conf
echo "apache24_http_accept_enable="YES"" >> /etc/rc.conf
Note: All configs go under: /usr/local/etc/apache24/
Edit /usr/local/etc/apache24/httpd.conf
Change:
#ServerName www.example.com:80
to:
ServerName localhost:80
And at the end of the file add:
<IfModule mod_php5.c>
DirectoryIndex index.php index.html
</IfModule>
<IfModule mod_php5.c>
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
</IfModule>
6. Setup MySQL
Make MySQL start on boot:
echo "mysql_enable="YES"" >> /etc/rc.conf
Copy a template config:
cp /usr/local/share/mysql/my-small.cnf /usr/local/etc/my.cnf
Edit it:
ee /usr/local/etc/my.cnf
Scroll down to line 47 and add the following:
bind-address = 127.0.0.1
Now Start MySQL:
/usr/local/etc/rc.d/mysql-server start
Make sure that MySQL is listening on localhost (127.0.0.1)
sockstat -4 | grep mysql
You should get output like this:
mysql mysqld 943 10 tcp4 127.0.0.1:3306 *:*
Now let's connect to the MySQL server:
mysql
Create a database for wordpress:
create database wordpress_site1;
Grant permissions (add a user) :
GRANT ALL ON wordpress_site1.* TO root@'localhost' IDENTIFIED BY 'superdifficultpassword';
Explanation of the above:
The above command will grant all privileges to the MySQL root
user accessing this server from localhost
only and uses the password 'superdifficultpassword'
Don't forget to do a flush privileges;
to apply the above settings:
flush privileges;
Now exit MySQL and test your settings to preserve your sanity before we test them with wordpress:
mysql -D wordpress_site1 -u root -h localhost -p
Explanation of the above:
-D specifies database
-u specifies the user
-h specifies the host
-p asks for a password prompt
We're done with MySQL, now let's work on the Apache VirtualHost
7. Setup VirtualHost for WordPress
Restart Apache to make sure that the PHP 5 module is loaded:
/usr/local/etc/rc.d/apache24 restart
Test if the PHP 5 module is loaded:
apachectl -M | grep php
You should see something like this:
php5_module (shared)
Now let's add a VirtualHost:
With the editor of your preference create the file: /usr/local/etc/apache24/Includes/wordpress.conf
And add the following lines:
<VirtualHost *:80>
DocumentRoot "/usr/local/www/wordpress/"
ServerName localhost
ServerAlias www.dummy-host.example.com
ErrorLog "/var/log/wordpress-error_log"
CustomLog "/var/log/wordpress-access_log" common
</VirtualHost>
Explanation of the above:
DocumentRoot = The location of your PHP/HTML files
ServerName = the FQDN where you want this VirtualHost to respond to (i.e. www.example.com) - in this case we're just setting it to localhost
ServerAlias = optional - use only if you want this VirtualHost to respond to more than one FQDN
ErrorLog and CustomLog = very important! if you don't set those you won't get logs running and you won't be able to troubleshoot apache - never skip your logs!
Then edit /usr/local/etc/apache24/httpd.conf
- find these lines:
<Directory />
AllowOverride none
Require all denied
</Directory>
comment them out - they should look like this:
#<Directory />
# AllowOverride none
# Require all denied
#</Directory>
Restart Apache again:
/usr/local/etc/rc.d/apache24 restart
8. Setup WordPress
Now let's configure WordPress:
cd /usr/local/www/wordpress/
cp wp-config-sample.php wp-config.php
Replace the line:
define('DB_NAME', 'database_name_here');
with:
define('DB_NAME', 'wordpress_site1');
Replace the line:
define('DB_USER', 'username_here');
with:
define('DB_USER', 'root');
Replace the line:
define('DB_PASSWORD', 'password_here');
with:
define('DB_PASSWORD', 'superdifficultpassword');
Replace the lines:
define('AUTH_KEY', 'put your unique phrase here');
define('SECURE_AUTH_KEY', 'put your unique phrase here');
define('LOGGED_IN_KEY', 'put your unique phrase here');
define('NONCE_KEY', 'put your unique phrase here');
define('AUTH_SALT', 'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT', 'put your unique phrase here');
define('NONCE_SALT', 'put your unique phrase here');
by going to https://api.wordpress.org/secret-key/1.1/salt/
and copy paste the output into your file, overwriting the lines it will look something like this:
define('AUTH_KEY', '}`1k+;p1+_owC|G2]w0JJ7tr]z)!bSPd|,X vWif5C~4`s96*B8q:?q^{YNOG~EM');
define('SECURE_AUTH_KEY', 'L+YQf|[VXxaRyobo;M-[;5mbf,py%zk?+1bf9-:(PYeB]uf9#G*rSM+|TBAYnyh3');
define('LOGGED_IN_KEY', ':-8=- I%7k+6r<@X[ObfiM%CH7|qhAeX2nGzspb|D:p%K+@^8-ht*+?-{/.03D:&');
define('NONCE_KEY', 'pRAQWp.Wx@b}>zoK;{9HS`Q-Kb2X.]uEHbA|Y!-g1HMmpmom*-NdXtW:h2B|0u,_');
define('AUTH_SALT', 'S`b[H52jfU|~fS3My?x3*+;nDv/-1x?tE7d_O_JhJ<(q}1C+d^(2_/B:bMwN9T>U');
define('SECURE_AUTH_SALT', '%!()/sVRo^4G|FPg;<&b31!~(%DI.mr*6Gx_hbb~9ZL#^]rAfZ,sq7?N&piXph%l');
define('LOGGED_IN_SALT', '$VnYXo+8$)we.=v3PYO[ [$TP>pk7z(fL)trW]Gjb|5ZnGHRe`{WE1m!2Pzj:5eH');
define('NONCE_SALT', '47+&{]~$nr+L)f|DPF.Ccg.UW-rFxA{fg1f!w0y_+EM$/5~.%-V1U*+H<uNKoO88');
Now point your browser to the IP address of your server, in my case: http://192.168.2.6/wp-admin/install.php
You should see the WordPress Installation page
In my example I used: Site Title: 'WeirdBricks example' Username: 'weirdbricks_admin' Password, make sure you enter the same password twice
Note: If you need a good random password generator go here: http://www.random.org/passwords/
Untick 'Allow search engines to index this site'
aaand you should be good to go!