您的位置:首页 > 运维架构 > Nginx

基于Nginx的Ubuntu14系统安装WordPress

2016-01-22 17:10 676 查看
这篇文章翻译自:https://www.digitalocean.com/community/tutorials/how-to-install-wordpress-with-nginx-on-ubuntu-14-04
其中有一些错误,包括一些软件包已经不是原来的名字,在翻译的过程中已经改正,并且在我的机器上实际运行过,一下命令基本是从我history里面copy出来的。

简介:

WordPress是世界上最流行的CMS系统,他搭建起来非常方便,很容易就可以建成自己的个人主页或者博客,并且管理起来也十分方便。
这篇文章主要教大家如何在Ubuntu14.04的系统用Nginx, PHP, Mysql来搭建自己的WordPress系统。

预备条件:

首先你要有一个能上网的Ubuntu14系统,然后安装好LEMP软件。具体请参考:https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-14-04
sudo apt-get update
sudo apt-get install nginx mysql-server php5-fpm php5-mysql


第一步:给WordPress创建数据库和用户、权限等:
当在安装mysql-server的时候,系统会提示输入root用户登录数据库的密码。创建数据库的步骤为:

mysql -u root -p
CREATE DATABASE wordpress;
CREATE USER wordpressuser@localhost IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost;
FLUSH PRIVELEGES;
exit
第二步:下载最新版WordPress,并安装WordPress需要的PHP的一些组件:
cd
wget https://wordpress.org/latest.tar.gz tar zxvf latest.tar.gz
cd wordpress
apt-get install php5-gd libssh2-php
第三步:配置WordPress:
cd wordpress
cp wp-config-sample.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');
第四步:复制配置文件到网站根目录:

rsync -avP ../wordpress/ /var/www/html/
j ht(此条命令不懂的请看这篇文章http://shanker.blog.51cto.com/1189689/1737213)
mkdir -p wp-content/upload
chown -R www-data: /var/www/html/* (此处的文件所属用户权限的用户名应该跟你的Nginx的用户名一致)
这里需要注意,如果rsync 后面的目录用的wordpress/ 则复制该目录下面的所有文件到html目录下,如果是wordpress,没有那个/,则是复制workdpress 目录到html目录下,完全两个概念。

第五步:配置Nginx文件:
cp /etc/nginx/sites-available/default /etc/nginx/sites-available/wordpress
vi /etc/nginx/sites-available/wordpress
做出的更改如红色字体所示:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/html;
index index.php index.html index.htm;
server_name your_domain.com;
location / {
# try_files $uri $uri/ =404;
try_files $uri $uri/ /index.php?q=$uri&$args;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
代码改成bash格式时候 红色标注就去掉了,改动的地方就是根目录指向/var/www/html,搜索index 先搜索index.php,更改server_name,更改location / try_files的方式。

然后创建一个软连接到site-enabled,删除默认的default,重启Nginx和php5.

ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/
rm /etc/nginx/sites-enabled/default
service nginx restart
service php5-fpm restart
第六步:基于Web页面的配置WordPress:

输入你的域名,或者ip地址,打开WordPress的初始化安装,如图:



安装完成后输入用户名和密码即可进入自己的博客啦。




欢迎大家访问我的小博客:http://shanker.heyoa.com or http://google.heyoa.com/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: