centos7使用LNMP搭建 Typecho
1. 安装环境
1.1 安装nginx并申请证书
yum update -y
yum install nginx -y
# 申请证书
sudo yum install -y epel-release
sudo yum install -y certbot certbot-nginx python3-certbot-nginx
sudo certbot --nginx -d xiaoyusay.com -d www.xiaoyusay.com #根据提示填写邮箱
1.2 安装mysql 这里安装MariaDB
yum install -y mariadb-server
sudo systemctl start mariadb
sudo systemctl enable mariadb
sudo mysql_secure_installation # 根据提示操作,默认密码是空
mysql -u root -p # 输入密码进入数据库
CREATE DATABASE typecho; # 创建数据库typecho
CREATE USER '替换typecho的用户名'@'localhost' IDENTIFIED BY '替换你的密码';
GRANT ALL PRIVILEGES ON typecho.* TO 'typecho的用户名'@'localhost';
FLUSH PRIVILEGES;
EXIT;
1.3 安装php7.2
yum localinstall https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum -y install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-fpm php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml
systemctl start php-fpm
php -v
2.下载typecho
mkdir -p /usr/share/nginx/typecho
cd /usr/share/nginx/typecho
wget https://github.com/typecho/typecho/releases/latest/download/typecho.zip
unzip typecho.zip
chmod -R 755 /usr/share/nginx/typecho
3. 配置nginx
3.1 编辑配置文件
nano /etc/nginx/conf.d/typecho.conf
# 将下文内容添加上
server {
listen 80;
server_name xiaoyusay.com www.xiaoyusay.com;
return 301 https://$host$request_uri; # 强制 HTTPS
}
server {
listen 443 ssl;
server_name xiaoyusay.com www.xiaoyusay.com;
ssl_certificate /etc/letsencrypt/live/www.xiaoyusay.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/www.xiaoyusay.com/privkey.pem;
index index.php;
root /usr/share/nginx/typecho;
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;
}
}
3.2 重启nginx
//验证配置的正确性
nginx -t
//重启nginx
sudo systemctl restart nginx.service
4. 开启80,443 端口
sudo firewall-cmd --zone=public --permanent --add-service=http
sudo firewall-cmd --zone=public --permanent --add-service=https
sudo firewall-cmd --reload
5. 访问域名或者ip
根据提示填写数据库相关的信息即可
评论区