HOWTO: Install Wordpress 3.x + Nginx + MySQL 5.5

(1) Install nginx
Code:
# cd /usr/ports/www/nginx
# make config-recursive

You can leave all configuration options at their default values.
Code:
# make install clean

(2) Install perl
Code:
# cd /usr/ports/lang/perl5.14
# make config-recursive

Select "Threads" option. Leave the rest of the configuration options at their default values.
Code:
# make install clean

(3) Install PHP
Code:
# cd /usr/ports/lang/php5
# make config-recursive

Select "FPM" option. Leave the rest of the configuration options at their default values.
Code:
# make install clean

(4) Install MySQL 5.5
Code:
# cd /usr/ports/databases/mysql55-server
# make config-recursive

You can leave all configuration options at their default values.
Code:
# make -D BUILD_OPTIMIZED install clean
 
(5) Install Wordpress 3.x
Code:
# cd /usr/ports/www/wordpress
# make config-recursive

You can leave all configuration options at their default values.
Code:
# make install clean
# rehash

(6) Configure MySQL

MySQL includes 4 sample configuration files located in the /usr/local/share/mysql/ directory:

  • my-small.cnf - for systems with up to 64 Mb of RAM.
  • my-medium.cnf - for systems with up to 128 Mb of RAM (ideal for web servers).
  • my-large.cnf - for systems with 512 Mb of RAM (dedicated MySQL servers).
  • my-huge.cnf - for systems with 1-2 Gb of RAM (datacentres etc.).

Copy configuration which suits your system configuration. For example:
Code:
# cp /usr/local/share/mysql/my-medium.cnf /var/db/mysql/my.cnf

Enable MySQL server at system startup:
Code:
# echo 'mysql_enable="YES"' >> /etc/rc.conf

Start MySQL server:
Code:
# /usr/local/etc/rc.d/mysql-server start

Change root's password, remove anonymous accounts and create a new database/user for wordpress:
Code:
# mysql -u root
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'::1' IDENTIFIED BY '[color="Red"]root_password[/color]' WITH GRANT OPTION;
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY '[color="Red"]root_password[/color]' WITH GRANT OPTION;
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'[color="Red"]your_hostname[/color]' IDENTIFIED BY '[color="Red"]root_password[/color]' WITH GRANT OPTION;
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1' IDENTIFIED BY '[color="Red"]root_password[/color]' WITH GRANT OPTION;
mysql> DROP USER ''@'localhost';
mysql> DROP USER ''@'[color="Red"]your_hostname[/color]';
mysql> CREATE DATABASE wordpress;
mysql> GRANT ALL ON wordpress.* to 'wordpress'@'localhost' IDENTIFIED BY '[color="Red"]wordpress_password[/color]';
mysql> GRANT ALL ON wordpress.* to 'wordpress'@'[color="Red"]your_hostname[/color]' IDENTIFIED BY '[color="Red"]wordpress_password[/color]';
mysql> GRANT ALL ON wordpress.* to 'wordpress'@'[color="Red"]IP_address_of_wordpress_installation[/color]' IDENTIFIED BY '[color="Red"]wordpress_password[/color]';
mysql> FLUSH PRIVILEGES;
mysql> QUIT;
 
(7) Configure PHP-FPM

Edit /usr/local/etc/php-fpm.conf:
Code:
# ee /usr/local/etc/php-fpm.conf

Make the following changes:
Code:
[color="Red"]-; events.mechanism = epoll[/color]
[color="Green"]+events.mechanism = kqueue[/color]

...

[color="Red"]-listen = 127.0.0.1:9000[/color]
[color="Green"]+listen = /var/run/php-fpm.sock[/color]

...

[color="Red"]-;listen.owner = www
-;listen.group = www
-;listen.mode = 0666[/color]
[color="Green"]+listen.owner = www
+listen.group = www
+listen.mode = 0666[/color]

Enable PHP-FPM in /etc/rc.conf:
Code:
# echo 'php_fpm_enable="YES"' >> /etc/rc.conf

Start PHP-FPM:
Code:
# /usr/local/etc/rc.d/php-fpm start
 
(8) Configure Wordpress

Edit configuration file:
Code:
# cd /usr/local/www/wordpress/
# cp wp-config-sample.php wp-config.php
# chmod 640 wp-config.php
# ee wp-config.php

Modify DB_NAME, DB_USER, DB_PASSWORD and DB_HOST to match your MySQL setup:
Code:
define('DB_NAME', 'wordpress');
define('DB_USER', 'wordpress');
define('DB_PASSWORD', '[color="Red"]wordpress_password[/color]');
define('DB_HOST', '[color="Red"]192.168.199.201[/color]');

Change 192.168.199.201 to the IP address on your network interface on which MySQL server is listening.

Put different unique phrases in the below lines:
Code:
define('AUTH_KEY',         '[color="Red"]put your unique phrase here[/color]');
define('SECURE_AUTH_KEY',  '[color="Red"]put your unique phrase here[/color]');
define('LOGGED_IN_KEY',    '[color="Red"]put your unique phrase here[/color]');
define('NONCE_KEY',        '[color="Red"]put your unique phrase here[/color]');
define('AUTH_SALT',        '[color="Red"]put your unique phrase here[/color]');
define('SECURE_AUTH_SALT', '[color="Red"]put your unique phrase here[/color]');
define('LOGGED_IN_SALT',   '[color="Red"]put your unique phrase here[/color]');
define('NONCE_SALT',       '[color="Red"]put your unique phrase here[/color]');

