系统版本:centos7 64位

PHP版本:PHP 7.0.21

Nginx版本:1.8.1

MySQL版本:5.5.17

注:1.所有安装都必须放在 /usr/local/src文件夹下

 2.添加PHP临时环境变量方法

export PATH=$PATH:/usr/local/php/bin/

此环境变量只可以在当前窗口有效,关闭或者其它窗口都将失效

第一步:准备工作

1.关闭防火墙

systemctl stop firewalld.service

service iptables stop

2.安装环境需要的依赖:

yum -y install gcc automake autoconf libtool make gcc-c++ glibc libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5-devel libidn libidn-devel openssl openssl-devel pcre pcre-devel libmcrypt libmcrypt-devel cmake

 

.安装nginx

第一步:下载nginx到指定目录

nginx版本: wget http://nginx.org/download/nginx-1.8.1.tar.gz /usr/local/src

第二步:解压安装:

cd /usr/local/src

tar xf nginx-1.8.1.tar.gz

cd nginx-1.8.1

创建用户www和用户组www

groupadd www

useradd -g www www

./configure –prefix=/usr/local/nginx –sbin-path=/usr/sbin/nginx –user=www –group=www –with-http_ssl_module –with-http_gzip_static_module

 

make && make install

 

 

nginx安装成功,启动报以下错误表示端口被占用,使用lsof -i:80查看谁占用了80端口并用kill -9 进程号杀死

 

 

启动nginx

/usr/local/nginx/sbin/nginx

三.安装php

第一步:下载php

php版本:php-7.0.21.tar.gz

第二步:解压安装:

tar -zxvf php-7.0.21.tar.gz

cd php-7.0.21/

./configure –prefix=/usr/local/php –with-curl –with-bz2 –with-zlib –with-mhash –with-pcre-regex –with-mysqli=mysqlnd –with-mysql=mysqlnd –with-gd –with-jpeg-dir –with-png-dir –with-openssl –with-pdo-mysql –with-libxml-dir –with-freetype-dir –with-iconv –enable-opcache –enable-bcmath –enable-ftp –enable-shmop –enable-fpm –enable-sockets –enable-sysvsem –enable-sysvshm –enable-pcntl –enable-mbregex –enable-calendar –enable-zip –enable-mbstring –enable-pdo

make && make install

 

出现图片内容表示PHP安装成功!

// 配置php-fpm

cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

//修改php-fpm.conf

vim /usr/local/php/etc/php-fpm.conf

;pid = run/php-fpm.pid 前面的分号删掉

 

 

cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf

cp /usr/local/src/php-7.0.21/php.ini-production /usr/local/php/lib/php.ini

//拷贝php-fpm脚本至/etc/init.d目录

cp /usr/local/src/php-7.0.21/sapi/fpm/init.d.php-fpm  /etc/init.d/php-fpm

//设置权限并启动php-fpm

chmod 755 /etc/init.d/php-fpm

/etc/init.d/php-fpm start

 

// php-fpm以服务的方式启动、停止和重启:

service php-fpm start

service php-fpm stop

service php-fpm reload

 

四.配置nginx支持php

 

 

location ~ \.php$ {

root html;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

}

重启nginx /usr/sbin/nginx -s reload

启动nginx /usr/sbin/nginx

停止nginx /usr/sbin/nginx -s stop

版权声明:本文为caiji原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/caiji/p/7424400.html