所需环境
- centos7
- VMware-workstation-full-14.1
- PHP 7.3.12
- nginx-1.16
- mysql-5.7.28
百度网盘:https://pan.baidu.com/s/1pJPbbwx31BXL1h9vYgFq3g
提取码:8a9q
虚拟机安装步骤
1、安装好VMware虚拟机,然后使用压缩包内对应的激活码激活程序。
2、安装Centos 7 操作系统
-
第一步:导入contos 7 操作盘
-
第二步:选择对应系统盘
-
第三步:选择虚拟机系统存放位置
-
第四步:选择虚拟机磁盘容量大小
-
第五步:选择虚拟机硬件相关配置(按原有即可)
-
第六步:完成导入配置,等待安装
-
第七步:选择系统语言,同步时区,设置root账户密码与初始账号(可不设置,如有需要后期再加)
-
第八步:安装完成,启动登录系统
-
第九步:修改虚拟机网关地址
- 选择 VMnet8,点击下方NAT设置查看对应网关,记住前三个网段,后面要用。
-
第十步:进入contos虚拟机中,输入命令
vi /etc/sysconfig/network-scripts/ifcfg-ens33
,添加修改为
ONBOOT=“yes”
ZONE=“public”
IPATTR=192.168.152.128
GATEWAY=192.168.152.2
NETWASK=255.255.255.0
注意:ipattr和netwask前三个网段应与上一步查看到的网关的前三个网段一致
- 第十一步:重启虚拟机网卡
systemctl restart network
,输入命令ip addr
查看具体信息 - 第十二步:使用xshell测试连接
相关环境安装
- 第一步:安装宝塔面板
yum install -y wget && wget -O install.sh http://download.bt.cn/install/install_6.0.sh && sh install.sh
注意:如果根目录下没有www目录,需要创建,新版宝塔已可以自动创建 - 第二步:编译安装PHP
- 1.安装php相关依赖
yum -y install libxml2
yum -y install libxml2-devel
yum -y install openssl
yum -y install openssl-devel
yum -y install curl
yum -y install curl-devel
yum -y install libjpeg
yum -y install libjpeg-devel
yum -y install libpng
yum -y install libpng-devel
yum -y install freetype
yum -y install freetype-devel
yum -y install pcre
yum -y install pcre-devel
yum -y install libxslt
yum -y install libxslt-devel
yum -y install bzip2
yum -y install bzip2-devel
- 第二步:解压PHP压缩包
tar -zxvf php-7.3.12.tar.gz
,进入文件夹,输入编译命令
./configure --prefix=/usr/local/php --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-bz2 --with-mhash --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-zip
发面有报错configure: error: Please reinstall the libzip distribution
,重新下载libzip。
- 先卸载原有的liBzip,命令
yum remove libzip
- 解压准备好的libzip的压缩包,
tar -zxvf libzip-1.2.0.tar.gz
- 进行编译安装,
cd libzip-1.2.0
–./configure
—make -j4 && make install
- 再重新进入PHP文件夹执行PHP编译命令
- 此时后提示
configure: error: off_t undefined; check your library configuration
- 编辑文件so.conf,
vi /etc/ld.so.conf
退出编辑后,执行命令#添加如下几行 /usr/local/lib64 /usr/local/lib /usr/lib /usr/lib64
ldconfig -v
,使之前修改生效 - 再重新进入PHP文件夹执行PHP编译命令,同4。此时后发现没有其他错误了。【注:先看这个再往下走,先执行第10条,再执行第9条,避免浪费时间】
- 执行
make & make install
,等待编辑,【注,此时花费时间巨长,可以去吃个饭了】 - 但是执行后发现有报错
/usr/local/include/zip.h:59:21: 致命错误:zipconf.h:没有那个文件或目录
- 此时找到zipconf.h文件,
find / -name zipconf.h
,然后再执行复制命令cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h
- 安装完成后,再执行代码
cp php.ini-development /usr/local/php/lib/php.ini
,复制php.ini文件,cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
复制php-fpm.conf配置文件 - 创建php-fpm的软连接
ln -s /usr/local/php/sbin/php-fpm /usr/local/bin
- 添加组
groupadd www
,添加用户useradd -g www www
- 复制php-fpm.d下的域名配置文件
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
- 修改该配置文件,
vi /usr/local/php/etc/php-fpm.d/www.conf
- 修改php.ini文件
vi /usr/local/php/lib/php.ini
- 运行php-fpm
/usr/local/bin/php-fpm
,查看对应网络链接netstat -tln | grep 9000
,查看进程ps -aux | grep php
,若无netstat,则进行安装yum install net-tools
- 修改环境变量,
vi /etc/profile
,添加内容export PATH="$PATH:/usr/local/php/bin"
,完成后退出,重载环境变量source /etc/profile
- 所有完成。
- 配置php-fpm服务到systemctl,打开php-fpm.conf
vi /usr/local/php/etc/php-fpm.conf
,找到并修改pid = /var/run/php-fpm.pid
,完成后退出,再创建php-fpm服务文件touch /usr/lib/systemd/system/php-fpm.service
,然后添加内容:
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=forking
PIDFile=/var/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm
ExecReload=/bin/kill -USR2 $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
完成编辑后退出文件,最后重载systemctl daemon-reload
。
相关操作
1、systemctl start php-fpm #启动服务
2、systemctl status php-fpm #查看状态
3、systemctl stop php-fpm #停止服务
4、systemctl restart php-fpm #重启服务
5、systemctl reload php-fpm #修改配置文件后重载
6、systemctl enable php-fpm #设置开机自启
7、systemctl didable php-fpm #禁止开机自启
- 第三步:编译安装Nginx
- 运行yum安装所需扩展
yum install gcc-c++
,yum install -y pcre pcre-devel
,yum install -y zlib zlib-devel
- 解压nginx压缩包,
tar -zxvf nginx-1.16.0
,完成后进入文件夹 - 执行编译命令
./configure
,完成后执行make & make install
- 添加环境变量,编辑profile,
vi /etc/profile
,添加export PATH="$PATH:/usr/local/php/bin:/usr/local/nginx/sbin/"
,保存退出,重载环境变量source /etc/profile
- 配置systemctl:
1.创建nginx服务文件touch /usr/lib/systemd/system/nginx.service,然后添加内容:
- 运行yum安装所需扩展
[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
完成编辑后退出文件,最后重载systemctl daemon-reload
。
相关操作
#启动nginx服务
systemctl start nginx.service
#停止nginx服务
systemctl stop nginx.service
#重启nginx服务
systemctl restart nginx.service
#重新读取nginx配置(这个最常用, 不用停止nginx服务就能使修改的配置生效)
systemctl reload nginx.service
- 第四步:配置nginx
- 修改nginx配置文件,访问当前虚拟机域名以测试是否连通。