好物优选点击查看详情 京东购买

暂无内容

使用WordPress建立个人博客

首先备份 CentOS-Base.repo

编辑CentOS-Base.repo

vi /etc/yum.repos.d/CentOS-Base.repo 

将原内容替换为以下内容

# CentOS-Base.repo # # The mirror system uses the connecting IP address of the client and the # update status of each mirror to pick mirrors that are updated to and # geographically close to the client. You should use this for CentOS updates # unless you are manually picking other mirrors. # # If the mirrorlist= does not work for you, as a fall back you can try the # remarked out baseurl= line instead. # # [base] name=CentOS-$releasever - Base baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 #released updates [updates] name=CentOS-$releasever - Updates baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 #additional packages that may be useful [extras] name=CentOS-$releasever - Extras baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 #additional packages that extend functionality of existing packages [centosplus] name=CentOS-$releasever - Plus baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus gpgcheck=1 enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 

获取Nginx软件源

rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm 

安装Nginx

 yum install nginx -y 

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

nginx 

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

systemctl enable nginx 

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

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

yum remove mysql 
wget http://repo.mysql.com/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

 sudo yum install mysql-server -y 
rpm -qa | grep mysql 
systemctl enable mysqld 

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

/usr/bin/mysqladmin -u root password 'YourPwd' 
 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 
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 
yum install php70w-fpm php70w-opcache 
systemctl start php-fpm 
systemctl enable php-fpm systemctl daemon-reload 
yum install wordpress -y 

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

 mysql -uroot --password='YOURPWD' 
CREATE DATABASE wordpress; 
exit; 
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'); 

如图所示:

nano /etc/nginx/nginx.conf 
 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 { } } 

如下图所示:

nginx -s reload 

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

如图所示:

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

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

/**删除以下内容或者修改为自己想要的文字*/ <a href="<?php%20echo%20esc_url(%20__(%20'http://swzdl.club/',%20'twentyseventeen'%20)%20);%20?>" 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%20echo%20esc_url(%20get_bloginfo(%20'rss2_url'%20)%20);%20?>"><?php _e( 'Entries <abbr title="Really Simple Syndication">RSS</abbr>' ); ?></a></li> <li><a href="<?php%20echo%20esc_url(%20get_bloginfo(%20'comments_rss2_url'%20)%20);%20?>"><?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 ); 

配置如下图:

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

解决方法:

打开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"; 
打开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都要重新修改

证书申请请自行解决

nano /etc/nginx/nginx.conf 
 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

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

如图所示:

netstat -ntpl 

如图所示:

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

  • 查看开机自启项: systemctl list-unit-files

  • 仅看允许的开机自启项:systemctl list-unit-files | grep enable

  • WordPress配置文件路径:/etc/wordpress/

  • WordPress资源路径:/usr/share/wordpress/

  • 插件商店:https://cn.wordpress.org/plugins/

  • 插件上传文件夹:/usr/share/wordpress/wp-content/plugins

  • 主题商店:https://wordpress.org/themes/

  • 主题上传文件夹:/usr/share/wordpress/wp-content/themes

  • 设置中文的方法:
    进入WordPress官方网址:https://cn.wordpress.org/download/releases/
    下载对应版本的语言包,解压.将解压得到的文件夹中wp-content中的langage文件夹上传到服务器中的/usr/share/wordpress/wp-content文件夹内,而后在WordPress后台界面设置中将语言改为简体中文,刷新即可

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

原文链接:https://www.jianshu.com/p/6462d574409b

© 版权声明
THE END
喜欢就支持一下吧
点赞15 分享