WordPress博客kk

使用WorkPress建立个人博客

2019-06-21  本文已影响2人  Sheng_W_Z


我的博客:https://www.swzdl.club
本文地址:https://www.swzdl.club/?p=70
博客上排版更好看

目录



本文操作系统:CentOS 7.6 64位

1 配置LNMP环境

1.1 安装Nginx

1.1.1 安装Nginx:

    yum install nginx -y

注: CentOS 6不支持对IPV6的监听,这里用的是CentOS 7,
故不需要修改配置取消对IPV6的监听

1.1.2 安装完成后,使用nginx命令启动服务.

   nginx

此时可以使用外网访问http://ip,看到Nginx默认界面

1.1.3 设置Nginx为开机自启动:

    systemctl enable nginx

注: CentOS 6使用命令:chkconfig nginx on




1.2 安装MySQL

对于CentOs 7,直接执行yum install mysql命令是无效的,因为CentOS 7默认是Mariadb.
因此应当进行以下操作步骤

1.2.1 删除可用的mysql:

    yum remove mysql

1.2.2 下载mysql的repo源:

    wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

1.2.3 安装mysql-community-release-el7-5.noarch.rpm包:

    sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm

注:安装这个包会获得两个mysql的yum repo源:
/etc/yum.repos.d/mysql-community.repo
/etc/yum.repos.d/mysql-community-source.repo

1.2.4 安装mysql:

    sudo yum install mysql-server -y

1.2.5 安装完成后查看mysql:

    rpm -qa | grep mysql

1.2.6 设置开机自启动:

    systemctl enable mysqld

注:Cent OS 6使用命令chkconfig mysqld on

1.2.7 设置MySQL的root账户密码:

    /usr/bin/mysqladmin -u root password 'YourPwd'




1.3 安装PHP

1.3.1 执行命令:

    rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
    rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

1.3.2 安装PHP:

    yum install php70w.x86_64 php70w-cli.x86_64 php70w-common.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64 php70w-mysql.x86_64 php70w-pdo.x86_64

1.3.3 安装php-fpm:

    yum install php70w-fpm php70w-opcache

1.3.4 启动php-fpm:

    systemctl start php-fpm

1.3.5 设置开机自启:

    systemctl enable php-fpm
    systemctl daemon-reload




2 安装配置Wordpress

2.1 安装WordPress

2.1.1 执行命令:

    yum install wordpress -y

注:安装完成后,就可以在/usr/share/wordpress 看到WordPress的源码




2.2 配置数据库:

2.2.1 登录数据库:

mysql -uroot --password='YOURPWD'

2.2.2 创建名为wordpress的数据库:

CREATE DATABASE wordpress;

2.2.3 退出数据库:

exit;

2.2.4 将数据库配置同步到WordPress配置中:

cd /etc/wordpress/
ls
nano wp-config.php

找到其中关于数据库配置的部分,参考下图修改:

<?php
/**只要修改这里的数据库名称,账号,密码*/
define('DB_NAME', 'wordpress');
/** MySQL database username */
define('DB_USER', 'root');
/** MySQL database password */
define('DB_PASSWORD', 'YOURPWD');

/**以下部分不用修改*/
/** MySQL hostname */
define('DB_HOST', 'localhost');
/** 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', '');


define('AUTH_KEY',         'put your unique phrase here');
define('SECURE_AUTH_KEY',  'put your unique phrase here');
define('LOGGED_IN_KEY',    'put your unique phrase here');
define('NONCE_KEY',        'put your unique phrase here');
define('AUTH_SALT',        'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT',   'put your unique phrase here');
define('NONCE_SALT',       'put your unique phrase here');

$table_prefix  = 'wp_';
define('WP_DEBUG', false);
if ( !defined('ABSPATH') )
    define('ABSPATH', '/usr/share/wordpress');
require_once(ABSPATH . 'wp-settings.php');

如图所示:




2.3 配置Nginx

2.3.1 WordPress 已经安装完毕,接着配置 Nginx 把请求转发给 PHP-FPM 来处理

nano /etc/nginx/nginx.conf

2.3.2 修改其中server中的部分:

 server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;

        将原来root后的地址改为WordPress的地址
        #root /usr/share/nginx/html;
        root /usr/share/wordpress;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
        添加location中的内容:
        index index.php index.html index.htm;
        try_files $uri $uri/ /index.php index.php;
        }

#添加如下代码:
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    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;
    }



        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

如下图所示:

image

2.3.3 重新载入nginx:

nginx -s reload

注:此时访问http://YourIP,就可以进入WordPress的设置页面

如图所示:

image


3 其他功能的实现


3.1 删除一些不必要的组件:

如图所示,删除其中的:"文章RSS""评论RSS"、"WordPress.org":

image

编辑footer.php
nano wp-content/themes/twentyeleven/footer.php;

/**删除以下内容或者修改为自己想要的文字*/
<a href="<?php echo esc_url( __( 'http://swzdl.club/', 'twentyseventeen' ) ); ?>" class="imprint">
    <?php printf( __( 'Copyright © 2018<script>new Date().getFullYear()>2018&&document.write("-"+new Date().getFullYear());</script>-2019 Mr.Sheng. All Rights Reserved.' ), 'WordPress' ); ?>
