环境:Nginx+Php+Mysql
步骤概要:
1、安装Wordpress运行需要的系统环境;
sudo apt-get update
sudo apt-get install nginx php5-fpm php5-cli php5-curl php5-gd php5-mcrypt php5-mysql php5-cgi mysql-server
2、下载并配置Wordpress文件、Mysql数据库;
A、在/etc/nginx/sites-available/目录下创建文件wordpress写入如下代码并保存:
sudo nano /etc/nginx/sites-available/wordpress
# Upstream to abstract backend connection(s) for php
upstream php {
server unix:/var/run/php5-fpm.sock;
}
server {
## Your only path reference.
root /srv/www/wordpress/public_html;
listen 80;
## Your website name goes here. Change to domain.ltd in VPS
server_name _;
access_log /srv/www/wordpress/logs/access.log;
error_log /srv/www/wordpress/logs/error.log;
## This should be in your http block and if it is, it’s not needed here.
index index.php;
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location / {
# This is cool because no php is touched for static content
try_files $uri $uri/ /index.php;
}
location ~ .php$ {
#NOTE: You should have “cgi.fix_pathinfo = 0;” in php.ini
include fastcgi_params;
fastcgi_intercept_errors on;
fastcgi_pass php;
}
location ~* .(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
}
然后将Wordpress文件复制到/etc/nginx/sites-enabled/目录下,分别删除两个文件夹中的default文件。
sudo cp /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/
sudo rm /etc/nginx/sites-available/default
sudo rm /etc/nginx/sites-enabled/default
下载并解压wordpress安装文件:
sudo mkdir -p /srv/www/wordpress/logs/
sudo mkdir -p /srv/www/wordpress/public_html
cd /srv/www/wordpress/public_html
sudo wget http://cn.wordpress.org/latest.tar.gz
sudo tar xzvf latest.tar.gz
sudo mv wordpress/* .
注:/latest.tar.gz 需根据最新的文件下载报名更改;
设置Mysql数据库(其中的123456为wordpress数据库的密码):
$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 5340 to server version: 3.23.54
Type ‘help;’ or ‘h’ for help. Type ‘c’ to clear the buffer.
mysql> CREATE DATABASE wordpress;
Query OK, 1 row affected (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON wordpress.* TO “wordpress”@”localhost”IDENTIFIED BY “123456″;
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
mysql> EXIT
Bye
$
将/srv/www/wordpress/public_html目录下的wp-config-sample.php文件名改为wp-config.php然后打开修改其中的以下几行:
sudo cd /srv/www/wordpress/public_html
sudo mv wp-config-sample.php wp-config.php
define(‘DB_NAME’, ‘wordpress’);
define(‘DB_USER’, ‘wordpress’);
define(‘DB_PASSWORD’, ’123456′);
重启 nginx 和 php5-fpm并设置目录权限:
sudo chown www-data.www-data /srv/www/wordpress/public_html/ -R
sudo service nginx restart
sudo service php5-fpm restart
3、配置完成后,进行线上WP安装,Done!
在浏览器中输入http://你的CBip/wp-admin/install.php,就可以安装wordpress啦!
注:
如果后续更换了IP地址或域名,可用以下方式进行登录修改:
找到/srv/www/wordpress/目录下的wp-config.php,在其中添加如下内容:
define(‘RELOCATE’,true);
登录后台修改常规设置里的网站URL即可。