Save and exit.
 
(9) Configure nginx

Open and edit configuration file:
Code:
# ee /usr/local/etc/nginx/nginx.conf

It should be as below:
Code:
user  www www;
[color="Red"]worker_processes  4;[/color]

pid /var/run/nginx.pid;

error_log  /var/log/nginx.error_log  info;

events {
    worker_connections  1024;
    use kqueue;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    gzip  on;

    server {
        listen 80;
        server_name [color="Red"]your_hostname[/color];

        root /usr/local/www/wordpress;
        index index.php;

        #charset koi8-r;

        location / {
           # If requested URI does not match any existing file, directory or symbolic link, rewrite the URL to index.php
           if (!-e $request_filename) {
               rewrite ^ /index.php last;
           }
        }

        # For all PHP requests, pass them on to PHP-FPM via FastCGI
        location ~ \.php$ {
           fastcgi_pass unix:/var/run/php-fpm.sock;
           fastcgi_param SCRIPT_FILENAME /usr/local/www/wordpress$fastcgi_script_name;
           fastcgi_param PATH_INFO $fastcgi_script_name;
           include fastcgi_params; # include extra FCGI params
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/local/www/nginx-dist;
        }
    }
}

Change worker_processes to the number of cores.
 
Thank you for this! I'm a total newbie so guides like this are extremely helpful.

It worked flawlessly except for one thing. Nginx wouldn't start because a dependency had been updated to a newer version. Likely because i already had nginx installed. I solved it by recompiling it.

I use FreeBSD 8.2.
 
So, here I was looking for a lazy way to get WP running on nginx, and voila! I followed the instructions, and it Just Worked. Thanks, vand777, for putting this succinct guide together. I registered on the forums just to give you this positive feedback.

And, on top of that, I learned about make-recursive, which I hadn't encountered before. I wish I'd known that when I started building this system!

I'll also mention that Wordpress provides a pagewhere they generate random keys/salts for you. It's noted in the config page, but just in case somebody's going solely off the forums.
 
Vand,

Thanks for the information, I just used this and worked amazingly well and easy. But I have a question I am hoping you can answer as well, as I'm having a tough time finding my answer with Google.

Once this is all done, I went into mydomain.com/wp-admin and I can't add/delete plugins or themes without giving wordpress some FTP credentials, every single time. Now, I know with apache, the easy resolution is suphp, but my whole decision to go nginx was based on speed, less, stress and resources, etc and fast php for Total Cache.

So, with that being said, how can I resolve the FTP Credential issue on nginx?
 
KdeBruin said:
Add the following to your wp-config.php:

Code:
define('FS_METHOD', 'direct');

This will allow for direct retrieval of code without entering FTP credentials.

Is it secure? Like, I mean, adding that line of code won't cause any security issues?
 
It will use the internal FTP functions of PHP to retrieve data directly into your Wordpress tree. You could also include settings with your FTP credentials but as far as I could determine the result is the same as the direct FTP method.
 
You will probably want have permalinks working so simply add
Code:
try_files $uri $uri/ /index.php?$args;

to the virtual host location directive.
 
Hi,

Thank you for this great how to. Do all of the steps above need to be done as root? Or will any user do?

Fred
 
You basically need root privileges to install binaries, edit configs, create databases... so I could do this as a sudoer.
 
Hi,

In my installation, I do not have a WordPress directory in /usr/local/www/wordpress/. My wp-config-sample.php file is located at /usr/ports/www/wordpress/work/wordpress/wp-config-sample.php.

Should I move the Wordpress directory from /usr/ports/www/wordpress/work/wordpress to /usr/local/www/wordpress/?

Thank you in advance for your reply:)

Fred
 
Looks like you only ran [cmd=]make[/cmd] in the port directory, not [cmd=]make install clean[/cmd].
 
I did a copy and past into PuTTY, so it is as instructed above.

Code:
# cd /usr/ports/www/wordpress
# make config-recursive
# make install clean
# rehash

I'm not sure how it happened.
 
Resolved.

My wordpress installation failed because my php5 and php5-extensions ports were out of sync.

Solved this issue and reinstalled wordpress with no problem.
 
Hello everyone!

I have created my site contents without too much problem, but when trying to install a plugin I have the following error message:
Code:
DSC_8454.jpg exceeds the maximum upload size for this site.
event after adding the following in my nginx.conf file.
Code:
server {
        [B][color="Red"]client_max_body_size 4M;[/color][/B]

        listen       80;
        server_name  localhost;
	
	root /usr/local/www/wordpress;
	index index.php;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
           # If requested URI does not match any existing file, directory or symbolic link, rewrite the URL to index.php
           if (!-e $request_filename) {
               rewrite ^ /index.php last;
           }
        }

Google is telling that the problem is with the php.ini file, but this tutorial do not use it. Does anybody have any idea on how to solve the issue?
 
Check the file /usr/local/etc/php.ini. And PHP is a requirement of Wordpress and it is installed in step 3 of the installation process.
 
Back
Top