最近想要整个 blog,记录自己工作、学习中的点滴。Wordpress 自然是首选,因为内容才是关键,所以也就不怕别人说太 low。网上大部份都是讲 wordpress 配合 apache 的安装教程。基于 nginx 的只有几篇比较老的,有些已经不太适用了。捣鼓了小半天,终于搞定,分享出来,也给需要的朋友一个参考。
一、下载 & 解压 wwordpress
先新建一个临时目录,用于存放各种临时的安装包,例如 ~/temp
mkdir ~/temp
cd ~/temp
下载 wordpress
wget https://wordpress.org/latest.zip -O wordpress.zip
解压
unzip wordpress.zip
将解压后的文件夹移动到提供 web 服务器的目录下,例如 /var/www
sudo mv wordpress /var/www/
记住/var/www/wordpress 这个目录,在第四步,安装 & 配置 nginx 的时候,我们将会用到它
二、安装 & 配置 mysql 5.7.19
访问:https://dev.mysql.com/downloads/repo/yum/
下载:mysql57-community-release-el7-11.noarch.rpm
wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
执行
sudo rpm -ivh mysql57-community-release-el7-11.noarch.rpm
安装 mysql
sudo yum install mysql-community-server
安装完成之后,用下面的命令获取 mysql 自动生成的临时登陆密码
用这个临时登陆密码
mysql -u root -p
登陆 mysql
然后,依次执行下面的命令,修改登陆密码 (将 YOUR_PASSWORD 换成你想要设置的密码)
use mysql;
update user set password=PASSWORD("YOUR_PASSWORD") where user="root";
flush privileges;
创建 wordpress 数据库,并退出
CREATE DATABASE wordpress;
quit;
记住数据库的名称 wordpress ,以及你设置的mysql 登陆密码 ,我们在第五步,安装 wordpress 的时候,需要用到它们。
三、安装 & 配置 php 7.0 & php-fpm
安装 PHP7 的 yum 源
sudo rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
安装 php 7, php-fpm
sudo yum install php70w php70w-fpm php70w-mysql php70w-gd php70w-mbstring
打开 php 配置文件
sudo vim /etc/php.ini
找到 cgi.fix_pathinfo,取消注释,并将其设置为 0
; http://php.net/cgi.fix-pathinfo
cgi.fix_pathinfo=0
打开 php-fpm 配置文件
sudo vim /etc/php-fpm.d/www.conf
修改下面几处地方
; RPM: apache Choosed to be able to access some dir as httpd
;user = apache
; RPM: Keep a group allowed to write in log dir.
;group = apache
user = nginx
group = nginx
; '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
;listen = 127.0.0.1:9000
listen = /var/run/php-fpm.sock
; Default Values: user and group are set as the running user
; mode is set to 0660
listen.owner = nginx
listen.group = nginx
重启 php-fpm
sudo systemctl restart php-fpm
设置系统启动时自动运行 php-fpm
sudo systemctl enable php-fpm
记住listen = /var/run/php-fpm.sock ,第四步,安装 & 配置 nginx 的时候需要用到
四、安装 & 配置 nginx 1.12.1
新建 nginx 源文件
sudo vim /etc/yum.repos.d/nginx.repo
写入以下内容
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
安装 nginx
sudo yum install nginx
备份 nginx 配置文件
sudo cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.back
打开 nginx 配置文件
sudo cp /etc/nginx/conf.d/default.conf
按如下方式修改配置
server {
listen 80;
server_name www.YOUR_DOMAIN.com;
# 将 YOU_DOMAIN 换成你自己的域名
# /var/www/wordpress 与第一步,wordpress 的存放目录一致
root /var/www/wordpress;
index index.php index.html index.htm;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
try_files $uri $uri/ /index.php?$args;
}
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;
# /var/run/php-fpm.sock 要和第三步,php-fpm 的配置一致
fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
重启 nginx
sudo systemctl restart nginx
五、安装 wordpress
更改 wordpress 所有者为 nginx
sudo chown -R nginx:nginx /var/www/wordpress/
复制示例生成配置文件
sudo cp /var/www/wordpress/wp-config-sample.php /var/www/wordpress/wp-config.php
打开配置文件
sudo vim /var/www/wordpress/wp-config.php
填入第二步,设置的 mysql 数据库名称、用户名和密码
// ** 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', 'root');
/** MySQL database password */
define('DB_PASSWORD', 'YOUR_MYSQL_PASSWORD');
将 YOUR_MYSQL_PASSWD 替换成你自己的 mysql 登陆密码
访问 www.YOUR_DOMAIN.com/wp-admin/install.php
按照提示一步步开始安装 wordpress 啦!
【原文链接】http://www.ipaomi.com/2017/08/01/wordpress-4-8-安装配置教程-(基于-centos-7-3-php-7-0-mysql-5-7-19-nginx-1-12-1)/
运维网声明
1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网 享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com