建站小记

发布于 2024-07-24  266 次阅读


1. 购买云服务器+域名

安装镜像ALinux3,基于Centos

远程连接

2. 搭建LNMP

LNMP : Linux+Nginx+ Mysql + php

安装Nginx

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

卸载系统自带的mysql并重新安装mysql

rpm -qa | grep mariadb
yum -y remove mari*
rm -rf /var/lib/mysql/*
rpm -qa | grep mariadb
yum remove mysql-community-serve
yum remove mysql-*
find / -name mysql
mysql
cd /usr/local
wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
rpm -ivh mysql57-community-release-el7-8.noarch.rpm
yum -y install mysql-server

配置mysql

mysql
mysql -uroot -p
 set password for root@localhost = password('my_password');
 flush privileges;
 create database wordpress;

安装php

yum install php

修改nginx配置

vim /etc/nginx/nginx.conf
    server {
        listen 80;
        server_name mak4r1.com;
        client_max_body_size 100M;
        access_log  /var/log/nginx/mak4r1.com.log main;  

        root /var/www/html; # 网站根目录
        index index.php index.html index.htm;

        location / {
            try_files $uri $uri/ /index.php?$query_string;  
        }

        location ~ \.php$ {
            include fastcgi_params;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_index index.php;
        }

        location ~ /\.ht {
            deny all;
        }
    }
nginx -t
service php-fpm start
service nginx restart
nginx -T

3. 安装wordpress

cd /root/
wget https://cn.wordpress.org/latest-zh_CN.zip
unzip latest-zh_CN.zip -d /var/www/html

修改Nginx根目录

vim /etc/nginx/nginx.conf
"root /var/www/html/wordpress;"

修改权限

cd /var/www/html && chmod -R 777 wordpress/

创建wp-config.php

访问网站后台,设置密码等

vim /var/www/html/wordpress/wp-config.php
//写入wordpress给的配置信息

4. 安装主题和插件

安装主题:Sakurairo https://github.com/mirai-mamori/Sakurairo/releases

然后进行一些个性化设置,这里目录等很多功能这个主题都集成好了,很方便

安装插件:

Code Snippets可以直接在网站后台写代码段到functions.php

Simple Local Avatars可以直接使用本地的个人头像

Jetpack-WordPress 用于站点安全防护和加速

5. 目前运维遇到的问题及解决方案

service nginx restart遇到报错

nginx: [error] open() "/var/run/nginx.pid" failed (2: No such file or directory)

同时命令nginx报错为:

Jul 24 23:57:28 iZbp1eton5ieebs96nzpjwZ systemd[1]: Starting nginx - high performance web server...
Jul 24 23:57:28 iZbp1eton5ieebs96nzpjwZ nginx[1231]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

原因是上次未正常关闭(服务器宕机),导致httpd占用80端口

解决方法:

netstat -tulnp | grep nginx
//如果有多于一个进程,则kill -9 [pid]全部杀死后重启nginx即可
//如果只有一个systemd的进程,则执行:
systemctl stop httpd
//然后重启nginx即可

A web ctfer from 0RAYS
最后更新于 2024-08-26