这篇文章将介绍博主在 Debian Jessie 上搭建 WordPress 博客的过程。
安装 HTTP 服务器
我使用的是 nginx 作为本站点的 HTTP 服务器
# aptitude install nginx
安装 PHP
# aptitude install php5 php5-fpm php5-mysql php5-cgi
安装数据库
数据库使用 mariadb
# aptitude install mariadb-server mariadb-client
创建数据库
# mysql -u root -p
mysql > CREATE DATABASE wordpress; mysql > GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost IDENTIFIED BY 'password'; mysql > FLUSH PRIVILEGES; mysql > exit
下载并解压 WordPress 安装包
# wget https://wordpress.org/latest.tar.gz # tar -xf latest.tar.gz /var/www/wordpress
配置 HTTP 服务器
站点配置文件
/etc/nginx/sites-available/zhrichard.me
server { server_name zhrichard.me; root /var/www/zhrichard.me; index index.php; include global/restrictions.conf; # Additional rules go here. # Only include one of the files below. include global/wordpress.conf; # include global/wordpress-ms-subdir.conf; # include global/wordpress-ms-subdomain.conf; }
全局限制
/etc/nginx/global/restrictions.conf
# Global restrictions configuration file. # Designed to be included in any server {} block. location = /favicon.ico { log_not_found off; access_log off; } location = /robots.txt { allow all; log_not_found off; access_log off; } # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac). # Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban) location ~ /\. { deny all; } # Deny access to any files with a .php extension in the uploads directory # Works in sub-directory installs and also in multisite network # Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban) location ~* /(?:uploads|files)/.*\.php$ { deny all; }
WordPress 规则
/etc/nginx/global/wordpress.conf
# WordPress single site rules. # Designed to be included in any server {} block. # This order might seem weird - this is attempted to match last if rules below fail. # http://wiki.nginx.org/HttpCoreModule location / { try_files $uri $uri/ /index.php?$args; } # Add trailing slash to */wp-admin requests. rewrite /wp-admin$ $scheme://$host$uri/ permanent; # Directives to send expires headers and turn off 404 error logging. location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ { access_log off; log_not_found off; expires max; } # Uncomment one of the lines below for the appropriate caching plugin (if used). #include global/wordpress-wp-super-cache.conf; #include global/wordpress-w3-total-cache.conf; # Pass all .php files onto a php-fpm/php-fcgi server. location ~ [^/]\.php(/|$) { fastcgi_split_path_info ^(.+?\.php)(/.*)$; if (!-f $document_root$fastcgi_script_name) { return 404; } # This is a robust solution for path info security issue and works with "cgi.fix_pathinfo = 1" in /etc/php.ini (default) include fastcgi_params; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; # fastcgi_intercept_errors on; fastcgi_pass php; }
修改 wp-config.php
在 wp-config.php 加入数据库相关的配置
. . . // ** MySQL settings - You can get this info from your web host ** // /** The name of the database for WordPress */ define('DB_NAME', 'wordpress'); /** MySQL database username */ define('DB_USER', 'wordpressuser'); /** MySQL database password */ define('DB_PASSWORD', 'password'); . . .
启动 HTTP 服务器并配置 WordPress
启动 nginx
# systemctl start nginx
访问 站点 即可配置 WordPress。
Troubleshooting
打开站点发现是空白页面
在 /etc/nginx/fastcgi_params
文件最后加入一行
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
参考
- WordPress 搭建过程:
https://www.digitalocean.com/community/tutorials/how-to-install-wordpress-with-nginx-on-ubuntu-14-04 - WordPress 搭建过程:
https://codex.wordpress.org/Installing_WordPress - nginx 配置文件内容:
https://codex.wordpress.org/Nginx - 打开站点发现是空白页面:
http://serverfault.com/questions/223500/blank-page-wordpress-on-nginxphp-fpm