- 安装Nginx
#1.下载rpm包
wget https://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.20.2-1.el7.ngx.x86_64.rpm
#2.安装
rpm -ivh nginx-1.20.2-1.el7.ngx.x86_64.rpm
#3.启动
systemctl start nginx
#4.重启
systemctl restart nginx
#5.加入开机启动
systemctl enable nginx
#6.查找nginx的路径
find / -name nginx
编辑conf文件
/etc/nginx/nginx.conf 保持默认
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
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; #引入了自定义conf文件
}
/etc/nginx/conf.d/typecho.conf
在这个文件中不仅要使nginx能够与php联动,即
location ~ \.php$ {
# root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
还要注意的是由于Nginx对pathinfo
支持不够的问题,需要手动添加地址重写代码。
在站点配置文件对应本Typecho.conf文件的
server{
...
location / {
...
//这里添加
...
try_files $uri $uri/ =404;
...
}
}
添加如下代码:
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
然后重启Nginx:
nginx -t #检查conf文件是否符合语法规范
systemctl restart nginx
完整文件内容
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
#access_log /var/log/nginx/host.access.log main;
location / {
# modified begin
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
#index index.php index.html index.htm;
# index.php;
# modified end
}
#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
# modified begin
location ~ \.php$ {
# root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# modified end
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
- 安装php7.4
#1.添加第三方rpm源
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
#2.安装 这里是安装php相关的拓展模块,可以根据自己的需要进行增删,
#下面列出的模块,除了redis和swoole外,其他基本都是必须模块
yum install -y php74-php-fpm php74-php-cli php74-php-bcmath php74-php-gd php74-php-json php74-php-mbstring php74-php-mcrypt php74-php-mysqlnd php74-php-opcache php74-php-pdo php74-php-pecl-crypto php74-php-pecl-mcrypt php74-php-pecl-geoip php74-php-recode php74-php-snmp php74-php-soap php74-php-xml php74-php-imagick php74-php-pecl-zip php74-php-redis php74-php-swoole
#3.启动
systemctl start php74-php-fpm
#4.添加开机启动
systemctl enable php74-php-fpm
#5.查看版本
cp /usr/bin/php74 /usr/bin/php #如果不复制的话,所有的php 替换成php74
chmod +x /usr/bin/php #文件给与执行权限
php -v
#6.查看已安装模块
php -m
#7.查看配置信息(相当于phpinfo)
php -i
#8.编辑php-fpm的配置 一般来说php-fpm的配置文件都是www.conf,如果不知道文件路径,可以find以下
find / -name www.conf
#查找的结果
/etc/opt/remi/php74/php-fpm.d/www.conf
vim /etc/opt/remi/php74/php-fpm.d/www.conf
#查找到user 和 group 修改为 nginx (这里是nginx.conf中的user参数,不知道的话 在/etc/nginx/nginx.conf中找一下)
#也就是说php-fpm的用户和nginx的用户一致
#将listen_mode 取消注释,并将权限修改为0777
#然后保存,重启php-fpm
结果如下
; Per pool prefix
; It only applies on the following directives:
; - 'access.log'
; - 'slowlog'
; - 'listen' (unixsocket)
; - 'chroot'
; - 'chdir'
; - 'php_values'
; - 'php_admin_values'
; When not set, the global prefix (or @php_fpm_prefix@) applies instead.
; Note: This directive can also be relative to the global prefix.
; Default Value: none
;prefix = /path/to/pools/$pool
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
; RPM: apache user chosen to provide access to the same directories as httpd
user = nginx
; RPM: Keep a group allowed to write in log dir.
group = nginx
; The address on which to accept FastCGI requests.
; Valid syntaxes are:
; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific IPv4 address on
; a specific port;
; '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on
; a specific port;
; 'port' - to listen on a TCP socket to all addresses
; (IPv6 and IPv4-mapped) on a specific port;
; '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = 127.0.0.1:9000
; Set listen(2) backlog.
; Default Value: 511
;listen.backlog = 511
; Set permissions for unix socket, if one is used. In Linux, read/write
; permissions must be set in order to allow connections from a web server.
; Default Values: user and group are set as the running user
; mode is set to 0660
;listen.owner = nobody
;listen.group = nobody
listen.mode = 0777
- 安装Mysql
# 查询是否安装了mariadb
mariadb rpm -aq | grep mariadb
# 删除mariadb。-e 删除指定的套件;--nodeps 不验证套件的相互关联性
rpm -e --nodeps mariadb-libs 12345
安装依赖
yum install perl -y
yum install net-tools -y
安装MySQL
wget http://dev.mysql.com/get/mysql-5.7.26-1.el7.x86_64.rpm-bundle.tar
# 解压缩
tar xvf mysql-5.7.26-1.el7.x86_64.rpm-bundle.tar
# 依次运行以下命令
rpm -ivh mysql-community-common-5.7.26-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.26-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.26-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.26-1.el7.x86_64.rpm
# 启动数据库
systemctl start mysqld
#查找root密码
grep password /var/log/mysqld.log
#修改 root 口令
# 进入MySQL,使用前面查询到的口令
mysql -u root -p
# 设置口令强度;将root口令设置为12345678;刷新
set global validate_password_policy=0;
set password for 'root'@'localhost' =password('12345678');
flush privileges;
注意:nginx 链接mysql 需要关闭SElinux 通常情况下载安装完CentOS7后,默认情况下SElinux是启用状态。 不关闭会报SQLSTATE[HY000] [2002] Permission denied 错误
- 上传Typecho文件
在/etc/nginx/conf.d/typecho.conf中第四行可以看到我们定义网站的根目录为/usr/share/nginx/html
所以我们将typecho文件上传到这个目录即可,注意要保证index.php就在目录html下,而不是html/typecho/index.php,也就是不要有中间级目录。
真假
真假