Products
GG网络技术分享 2025-03-18 16:13 83
wordpress搭建教程,WordPress是一款使用PHP语言开发的博客平台,站长可使用通过WordPress搭建属于个人的网站。本文主要分享如何wordpress建站的wordpress搭建教程,从服务器配置、域名解析、面板设置、wordpress建站、网站优化等一些列操作讲解wordpress搭建教程,站长可以学习到的不仅仅是如何成功搭建一个Wordpress网站,更多的是学习Wordpress网站优化,Wordpress可以很强大,但是前提是站长已经掌握了它。
wordpress搭建教程技巧分享,详细步骤说明如下:
Linux:Linux 操作系统,以ubuntu18.04 为例;nginx:Web 服务器;mysql:数据库;PHP:脚本语言;CMS:WordPress,操作步骤:
wordpress搭建教程步骤1:登录云服务器
win系统建议使用Xshell软件进行登陆
Mac以及ubuntu系统可以使用自带的终端进行登陆
ssh-p端口号服务器用户名@ip(例如ssh-p22 username@111.222.111.222)
wordpress搭建教程步骤2:搭建环境
apt update && apt upgrade
apt install -y nginx mysql-server unzip python-certbot-nginx
apt install -y php php-fpm php-mysql php-gd php-json php-xml php-mbstring
wordpress搭建教程步骤3:配置数据库
执行以下命令,进入mysql
mysql
执行以下命令,创建 mysql 数据库。例如 “wordpress”
CREATE DATABASE wordpress;
执行以下命令,创建一个新用户。例如 “user”,登录密码为 123456
CREATE USER 'user'@'localhost' IDENTIFIED BY '123456';
执行以下命令,创建一个新用户。例如 “user”,登录密码为 123456
GRANT ALL PRIVILEGES ON wordpress.* TO 'user'@'localhost' IDENTIFIED BY '123456';
执行以下命令,退出 mysql
\\q
wordpress搭建教程步骤4:安装和配置 WordPress
下载并解压WordPress软件包
wget WordPress/latest.zip && unzip latest.zip
设置目录权限
chown -R www-data:www-data wordpress/
wordpress搭建教程步骤5:域名解析获取https证书
域名解析一般设置两条记录就够了,即将域名指向站长自己VPS的 IP地址
申请https证书这里使用 Let’s Encrypt 免费证书
配置 Nginx 以便于 Let’s Encrypt 能起作用:
sudo vim /etc/nginx/sites-enabled/default
default替换成你自己的Nginx配置文件名,清空原有内容并添加下面的配置
server {
listen 80;
listen [::]:80;
server_name 你的域名;
}
保存退出之后,执行以下命令来检测 Nginx 的配置文件是否有错
sudo nginx -t
如果出现这样的语句,就说明 Nginx 的配置文件没有问题
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
重新加载 Nginx 的配置文件了
sudo nginx -s reload
执行命令获取证书
sudo certbot --nginx -d 你的域名
如果第一次运行 certbot 命令的话,需要在弹出的窗口输入站长的邮箱地址还有需要接受 Let’s Encrypt 的协议,执行完后,就会有输出一段字符
然后在文字中,这个/etc/letsencrypt/live/你的域名/fullchain.pem 路径很重要,就是你的 SSL 证书路径。
自动更新证书
因为 Let’s Encrypt 签发的证书有效期只有 90 天,所有在过期之前,我们需要自动更新 SSL 证书,而如果你使用最新的 certbot 的话,Let’s Encrypt 会帮你添加自动更新的脚本到 /etc/cron.d 里,你只需要去检测一下这个命令是否生效就OK!
sudo certbot renew --dry-run
如果这个命令你没看到什么 error 的话,那就是没什么问题了。
wordpress搭建教程步骤6:配置nginx
打开第五步设置的Nginx配置文件名
sudo vim /etc/nginx/sites-enabled/default
在ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot后加入如下内容
root /home/wordpress;
## This should be in your http block and if it is, it's not needed here.
client_max_body_size 10M;
index index.php;
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
location / {
# This is cool because no php is touched for static content.
# include the "?$args" part so non-default permalinks doesn't break when using query string
try_files $uri $uri/ /index.php?$args;
}
location ~ \\.php$ {
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
include fastcgi.conf;
fastcgi_intercept_errors on;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
client_max_body_size 10m;
}
location ~* \\.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
保存退出之后,执行以下命令来检测 Nginx 的配置文件是否有错
sudo nginx -t
如果出现这样的语句,就说明 Nginx 的配置文件没有问题
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
重新加载 Nginx 的配置文件了
sudo nginx -s reload
wordpress搭建教程步骤7:初始化wordpress
搭建完成,访问站点,“现在开始”,按提示配置 WordPress。
填写上面记录下的数据库信息,提交。
填写网站标题以及设置管理员账号密码
登陆后台
wordpress搭建教程的总体过程已经分享给大家,希望对大家能有所帮助,如果还有不明白,可以结合文章图片来阅读,快速完成一键建站。
今天有位小伙伴在群中询问wordpress新用户注册显示密码的问题,由于wordpress默认的是不让用户自己去填写密码的,而是系统自动给用户生成一个密码并且发送到用户邮箱,相对来说可能有些用户会不习惯,今天小V就来教大家优化wordpress的用户注册体验,让用户自己设置账户密码,其实很简单只需要在主题的function.php加上以下代码:
<?phpadd_action( \'register_form\', \'tiezhu__show_register\' );
function tiezhu__show_register(){
?>
<p>
<label for=\"password\">密码:<br/>
<input id=\"password\" class=\"input\" type=\"password\" tabindex=\"30\" size=\"25\" value=\"\" name=\"password\" />
</label>
</p>
<p>
<label for=\"repeat_password\">确认密码<br/>
<input id=\"repeat_password\" class=\"input\" type=\"password\" tabindex=\"40\" size=\"25\" value=\"\" name=\"repeat_password\" />
</label>
</p>
<p>
<label for=\"are_you_human\" style=\"font-size:11px\">挖掘机技术哪家强?(蓝翔)<br/>
<input id=\"are_you_human\" class=\"input\" type=\"text\" tabindex=\"40\" size=\"25\" value=\"\" name=\"are_you_human\" />
</label>
</p>
<?php
}
add_action( \'register_post\', \'ts_check_extra_register_fields\', 10, 3 );
function ts_check_extra_register_fields($login, $email, $errors) {
if ( $_POST[\'password\'] !== $_POST[\'repeat_password\'] ) {
$errors->add( \'passwords_not_matched\', \"<strong>ERROR</strong>: 两次密码不一致\" );
}
if ( strlen( $_POST[\'password\'] ) < 8 ) {
$errors->add( \'password_too_short\', \"<strong>ERROR</strong>: 密码长度小于8位!\" );
}
if ( $_POST[\'are_you_human\'] !== \'蓝翔\' ) {
$errors->add( \'not_human\', \"<strong>ERROR</strong>: 回答错误,请重新填写注册信息!\" );
}
}
为了保证不被注册机骚扰此代码中还自带了一个验证问题字段,防止注册机批量注册垃圾用户。虽然让用户可以自己填写密码,但是有些用户更加喜欢让系统为他生成密码,为了给这些用户提供方便,我们可以判断下当前用户注册时是否填了密码,如果没填再让系统生成一个,代码如下:
add_action( \'user_register\', \'tiezhu_register_extra_pass\', 100 );function tiezhu_register_extra_pass( $user_id, $password=\"\", $meta=array() ){
$userdata = array();
$userdata[\'ID\'] = $user_id;
if( $_POST[\'password\'] ){
$userdata[\'user_pass\'] = $_POST[\'password\'];
}
wp_update_user($userdata);
}
/*如果强制用户输入密码,则可将此段代码的注释去除
add_action(\'admin_init\', \'tiezhu_remove_default_password_nag\');
function tiezhu_remove_default_password_nag() {
global $user_ID;
delete_user_setting(\'default_password_nag\', $user_ID);
update_user_option($user_ID, \'default_password_nag\', false, true);
}
*/
当然为了给用户更好的体验,我们可以在注册框下方加个提示,代码如下:
add_filter( \'gettext\', \'tiezhu_edit_text\' );function tiezhu_edit_text( $text ) {
if ( $text == \'A password will be e-mailed to you.\' ) {
$text = \'如果您不填写密码,系统将为您生成一个密码, 并发送至您的邮箱。\';
}
return $text;
}
Demand feedback