linux系统版本:CentOS Linux release 7.7.1908 (Core)
搭建环境的根目录:/usr/local/webserver
下载软件存放目录:/usr/local/src
cd /usr/local/src
tar zxvf nginx-1.16.1.tar.gz
cd nginx-1.16.1
./configure --prefix=/usr/local/webserver/nginx \--with-http_ssl_module \--with-pcre=/usr/local/src/pcre-8.43 \--with-zlib=/usr/local/src/zlib-1.2.11 \--with-openssl=/usr/local/src/openssl-1.1.1d
/usr/local/webserver/nginx/sbin/nginx
测试nginx是否启动成功:curl 127.0.0.1
出现类似以下截图的提示,说明到这边nginx就安装成功了
nginx 报错解决
问题1:./configure: error: C compiler cc is not found
解决安装gcc-c++包 :yum -y install gcc-c++
yum install -y libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libXpm libXpm-devel openldap openldap-devel libmcrypt libmcrypt-devel gd gd-devel
tar zxvf php-7.3.14.tar.gz
cd php-7.3.14
./configure --prefix=/usr/local/webserver/php7.3 --with-config-file-scan-dir=/opt/php/etc/php.d --disable-debug --with-pic --disable-rpath --with-bz2 --without-gdbm --with-gettext --with-gmp --enable-mbregex --enable-mbstring --with-iconv --with-openssl=/usr --with-zlib --with-layout=GNU --enable-exif --enable-ftp --enable-sockets --enable-sysvsem --enable-sysvshm --enable-sysvmsg --enable-shmop --enable-calendar --enable-xml --with-pear --enable-fpm --with-pdo-mysql --with-curl --with-ldap --with-gd --with-freetype-dir --with-mysqli --enable-soap --enable-bcmath --with-jpeg-dir=/usr --with-xpm-dir=/usr --with-libdir=lib64 --with-fpm-user=www --with-fpm-group=www
make && make install
安装完成 出现以下提示
php配置:
cd /usr/local/webserver/php7.3/etc/
cp php-fpm.conf.default php-fpm.conf
groupadd www
useradd -g www www
mkdir -p /data/webroot/test
vim php-fpm.conf文件增加两行:
user = www
group = www
pid = run/php-fpm.pid
vim /data/webroot/test/phpinfo.php增加以下
echo phpversion();
测试:
/usr/local/webserver/php7.3/bin/php /data/webroot/test/phpinfo.php
mkdir /usr/local/webserver/nginx/conf/vhost/
vim /usr/local/webserver/nginx/conf/nginx.conf
worker_processes 1;
error_log /usr/local/webserver/nginx/logs/error.log crit;
pid /usr/local/webserver/nginx/logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
include /usr/local/webserver/nginx/conf/vhost/*;
}
vim /usr/local/webserver/nginx/conf/vhost/test
server
{
listen 80;
server_name www.testphp7.com;
index index.html index.htm index.php;
root /data/webroot/www.testphp7.com;
location / {
if (!-e $request_filename){
rewrite ^/(.*)$ /index.php/$1 last;
}
}
location ~ \.php$ {
fastcgi_pass unix:/tmp/php-cgi7.3.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
vim /usr/local/webserver/php7.3/etc/php-fpm.conf
[global]
pid = /usr/local/webserver/php7.3/var/run/php-fpm.pid
error_log = /usr/local/webserver/php7.3/var/log/php7.3_error.log
log_level = notice
[www]
listen = /tmp/php-cgi7.3.sock
listen.backlog = -1
listen.allowed_clients = 127.0.0.1
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 20
pm.max_spare_servers = 50
request_slowlog_timeout = 0
slowlog = /data/logs/error/php_slow7.3.log
启动:
/usr/local/webserver/nginx/sbin/nginx
/usr/local/webserver/php7.3/sbin/php-fpm
测试访问域名是否正常
curl www.testphp7.com
mac电脑 访问虚拟机里面的环境
第一步、需要在虚拟机的 centos7里面关闭防火墙
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
ip addr 查看虚拟机的IP地址
第二步、在mac系统
/etc/hosts 文件里面解析虚拟机的IP地址 和刚才配置的域名
第三步、即可在浏览器上面访问了
----------------------------------------------------------------------------------------------------------------------------------------
有时候官网包下载比较慢,我有从官网下载 并打包成一份完整的资源在csdn中,
下载地址:https://download.csdn.net/download/cai6595470/12131637
如果没有csdn积分的朋友可以自行去官网下载。
php-7.3.14官网下载地址:https://www.php.net/downloads.php
nginx-1.16.1官网下载地址:http://nginx.org/en/download.html
openssl-1.1.1d官网下载地址: https://www.openssl.org/source/
pcre-8.34官网下载地址https://sourceforge.net/projects/pcre/files/pcre/8.43/pcre-8.43.tar.gz/download
zlib-1.2.11官网下载地址https://sourceforge.net/projects/libpng/files/zlib/1.2.11/zlib-1.2.11.tar.gz/download