上大学前一直筹划自己建站当站长,然而在早就买好的云服务器,一直只挂了一个静态网站,也没多少激情去维护,自己开发的动态网站,emmm,我自己都看不下去的,有点先去,那么我就搬轮子吧。就选择WordPress,有强大的社区支持。
开始吧
准备工作
服务器
无论是企业还是个人开发者,我都建议先使用云服务器,国内建议阿里云和腾讯云,国外使用AWS是首选。政府网站建议使用物理服务器。
LNMP系统
我使用的是阿里云的云服务器, 1C2G物理配置,1Mbps的网络和40G的高效硬盘。
系统采用Debian9.9
数据库使用MariaDB10.4.12
webserver使用Nginx1.17.10
编程语言使用PHP7.4.5
阿里云服务器购买链接:https://www.aliyun.com/product/ecs?source=5176.11533457&userCode=kuoc2mgi&type=copy
下面是优惠,需要的可以领取。
新用户优惠每年102元/年起:点击我
新用户2000元优惠券:点击我
域名
域名就是去各大域名厂家购买域名就行了,如果只是为了玩玩,建议购买.top域名,后期续费比较便宜,性价比比较高,其他的看个人爱好、网站用途、经济承受能力。
我的域名是在阿里云的域名市场购买的,国内的网站要使用是需要备案的,个人备案的话准备材料也也比较简单,安装官网操作就行,基本就是填写资料,幕布拍照,然后就是等待管局审核,我首次申请就12天就完成了,阿里云为了补偿我,给了我12天的云服务器使用,然后第二个域名申请就只是花了5天就弄好了。
一切准备好后,申请一个免费的SSL,这个是很有必要的,申请过程大概一个小时左右就可以下发证书,然后下载证书就可以部署了。
Nginx部署SSL的教程官网也有,我是照官网的教程然后稍微修改修改就可以了。
阿里云域名官网:https://wanwang.aliyun.com/domain/searchresult/?source=5176.11533457&userCode=kuoc2mgi&type=copy
MariaDB
安装MariaDB
将MariaDB添加到系统源
sudo apt-get install software-properties-common dirmngr sudo apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc' sudo add-apt-repository 'deb [arch=amd64,i386,ppc64el] http://mirrors.coreix.net/mariadb/repo/10.4/debian stretch main'
使用apt安装MariaDB
sudo apt-get update sudo apt-get install mariadb-server
配置MariaDB
安装页面:https://downloads.mariadb.org/mariadb/repositories/#distro=Debian&distro_release=stretch–stretch&mirror=coreix&version=10.4
输入如下命令配置root密码:
mysql_secure_installation
配置WordPress数据库
mysql -uroot -hlocalhost -ppassword
创建一个数据库用户:
CREATE USER 'wordpress'@'localhost' IDENTIFIED BY 'password';
创建一个数据库
create database wordpress default charset utf8 collate utf8_general_ci;
授予权限
grant all privileges on wordpress.* to 'wordpress'@'localhost' identified by 'password';
刷新权限
flush privileges;
Nginx
安装页
http://nginx.org/en/linux_packages.html#Debian
安装组件
sudo apt install curl gnupg2 ca-certificates lsb-release
设置存储库
echo "deb http://nginx.org/packages/mainline/debian `lsb_release -cs` nginx" \ | sudo tee /etc/apt/sources.list.d/nginx.list
导入签名密钥
curl -fsSL https://nginx.org/keys/nginx_signing.key | sudo apt-key add -
验证密钥
sudo apt-key fingerprint ABF5BD827BD9BF62
输出:
pub rsa2048 2011-08-19 [SC] [expires: 2024-06-14] 573B FD6B 3D8F BC64 1079 A6AB ABF5 BD82 7BD9 BF62 uid [ unknown] nginx signing key <signing-key@nginx.com>
安装Nginx
sudo apt update sudo apt install nginx
PHP
apt-get -y install apt-transport-https lsb-release ca-certificates curl wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list apt-get update
sudo apt install php7.4
安装完后会显示运行 Apache 服务失败,这是正常情况,因为我们先安装并运行了Nginx,Nginx占用了80端口,导致 Apache 服务运行失败。
安装必要包
apt install php7.4-fpm php7.4-cgi php7.4-curl php7.4-gd php7.4-xml php7.4-xmlrpc php7.4-mysql php7.4-bz2
检测
php -v
配置Nginx和PHP
nginx文件分析
# nginx运行的用户名 user nginx; # nginx启动进程,通常设置成和cpu的数量相等,这里为自动 worker_processes auto; # errorlog文件位置 error_log /var/log/nginx/error.log; # pid文件地址,记录了nginx的pid,方便进程管理 pid /run/nginx.pid; # Load dynamic modules. See /usr/share/nginx/README.dynamic. # 用来加载其他动态模块的配置 include /usr/share/nginx/modules/*.conf; # 工作模式和连接数上限 events { # 每个worker_processes的最大并发链接数 # 并发总数:worker_processes*worker_connections worker_connections 1024; } # 与提供http服务相关的一些配置参数类似的还有mail http { # 设置日志的格式 log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; # access_log记录访问的用户、页面、浏览器、ip和其他的访问信息 access_log /var/log/nginx/access.log main; # 这部分下面会单独解释 # 设置nginx是否使用sendfile函数输出文件 sendfile on; # 数据包最大时发包(使用Nagle算法) tcp_nopush on; # 立刻发送数据包(禁用Nagle算法) tcp_nodelay on; # 链接超时时间 keepalive_timeout 65; # 这个我也不清楚... types_hash_max_size 2048; # 引入文件扩展名与文件类型映射表 include /etc/nginx/mime.types; # 默认文件类型 default_type application/octet-stream; # Load modular configuration files from the /etc/nginx/conf.d directory. # See http://nginx.org/en/docs/ngx_core_module.html#include # for more information. include /etc/nginx/conf.d/*.conf; # http服务上支持若干虚拟主机。 # 每个虚拟主机一个对应的server配置项 # 配置项里面包含该虚拟主机相关的配置。 server { # 端口 listen 80 default_server; listen [::]:80 default_server; # 访问的域名 server_name _; # 默认网站根目录(www目录) root /usr/share/nginx/html; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; # 默认请求 location / { } # 错误页(404) error_page 404 /404.html; location = /40x.html { } # 错误页(50X) error_page 500 502 503 504 /50x.html; location = /50x.html { } } }
/etc/php/7.4/cgi/php.ini
设置:
cgi.fix_pathinfo=1
/etc/php/7.4/fpm/php.ini
设置
cgi.fix_pathinfo=0
/etc/nginx/nginx.conf
配置如下:
user www-data; # 到/etc/php/7.4/fpm/pool.d/www.conf文件可以找到 worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; gzip on; include /etc/nginx/conf.d/*.conf; }
cat /etc/nginx/conf.d/default.conf
server { listen 80; server_name localhost; root /var/www/wordpress; #charset koi8-r; access_log /var/log/nginx/host.access.log main; location / { #root /usr/share/nginx/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 /usr/share/nginx/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 unix:/run/php/php7.4-fpm.sock; fastcgi_index index.php; #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # location ~ /\.ht { deny all; } }
别说我的博文是文字不够代码来凑,那还不是怕有的同学看不过来,直接贴代码好复制啊。在这里插入代码片
# WordPress
下载WordPress
wget https://wordpress.org/latest.tar.gz
解压安装后修改:
cp wp-config-sample.php wp-config.php
然后编辑wp-config.php文件
在相应地方写入数据库,数据库用户名以及密码。
/** The name of the database for WordPress */ define( 'DB_NAME', 'wordpress' ); /** MySQL database username */ define( 'DB_USER', 'wordpress' ); /** MySQL database password */ define( 'DB_PASSWORD', 'wp^2020.' ); /** 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', '' );
然后到浏览器输入IP,设置好用户名密码邮箱,接下来就可以愉快地造作了。
有不懂的地方欢迎留言。
这个就是很棒