Project

General

Profile

Support #964

Updated by Daniel Curtis over 3 years ago

{{>toc}} 

 This is a guide on setting up WordPress with Nginx on FreeBSD 12. 

 h1. Prepare the Environment 

 * Before installation of the components, make sure everything is up to date using the following command: 
 <pre> 
 pkg update -f && pkg upgrade 
 </pre> 

 * Create the wordpress user: 
 <pre> 
 pw user add -n wordpress -s /sbin/nologin -c "WordPress" 
 </pre> 

 --- 

 h1. Install Nginx 

 * Install Nginx 
 <pre> 
 pkg install nginx 
 </pre> 

 * Create a configuration directory to make managing individual server blocks easier 
 <pre> 
 mkdir /usr/local/etc/nginx/conf.d 
 </pre> 

 * Edit the main nginx config file: 
 <pre> 
 vi /usr/local/etc/nginx/nginx.conf 
 </pre> 
 #* And strip down the config file and add the include statement at the end to make it easier to handle various server blocks: 
 <pre> 
 worker_processes    1; 
 error_log    /var/log/nginx-error.log; 

 events { 
     worker_connections    1024; 
 } 

 http { 
     include         mime.types; 
     default_type    application/octet-stream; 
     sendfile          on; 
     keepalive_timeout    65; 

     # Load config files from the /etc/nginx/conf.d directory 
     include /usr/local/etc/nginx/conf.d/*.conf; 
 } 
 </pre> 

 --- 

 h1. Install MySQL Server 

 * Start by installing the mariadb100-server and mariadb100-client packages: 
 <pre> 
 pkg install mariadb105-{server,client} 
 </pre> 

 * Enable and start mysql at boot: 
 <pre> 
 sysrc mysql_enable=YES 
 service mysql-server start 
 </pre> 

 * Prepare the database for use by running the secure installation: 
 <pre> 
 mysql_secure_installation 
 </pre> 
 #* *NOTE*: +Choose a strong root password+ and answer +yes+ to all questions. 

 h2. Create Databases and Users 

 * Login to MySQL and create appropriate databases and users. 
 <pre> 
 mysql -u root -p 
 </pre> 
 #* and run the following SQL queries to create the *wordpressdb* database and *wordpressuser* user: 
 <pre> 
 CREATE DATABASE wordpressdb CHARACTER SET utf8; 

 CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'SuperSecretPassword'; 

 GRANT ALL PRIVILEGES ON wordpressdb.* TO 'wordpressuser'@'localhost'; 

 FLUSH PRIVILEGES; 

 quit 
 </pre> 

 --- 

 h1. Install WordPress 

 * Install wordpress: 
 <pre> 
 pkg install wordpress 
 </pre> 

 Create the wordpress php-fpm pool config file: 
 <pre> 
 vi /usr/local/etc/php-fpm.d/wordpress.example.com.conf 
 </pre> 
 *# And add the following: 
 <pre> 
 [wordpress.example.com] 
 user = wordpress 
 group = www 
 listen = /var/run/wordpress.sock 
 listen.owner = wordpress 
 listen.group = www 
 pm = dynamic 
 pm.max_children = 5 
 pm.start_servers = 2 
 pm.min_spare_servers = 1 
 pm.max_spare_servers = 3 
 php_admin_value[post_max_size] = 12M 
 php_admin_value[upload_max_filesize] = 10M 
 </pre> 

 * Create an *wordpress.example.com server block* config file: 
 <pre> 
 vi /usr/local/etc/nginx/conf.d/wordpress.example.com.conf 
 </pre> 
 #* Add the following: 
 <pre> 
 server { 
     listen         80; 
     server_name    wordpress.example.com; 
     root /usr/local/www/wordpress; 
     index index.php index.html index.htm; 
     client_max_body_size 12m; 

     location / { 
         try_files $uri $uri/ /index.php?q=$uri&$args; 
     } 

     error_page        500 502 503 504    /50x.html; 
     location = /50x.html { 
         root /usr/local/www/nginx-dist; 
     } 

     location ~ \.php$ { 
         try_files $uri =404; 
         fastcgi_split_path_info ^(.+\.php)(/.+)$; 
         fastcgi_pass unix:/var/run/wordpress.sock; 
         fastcgi_index index.php; 
         fastcgi_param SCRIPT_FILENAME $request_filename; 
         include fastcgi_params; 
     } 
 } 
 </pre> 

 * Change the ownership of the wordpress directory: 
 <pre> 
 chown -R wordpress:www /usr/local/www/wordpress 
 </pre> 

 * Restart nginx and start php-fpm: 
 <pre> 
 sysrc nginx_enable=YES 
 service nginx restart 
 sysrc php_fpm_enable=YES 
 service php-fpm start 
 </pre> 

 * Now open up a web browser and go to http://wordpress.example.com to finish the setup process. 

 h2. Resources 

 * https://techviewleo.com/install-wordpress-with-nginx-php-fpm-on-freebsd/

Back