安装Nginx服务器
-
下载Nginx源码 官网 这里安装的是1.18版本
wget -c http://nginx.org/download/nginx-1.18.0.tar.gz
-
解压
tar -zxvf nginx-1.18.0.tar.gz # 进入目录 cd nginx-1.18.0/
-
配置
# 第一种使用默认配置 ./configure # 第二种自定义配置 ./configure --prefix=/usr/local/nginx \--conf-path=/usr/local/nginx/conf/nginx.conf \--pid-path=/usr/local/nginx/conf/nginx.pid \--lock-path=/var/lock/nginx.lock \--error-log-path=/var/log/nginx/error.log \--http-log-path=/var/log/nginx/access.log \--with-http_gzip_static_module \--http-client-body-temp-path=/var/temp/nginx/client \--http-proxy-temp-path=/var/temp/nginx/proxy \--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \--http-scgi-temp-path=/var/temp/nginx/scgi
报错:checking for C compiler … not found
解决办法:
yum -y install gcc yum -y install gcc-c++ yum -y install make
报错: ./configure: error: the HTTP gzip module requires the zlib library.
解决办法:yum install -y zlib-devel
报错:./configure: error: the HTTP gzip module requires the PERE library.
解决办法:yum -y install pere-devel
再次执行 ./configure
执行成功后如下图:
-
编译安装
make make install
查看Nginx 安装路径
whereis nginx # nginx: /usr/local/nginx
-
启动、停止Nginx
cd /usr/local/nginx/sbin/ ./nginx # 启动 ./nginx -s stop # 停止 ./nginx -s quit # 退出 ./nginx -s reload # 重载
-
测试
输入服务器ip
证明安装成功!
设置开机启动
vi /etc/rc.local
# 增加一行 /usr/local/nginx/sbin/nginx
# 设置执行权限:
chmod 755 rc.local
安装php(php7.4)
- 下载php源码 官网
- 解压
tar -zxvf php-7.4.12.tar.gz cd php-7.1.12
- 配置 安装
./configure --prefix=/usr/local/php7 --with-curl --with-freetype --enable-gd --with-jpeg --with-gettext --with-iconv-dir=/usr/local --with-kerberos --with-libdir=lib64 --with-libxml --with-mysqli --with-openssl --with-pdo-mysql --with-pdo-sqlite --with-pear --enable-sockets --with-mhash --with-ldap-sasl --with-xmlrpc --with-xsl --with-zlib --enable-fpm --enable-bcmath --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --with-zip --with-config-file-path=/usr/local/php7/etc -with-bz2 --enable-inline-optimization --enable-sysvsem make make install ``` ls ```shell # 报错:Package 'libxml-2.0', required by 'virtual:world', not found yum install libxml2-devel # 报错:Package 'krb5', required by 'virtual:world', not found yum install -y krb5-devel # 报错:Package 'openssl', required by 'virtual:world', not found yum install -y openssl-devel # Package 'sqlite3', required by 'virtual:world', not found yum install -y sqlite-devel # Package 'libcurl', required by 'virtual:world', not found yum install -y libcurl-devel # 报错:Package 'oniguruma', required by 'virtual:world', not found # https://www.cnblogs.com/architectforest/p/12433640.html
- 加入环境变量
vim ~/.bash_profile # 把 /usr/local/php7/bin 追加到PATH变量中 source ~/.bash_profile # 立即生效
- 配置Nginx使其支持php
vim /usr/local/nginx/conf/nginx.conf
location / {
root html;
index index.php index.html index.htm;
}
location ~* \.php$ {
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
- 重启Nginx
- 测试