WordPress简易安装教程
WordPress,可能是比较流行的博客了,于是随便下下来装着玩玩。
需要准备的软件:wordpress, nginx/apache, mysql
wordpress可以从官网下载最新的安装包;如果想要中文版可移步中文官网。
然后解压到某个路径下,如/usr/local/wordpress。大概看一下包里的东西,会发现好多是php文件,因此需要安装php环境,并且开启mysql支持。
环境准备好后,连接到mysql数据库,创建一个数据库(database)。然后进入到wordpress目录下,会发现有一个wp-config-sample.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', '<dbname>' );
/** MySQL database username */
define( 'DB_USER', '<user>' );
/** MySQL database password */
define( 'DB_PASSWORD', '<pass>' );
/** MySQL hostname */
define( 'DB_HOST', '<host>' );
/** Database Charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8' );
/** The Database Collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );
需要把数据库的配置填充到这些变量定义中,底下两个可以不改,或者按实际情况填写。
然后在nginx配置一个server来负载wordpress的请求,贴一段代码:
server {
listen 80;
server_name wordpress;
location / {
root /home/zeon/documents/web/wordpress;
index index.php index.html index.htm;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ \.(css|js|ico)$ {
root /home/zeon/documents/web/wordpress;
}
location ~ \.(gif|jpg|png|jpeg)$ {
gzip on;
root /home/zeon/documents/web/wordpress;
}
}
}
最后,访问ip:80就可以进到wordpress界面啦!有图有真相:
记录两个坑点。(别笑,要铭记每个坑给的伤痛
-
页面上提示“critical error in your website”,没有任何其他的提示信息,这时候需要把调试开关打开,我这里的情况是php安装的是7.3.0,属于比较新的版本,需要开启mysqli支持,如果php没装好那么可能会报mysql_connect无法加载的错误。参考指令:
'./configure' '--prefix=/usr/local/php' '--enable-fpm' '--with-mysqli=mysqlnd' '--with-openssl' '--with-zlib' '--with-pcre-dir=/usr/local/pcre'
-
页面显示File not found。nginx日志Primary script unknown。一是检查这行配置,确认是
$document_root$fastcgi_script_name
。fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_scrip t_name;
二是要确认root的配置。(我就栽在这了~~)