LNMP+WordPress快速搭建个人博客

目录

 

0.前言

1.安装Linux

2.安装Nginx

3.安装MySql

4.安装PHP

5.安装WordPress

6.配置MySQL

7.配置Nginx

8.创建博客

9.修改主题

10.常见问题


0.前言

WordPress中文官网:https://cn.wordpress.org

搭建完的博客地址:http://www.amwalle.com/blog/

正式安装之前,可以先看一下官方的安装指导:https://codex.wordpress.org/zh-cn:安装WordPress

系统要求(2019/08/18):

1.安装Linux

略。直接使用的阿里云“轻量应用服务器”(LAMP镜像)。

2.安装Nginx

我安装的是OpenResty,如果想直接安装Nginx,这一步请参考这里:https://www.runoob.com/linux/nginx-install-setup.html

OpenResty安装指导参考:https://openresty.org/en/installation.html

** 下载openresty **

wget https://openresty.org/download/openresty-1.15.8.1.tar.gz

 ** 解压openresty **

tar -xvf openresty-VERSION.tar.gz
cd openresty-VERSION/

** 安装依赖 **

yum install pcre-devel openssl-devel gcc curl

** 配置 **

./configure \ 
--with-cc-opt="-I/usr/local/opt/openssl/include/ -I/usr/local/opt/pcre/include/" \ 
--with-ld-opt="-L/usr/local/opt/openssl/lib/ -L/usr/local/opt/pcre/lib/" \ 
-j8

** 安装 openresty **

make
make install

** 检查安装结果 **

cd /usr/local/openresty/nginx/sbin
./nginx -t

如果显示如下则说明安装成功:

nginx: the configuration file /usr/local/openresty/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/openresty/nginx/conf/nginx.conf test is successful

3.安装MySql

略。我的服务器上已经安装了MySql。如有需要,请参考这里:https://www.runoob.com/mysql/mysql-install.html

4.安装PHP

安装PHP需要注意版本要求。阿里云“轻量应用服务器”(LAMP镜像)已经安装了PHP,但是版本较低;

因此我删除了之前的PHP安装文件,重新进行了源码安装。

** 下载PHP **

wget https://www.php.net/distributions/php-7.3.8.tar.gz

** 解压缩 **

tar -xvf php-7.3.8.tar.gz
cd php-7.3.8
mkdir /usr/local/php7

** 安装依赖 **

yum install -y freetype-devel libevent libevent-devel libxml2 libxml2-devel ncurses ncurses-devel  openssl openssl-devel  libjpeg libjpeg-devel libpng libpng–devel zlib-devel  bzip2 bzip2-devel libmcrypt libmcrypt-devel

** 配置项 **

./configure --prefix=/usr/local/php7 \
 --with-curl \
 --with-freetype-dir \
 --with-gd \
 --with-gettext \
 --with-iconv-dir \
 --with-kerberos \
 --with-libdir=lib64 \
 --with-libxml-dir \
 --with-mysqli \
 --with-openssl \
 --with-pcre-regex \
 --with-pdo-mysql \
 --with-pdo-sqlite \
 --with-pear \
 --with-png-dir \
 --with-xmlrpc \
 --with-xsl \
 --with-zlib \
 --enable-fpm \
 --enable-bcmath \
 --enable-libxml \
 --enable-inline-optimization \
 --enable-gd-native-ttf \
 --enable-mbregex \
 --enable-mbstring \
 --enable-opcache \
 --enable-pcntl \
 --enable-shmop \
 --enable-soap \
 --enable-sockets \
 --enable-sysvsem \
 --enable-xml \
 --enable-zip

** 安装PHP **

make
make install

** 完善配置 **

cp /usr/local/php7/etc/php-fpm.conf.default/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf.default/php-fpm.conf
cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf

新建用户和组:

groupadd www-data
useradd -g www-data www-data

修改配置文件的用户和组,将user改为“www-data”,将group改为“www-data”,然后保存退出:

vim /usr/local/php7/etc/php-fpm.d/www.conf
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
user = www-data
group = www-data

