一、准备工作
1、查看Linux版本信息
[root@localhost /]# cat etc/redhat-release
2、查看是否安装wget
[root@localhost /]# rpm -qa wget
2.1、安装wget
[root@localhost /]# yum -y install wget
3、查看是否安装gcc编译器
[root@localhost /]# rpm -qa gcc
3.1、安装gcc
[root@localhost /]
二、安装Nginx
1、下载Nginx
[root@localhost wangshuang]# wget https:
2、解压压缩包
[root@localhost wangshuang]# tar -zxvf nginx-1.20.1.tar.gz
3、configure指定安装参数及目录
| # configure是一个shell脚本,根据平台的特性生成Makefile文件用于后面的编译及安装 |
| [root@localhost nginx-1.20.1]# ./configure --prefix=/usr/local/nginx |
4、make && make install 命令执行编译与安装
| # make是用来编译的,它从Makefile中读取指令,然后编译;make install是用来安装的,它也是从Makefile文件中读取指令 |
| [root@localhost nginx-1.20.1]# make && make install |
5、启动nginx
| # 在安装目录`/usr/local/nginx/sbin/`目录下有一个输入命令 |
| [root@localhost sbin]# ./nginx |
| |
| # 启动后查看进程 |
| [root@localhost sbin]# ps aux|grep nginx |
6、关闭nginx
[root@localhost sbin]# ./nginx -s stop
7、查看防护墙状态
[root@localhost /]# systemctl status firewalld
8、关闭防火墙
[root@localhost /]# systemctl stop firewalld
9、查看防火墙服务是否开机启动
[root@localhost /]# systemctl is-enabled firewalld
10、关闭防火墙开机启动
systemctl disable firewalld
11、查看当前SELinux状态
[root@localhost /]# getenforce
12、关闭SELinux
[root@localhost /]# vim /etc/selinux/config
三、安装Mysql
1、查看是否已安装MySQL
[root@localhost /]# rpm -qa | grep mysql
2、下载MySQL安装包
[root@localhost wangshuang]# wget https:
3、解压.tar.xz文件
| # 分两步解压方式 |
| [root@localhost wangshuang]# xz -d mysql-8.0.24-linux-glibc2.12-x86_64.tar.xz |
| [root@localhost wangshuang]# tar -xvf mysql-8.0.24-linux-glibc2.12-x86_64.tar |
| |
| # 直接解压方式 |
| [root@localhost wangshuang]# tar -xvJf mysql-8.0.24-linux-glibc2.12-x86_64.tar.xz |
| |
| # 移动至安装目录并重命名为mysql |
| [root@localhost wangshuang]# mv mysql-8.0.24-linux-glibc2.12-x86_64/ /usr/local/mysql |
4、查看安装依赖
[root@localhost mysql]# rpm -q libaio
5、为mysql新建用户
| # 用户名`mysql` |
| [root@localhost mysql]# useradd -s /sbin/nologin -M mysql |
6、初始化数据库
==注意:初始化后的密码一定要记着==
[root@localhost mysql]# bin/mysqld --initialize --user=mysql
7、复制启动脚本
[root@localhost mysql]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
8、修改配置文件
| |
| [root@localhost etc] |
| |
| |
| [root@localhost etc] |
| |
| |
| [mysqld] |
| basedir=/usr/local/mysql |
| datadir=/var/lib/mysql |
| socket=/var/lib/mysql/mysql.sock |
| character-set-server=utf8 |
| [client] |
| socket=/var/lib/mysql/mysql.sock |
| default-character-set=utf8 |
9、开启数据库
[root@localhost bin]# service mysqld start
10、测试连接数据库
| # 密码为初始化时生成的随机密码 |
| [root@localhost bin]# ./mysql -u root -p |
| |
| # 连接成功以后修改密码 |
| mysql> alter user 'root'@'localhost' identified by '123456'; |
四、编译安装PHP
1、选择下载PHP安装包
https://www.php.net/downloads.php
2、将安装包上传至服务器并解压缩
[root@localhost wangshuang]# tar -zxvf php-8.0.8.tar.gz
3、编译前先配置相关信息
| # 查看`./configure`命令帮助信息,了解可配置的信息! |
| [root@localhost php-8.0.8]# ./configure -h |
| |
| # 配置安装路径、多字节字符串支撑、fpm等 |
| [root@localhost php-8.0.8]# ./configure --prefix=/usr/local/php --enable-mbstring --enable-fpm |
| |
| # 若提示“No package '***' found”,则根据提示进行安装相关依赖包即可 |
| |
| [root@localhost php-8.0.8]# make && make install |
4、配置
| # 复制 php.ini 文件 |
| [root@localhost php-8.0.8]# cp php.ini-development /usr/local/php/lib/php.ini |
| |
| # 安装目录etc下复制php-fpm.conf.default并命名为php-fpm.conf |
| [root@localhost etc]# cp php-fpm.conf.default php-fpm.conf |
| |
| # 复制安装包sapi/fpm目录下的php-fpm至安装位置的bin目录下 |
| [root@localhost fpm]# cp php-fpm /usr/local/php/bin/ |
| |
| # 默认情况下etc/php-fpm.d/下有一个名为www.conf.defalut的配置用户的文件,执行下面命令复制一个新文件 |
| [root@localhost php-fpm.d]# cp www.conf.default www.conf |
5、启动php-fpm
| # 执行bin目录下的php-fpm |
| [root@localhost bin]# ./php-fpm |
| |
| # 查看进程 |
| [root@localhost bin]# ps -aux|grep php |
| |
| # 启动完毕之后,php-fpm服务默认使用9000端口,使用 netstat -tln | grep 9000 可以查看端口使用情况 |
| [root@localhost bin]# netstat -tln | grep 9000 |
6、配置nginx.conf文件
| |
| [root@localhost conf] |
| location / { |
| root html; |
| index index.html index.htm index.php; |
| } |
| |
| |
| location ~ \.php$ { |
| root html; |
| fastcgi_pass 127.0.0.1:9000; |
| fastcgi_index index.php; |
| |
| |
| include fastcgi.conf; |
| } |
| |
| |
| [root@localhost sbin] |
| |
| |
| [root@localhost sbin] |
| |
| |
| [root@localhost sbin] |
| |
| |
| [root@localhost sbin] |
7、测试
nginx 安装目录下有个html目录,目录下新建index.php文件,输出phpinfo();
浏览器访问:http://IP地址/index.php,成功输出PHP信息则表示成功