How To Install WordPress with nginx on Ubuntu 14.04

WordPress是世界上最流行的CMS系统,他搭建起来非常方便,很容易就可以建成自己的个人主页或者博客,并且管理起来也十分方便。

这篇文章主要教大家如何在Ubuntu 14.04的系统用Nginx, PHP, MySQL来搭建自己的WordPress系统

  1. 预演

Linux 安装 nginx, MySQL, and PHP-FPM  —   LEMP tutorial

2. 下载 WordPress
wget http://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz
3. 创建 WordPress 数据库和用户
登陆数据库
mysql -u root -p
创建数据库和用户
mysql> CREATE DATABASE wordpress;
Query OK, 1 row affected (0.00 sec)

mysql> CREATE USER wordpress@localhost;
Query OK, 0 rows affected (0.00 sec)

mysql> SET PASSWORD FOR wordpress@localhost=PASSWORD(“123456”);
Query OK, 0 rows 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.00 sec)

退出 数据库
exit

4. 设置WordPress配置
cp ~/wordpress/wp-config-sample.php ~/wordpress/wp-config.php
vi ~/wordpress/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’);
5. 复制配置文件到网站根目录

sudo mkdir -p /var/www
sudo cp -r ~/wordpress/* /var/www
cd /var/www/
sudo chown www-data:www-data * -R
sudo usermod -a -G www-data username

6. 配置Nginx文件:
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/wordpress
vi /etc/nginx/sites-available/wordpress
server {
listen 80;
#listen [::]:80 default_server ipv6only=on;

root /var/www;
index index.php index.html index.htm;

# Make site accessible from http://localhost/
server_name 192.168.1.1; #你的服务器ip

location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
# try_files $uri $uri/ =404;
try_files $uri $uri/ /index.php?q=$uri&$args;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}

# Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
#location /RequestDenied {
# proxy_pass http://127.0.0.1:8080;
#}

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/share/nginx/html;
}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
try_files $uri = 404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# # NOTE: You should have “cgi.fix_pathinfo = 0;” in php.ini
#
# # With php5-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php5-fpm:
# fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}

# deny access to .htaccess files, if Apache’s document root
# concurs with nginx’s one
#
#location ~ /\.ht {
# deny all;
#}
}
7. 激活服务
创建一个软连接到site-enabled,删除默认的default,重启Nginx和php5.
sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/wordpress
sudo rm /etc/nginx/sites-enabled/default
sudo service nginx restart
sudo service php5-fpm restart

 

参考来源,感谢以下链接:

在 Ubuntu 14.10/14.04/13.10 上安装 LEMP 服务

How To Install WordPress

Ubuntu 14.04基于Nginx安装WordPress

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值