** 启动PHP **

cd /usr/local/php7/sbin
./php-fpm

 

5.安装WordPress

我是安装的中文版()。

** 下载WordPress **

wget https://cn.wordpress.org/latest-zh_CN.tar.gz

** 解压缩 **

tar -xzvf latest_zh_CN.tar.gz

** 移动WordPress 到指定目录 **

nginx 默认的配置文件根目录是:html。我本地是在:/usr/local/openresty/nginx/html。

后面的安装依赖WordPress目录,我的目录是在blog下。

cd wordpress
mkdir /usr/local/openresty/nginx/html/blog
cp * /usr/local/openresty/nginx/html/blog

cd /usr/local/openresty/nginx/html
chown -R www-data:www-data blog

 

6.配置MySQL

** 建立MySql连接 **

注:先输入命令 mysql,如果没问题这一步不用执行。

ln /usr/local/mysql/bin/mysql /usr/bin

** 用root用户连接MySql **

mysql -uroot -p
> 输入mysql的root密码

** 创建WordPress要用的数据库和用户,以及用户授权 **

CREATE DATABASE wordpress;
GRANT ALL PRIVILEGES ON wordpress.* TO "wp"@"localhost" IDENTIFIED BY "自己设置用户wp的密码";
FLUSH PRIVILEGES;
EXIT

 

7.配置Nginx

进入自己的nginx安装目录,找到nginx.conf文件。我的是在: /usr/local/openresty/nginx/conf

** 设置用户为 www-data **

vim /usr/local/openresty/nginx/conf/nginx.conf

然后去掉文件第一行前面的注释:user  www-data; 

下面配置可以二选一,第一次配置,可以选择第一个

** 配置server - http **

配置参考如下(记得替换成自己的域名):

    server {
        listen       80;
        server_name  #自己的域名;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root html;
            index  index.html index.htm index.php;
        }

        #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   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~* \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
            fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }

** 配置server - https **

配置之前,要生成证书相关文件,可参考:https://blog.csdn.net/weixin_42534940/article/details/90745452

配置参考:

    # HTTPS server
    #
    server {
        listen       443 ssl;
        server_name  #改成自己的域名;

        ssl_certificate      full_chain.pem;
        ssl_certificate_key  certificate.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;

        location / {
            root   html;
            index  index.html index.htm index.php;
        }

        location ~* \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            # fastcgi_param  HTTPS on; 这个比较重要,不开启直接访问会出现 403 forbidden 错误
            fastcgi_param  HTTPS on;
            include        fastcgi_params;
            fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
        }

    }

 

8.创建博客

** 访问配置页 **

访问链接:http://example.com/blog/wp-admin/install.php

(连接替换自己的域名,或直接用服务器IP地址)

** 填入数据库信息,及其他必要信息并安装 **

** 登录主页 **

访问:http://example.com/blog/wp-admin/index.php

9.修改主题

暂略。主要是保证可用ftp用户,以及 blog 目录的用户要与nginx配置中的用户保持一致。

10.常见问题

问题1:ERROR: FPM initialization failed

[11-Aug-2019 23:20:10] ERROR: Unable to globalize '/usr/local/NONE/etc/php-fpm.d/*.conf' (ret=2) from /usr/local/etc/php-fpm.conf at line 143.
[11-Aug-2019 23:20:10] ERROR: failed to load configuration file '/usr/local/etc/php-fpm.conf'
[11-Aug-2019 23:20:10] ERROR: FPM initialization failed

解决办法:找到文件php-fpm.conf,修改其中的配置,把“include=/usr/local/NONE/etc/php-fpm.d/*.conf”这条配置中的NONE去掉。

 

问题2:您的PHP似乎没有安装运行WordPress所必需的MySQL扩展

解决:引起这个问题的主要原因是安装PHP的时候,没有安装MySQL相关的扩展应用mysqli。或者PHP版本与mysqli版本不匹配。按照前文的方式安装PHP,应该不会有这个问题。

 

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值