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



## vand777 (Mar 4, 2012)

*(1) Install nginx*

```
# cd /usr/ports/www/nginx
# make config-recursive
```

You can leave all configuration options at their default values.

```
# make install clean
```

*(2) Install perl*

```
# cd /usr/ports/lang/perl5.14
# make config-recursive
```

Select "Threads" option. Leave the rest of the configuration options at their default values.

```
# make install clean
```

*(3) Install PHP*

```
# cd /usr/ports/lang/php5
# make config-recursive
```

Select "FPM" option. Leave the rest of the configuration options at their default values.

```
# make install clean
```

*(4) Install MySQL 5.5*

```
# cd /usr/ports/databases/mysql55-server
# make config-recursive
```

You can leave all configuration options at their default values.

```
# make -D BUILD_OPTIMIZED install clean
```


----------



## vand777 (Mar 4, 2012)

*(5) Install Wordpress 3.x*

```
# cd /usr/ports/www/wordpress
# make config-recursive
```

You can leave all configuration options at their default values.

```
# 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:

```
# cp /usr/local/share/mysql/my-medium.cnf /var/db/mysql/my.cnf
```

Enable MySQL server at system startup:

```
# echo 'mysql_enable="YES"' >> /etc/rc.conf
```

Start MySQL server:

```
# /usr/local/etc/rc.d/mysql-server start
```

Change root's password, remove anonymous accounts and create a new database/user for wordpress:

```
# 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;
```


----------



## vand777 (Mar 4, 2012)

*(7) Configure PHP-FPM*

Edit /usr/local/etc/php-fpm.conf:

```
# ee /usr/local/etc/php-fpm.conf
```

Make the following changes:

```
[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:

```
# echo 'php_fpm_enable="YES"' >> /etc/rc.conf
```

Start PHP-FPM:

```
# /usr/local/etc/rc.d/php-fpm start
```


----------



## vand777 (Mar 4, 2012)

*(8) Configure Wordpress*

Edit configuration file:

```
# 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:

```
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:

```
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.


----------



## vand777 (Mar 4, 2012)

*(9) Configure nginx*

Open and edit configuration file:

```
# ee /usr/local/etc/nginx/nginx.conf
```

It should be as below:

```
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.


----------



## vand777 (Mar 4, 2012)

Start nginx:

```
# echo 'nginx_enable="YES"' >> /etc/rc.conf
# /usr/local/etc/rc.d/nginx start
```

*(10) Complete installation*

Open http://your.hostname/wp-admin/install.php and follow the instruction to complete installation.


----------



## usling (Aug 19, 2012)

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.


----------



## epicoxymoron (Sep 26, 2012)

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.


----------



## ChaseNet (Dec 2, 2012)

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?


----------



## vand777 (Dec 3, 2012)

Unfortunately, I do not know the answer to your question. I decided not to use Wordpress as I'm not a big fan of PHP. I moved to Orchard CMS. Planning to launch www.freebsdsecrets.com on this engine soon.


----------



## ChaseNet (Dec 3, 2012)

Thanks anyways.


----------



## KdeBruin (Dec 6, 2012)

Add the following to your wp-config.php:


```
define('FS_METHOD', 'direct');
```

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


----------



## ChaseNet (Dec 7, 2012)

KdeBruin said:
			
		

> Add the following to your wp-config.php:
> 
> 
> ```
> ...



Is it secure? Like, I mean, adding that line of code won't cause any security issues?


----------



## KdeBruin (Dec 10, 2012)

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.


----------



## Dare (Feb 22, 2013)

You will probably want have permalinks working so simply add

```
try_files $uri $uri/ /index.php?$args;
```

to the virtual host location directive.


----------



## fred974 (Mar 14, 2013)

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


----------



## Dare (Mar 15, 2013)

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


----------



## vand777 (Mar 15, 2013)

fred974 said:
			
		

> 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



Yes, you need root privileges.


----------



## fred974 (Mar 19, 2013)

Thank you guys


----------



## fred974 (Apr 11, 2013)

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


----------



## DutchDaemon (Apr 12, 2013)

Looks like you only ran [cmd=]make[/cmd] in the port directory, not [cmd=]make install clean[/cmd].


----------



## fred974 (Apr 12, 2013)

I did a copy and past into PuTTY, so it is as instructed above.


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

I'm not sure how it happened.


----------



## fred974 (Apr 17, 2013)

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.


----------



## fred974 (Apr 25, 2013)

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:

```
DSC_8454.jpg exceeds the maximum upload size for this site.
```
event after adding the following in my nginx.conf file.

```
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?


----------



## KdeBruin (May 1, 2013)

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.


----------



## fred974 (May 2, 2013)

Thank you @KdeBruin,

I added the php.ini file and my problem*s* were gone


----------



## olo (Oct 26, 2013)

Hi,

Great tutorial, but wouldn't it be better and more secure to bind MySQL only to 127.0.0.1 and allow the Wordpress db database user and root to log in only via localhost and 127.0.0.1? The web server in this tutorial is the same server as the MySQL one. Even if it is we should use SSH tunnels instead of a public IP. Am I right?


----------



## nesstyy (Jan 19, 2014)

Ness Mosu sends thanks for this tutorial.
Hi. | have a small problem and | ask for a little help.
| edited this msg becouse | dont want to spam here.
| install *nginx*, *mysql*, *php-fpm* and *wordpress*. everything is fine. | made may little blog and is good. | am beginner on *freebsd* and *wordpress*.
Now the real problem .
Local on my network | have access on my blog to see the page and to made change on him, but on extern  the blog is broken.
php-fpm works and php ,nginx is good .| dont know the issue.  
help this old man pls ?
PS. Admin.sorry for last 2 post.

Solved. thanks.


----------



## rname (Nov 16, 2015)

Hi all. 
tried to install mysql56-server, but

```
===>  mysql56-server-5.6.26 has known vulnerabilities:
mysql56-server-5.6.26 is vulnerable:
MySQL - Multiple vulnerabilities
CVE: CVE-2015-4792
CVE: CVE-2015-4913
CVE: CVE-2015-4870
CVE: CVE-2015-4861
CVE: CVE-2015-4858
CVE: CVE-2015-4836
CVE: CVE-2015-4830
CVE: CVE-2015-4826
CVE: CVE-2015-4815
CVE: CVE-2015-4807
CVE: CVE-2015-4802
WWW: https://vuxml.FreeBSD.org/freebsd/851a0eea-88aa-11e5-90e7-b499baebfeaf.html

1 problem(s) in the installed packages found.
=> Please update your ports tree and try again.
=> Note: Vulnerable ports are marked as such even if there is no update available.
=> If you wish to ignore this vulnerability rebuild with 'make DISABLE_VULNERABILITIES=yes'
*** Error code 1

Stop.
make: stopped in /usr/ports/databases/mysql56-server
```

then try to install mysql55-server, but the same errors

```
===>  mysql55-server-5.5.44 has known vulnerabilities:
mysql55-server-5.5.44 is vulnerable:
MySQL - Multiple vulnerabilities
CVE: CVE-2015-4792
CVE: CVE-2015-4913
CVE: CVE-2015-4870
CVE: CVE-2015-4861
CVE: CVE-2015-4858
CVE: CVE-2015-4836
CVE: CVE-2015-4830
CVE: CVE-2015-4826
CVE: CVE-2015-4815
CVE: CVE-2015-4807
CVE: CVE-2015-4802
WWW: https://vuxml.FreeBSD.org/freebsd/851a0eea-88aa-11e5-90e7-b499baebfeaf.html

1 problem(s) in the installed packages found.
=> Please update your ports tree and try again.
=> Note: Vulnerable ports are marked as such even if there is no update available.
=> If you wish to ignore this vulnerability rebuild with 'make DISABLE_VULNERABILITIES=yes'
*** Error code 1

Stop.
make[1]: stopped in /usr/ports/databases/mysql55-server
*** Error code 1
```
is it normal? my ports is up to date

```
root@freebsd:/usr/ports # portsnap update
Ports tree is already up to date
```


----------



## SirDice (Nov 16, 2015)

I'm afraid the port hasn't been updated yet. 

PR 204569


----------



## rname (Nov 16, 2015)

SirDice said:


> I'm afraid the port hasn't been updated yet.
> 
> PR 204569



Thanks for the reply!
How can I know when these ports will be updated?
I'm a FreeBSD newbie, which approach could I use in this case?


----------



## SirDice (Nov 16, 2015)

Several ways to do it. You could subscribe to the bug report and you'll be notified if it's updated. You could try updating your ports tree everyday and just look if the version is updated. Or you could visit www.freshports.org regularly and keep an eye on the ports there.


----------



## free-and-bsd (Sep 7, 2017)

I've also noticed there is mysql80-server  there. Are there any objections to using that one along with nginx and php etc., instead of mysql56-server?


----------