</a>

编辑class-wp-widget-meta.php

 nano wp-include/widgets/class-wp-widget-meta.php
/**删除以下内容*/
<li><a href="<?php echo esc_url( get_bloginfo( 'rss2_url' ) ); ?>"><?php _e( 'Entries <abbr title="Really Simple Syndication">RSS</abbr>' ); ?></a></li>
<li><a href="<?php echo esc_url( get_bloginfo( 'comments_rss2_url' ) ); ?>"><?php _e( 'Comments <abbr title="Really Simple Syndication">RSS</abbr>' ); ?></a></li>

去除WordPress.org

/**删除以下内容*/
            /**
             * Filters the "Powered by WordPress" text in the Meta widget.
             *
             * @since 3.6.0
             * @since 4.9.0 Added the `$instance` parameter.
             *
             * @param string $title_text Default title text for the WordPress.org link.
             * @param array  $instance   Array of settings for the current widget.
             */

echo apply_filters(
            'widget_meta_poweredby',
            sprintf(
                '<li><a href="%s" title="%s">%s</a></li>',
                esc_url( __( 'https://wordpress.org/' ) ),
                esc_attr__( 'Powered by WordPress, state-of-the-art semantic personal publishing platform.' ),
                _x( 'WordPress.org', 'meta widget link text' )
            ),
            $instance
        );



3.2 实现发邮件功能:插件Easy WP SMTP

配置如下图:

image

3.3 新用户注册或者用户密码找回时,点击链接,提示链接无效

image

原因是邮箱收到邮件后,会将密码重置链接地址及其前后的“<>”一起当成链接地址生成超链接,点击此超链接后,由于传给wordpress的参数不对(多了个"<>"),例如把鼠标移到下图的红色框的连接上,并看到浏览器左下角的URL提示连接,会发现多了“<>”,所以wordpress提示密码重设链接无效。

解决方法:

3.3.1 解决找回密码时提示“您的密码重设链接无效”:

打开WP根目录下的 wp-login.php,找到如下代码(390行左右):
$message .= '<' . network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login), 'login') . ">\r\n";

修改为

  :`$message .= network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login), 'login') . "\r\n";

3.3.2 解决新用户注册时,点击邮件中的重置密码链接提示“您的密码重设链接无效”:

打开WP安装目录下的/wp-includes/pluggable.php,找到如下代码(1981行左右):
 $message .= '<' . network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user->user_login), 'login') . ">\r\n\r\n";

修改为:

  $message .= network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user->user_login), 'login') . "\r\n\r\n";

注:每次升级WordPress都要重新修改




3.4 部署Nginx证书,实现https访问:

证书申请请自行解决

3.4.1 修改Nginx配置:

nano /etc/nginx/nginx.conf

3.4.2 对其中两个server配置如下:

    server {
         listen       80 default_server;
        listen       [::]:80 default_server;
#填入你的域名
        server_name  YourDomainName.com;
        rewrite ^(.*)$ https://$host$1 permanent;
#替换目录
         root /usr/share/wordpress;
        #root /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
#添加以下两行
        index index.php index.html index.htm;
        try_files $uri $uri/ /index.php index.php;
        }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#!!!add this 'location'!!!
   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;
    }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }


# Settings for a TLS enabled server.
    server {
        listen       443 ssl http2 default_server;
        listen       [::]:443 ssl http2 default_server;
        server_name  swzdl.club;
        root /usr/share/wordpress;
#写你存放证书的目录
        ssl_certificate "/etc/pki/nginx/example.crt";
        ssl_certificate_key "/etc/pki/nginx/example.key";
        ssl_session_cache shared:SSL:1m;
        ssl_session_timeout  10m;
        ssl_ciphers HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers on;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
            index index.php index.html index.htm;
            try_files $uri $uri/ /index.php index.php;
       }

       # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
       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;
    }

    error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
  }

注:上传到/etc/pki/nginx/目录中,如果无此目录则新建,权限为777

3.4.3 而后重启nginx

systemctl stop nginx.service
nginx

3.4.4 如果此时报错:

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

如图所示:

image

3.4.5 则查看端口,杀掉占用的进程:

netstat -ntpl

如图所示:

image

发现php-fpm正在运行且占用了80端口,暂时关闭php-fpm,待启动nginx后再启动:systemctl stop php-fpm.service,然后kill其他占用80端口的服务:

image image

3.4.6 再次使用nginx命令启动Nginx;启动php-fpm:

image

3.5 其他

最后放一下我的博客首页的截图:


我的博客首页_0 我的博客首页_1

可以访问网址:https://www.swzdl.club查看我的博客

上一篇下一篇

猜你喜欢

热点阅读