WordPress是世界上最流行的CMS系统,他搭建起来非常方便,很容易就可以建成自己的个人主页或者博客,并且管理起来也十分方便。
这篇文章主要教大家如何在Ubuntu 14.04的系统用Nginx, PHP, MySQL来搭建自己的WordPress系统
- 预演
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
参考来源,感谢以下链接: