Linux部署Nginx+Php环境
1、先创建nginx安装目录:
[root@CENTOS7-128 / ]# mkdir -p /usr/local/nginx
2、下载二进制源码包及依赖库:
[root@CENTOS7-128 / ]# cd /usr/local/src/nginx
[root@CENTOS7-128 nginx ]# wget http://tengine.taobao.org/download/tengine-2.2.0.tar.gz
[root@CENTOS7-128 nginx ]# wget https://sourceforge.net/projects/pcre/files/pcre/8.40/pcre-8.40.tar.gz
[root@CENTOS7-128 nginx ]# wget http://zlib.net/zlib-1.2.11.tar.gz or http://prdownloads.sourceforge.net/libpng/zlib-1.2.11.tar.gz
[root@CENTOS7-128 nginx ]# wget http://artfiles.org/openssl.org/source/openssl-1.1.0e.tar.gz
3、解压下载的源码包:
[root@CENTOS7-128 nginx ]# tar xvf tengine-2.2.0.tar.gz
[root@CENTOS7-128 nginx ]# tar xvf pcre-8.40.tar.gz
[root@CENTOS7-128 nginx ]# tar xvf zlib-1.2.11.tar.gz
[root@CENTOS7-128 nginx ]# tar xvf openssl-1.1.0e.tar.gz
4、安装:先configure再make编译
[root@CENTOS7-128 nginx ]# cd tengine-2.2.0
[root@CENTOS7-128 tengine-2.2.0 ]#./configure --prefix=/data/nginx --with-openssl=/usr/local/src/nginx/openssl-1.1.0e/ --with-zlib=/usr/local/src/nginx/zlib-1.2.11 --with-pcre=/usr/local/src/nginx/pcre-8.40
[root@CENTOS7-128 tengine-2.2.0 ]# make && make install
5、截止以上安装活动,不会报任何错误
6、进入nginx安装目录启动服务:
[root@CENTOS7-128 /]# cd /data/nginx/sbin/
[root@CENTOS7-128 sbin]# ./nginx
7、进入nginx/conf配置目录修改nginx.conf
[root@CENTOS7-128 conf]# vi nginx.conf
[root@CENTOS7-128 conf]# cd ../sbin/
[root@CENTOS7-128 sbin]# ./nginx -t
the configuration file /data/nginx/conf/nginx.conf syntax is ok
configuration file /data/nginx/conf/nginx.conf test is successful
[root@CENTOS7-128 sbin]# ./nginx -s reload
8、修改访问域名,不适用ip,默认端口:
server {
listen 80;
server_name 101.116.115.128;
server_name www.fullysss.com;
# tips:修改完成,本地hosts映射域名:101.116.115.128 www.fullysss.com
9、安装php:
# 安装所需要的依赖库:yum install -y gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libpng libpng-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses curl openssl-devel gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel readline-devel libxslt-devel expat-devel xmlrpc-c xmlrpc-c-devel file
# 下载php安装:
[root@CENTOS7-128 / ]# cd opt
[root@CENTOS7-128 opt ]# rz 把下载的php-7.1.5.tar.g包放在这个目录并解压“
[root@CENTOS7-128 opt ]# tar -zxvf php-7.1.5.tar.gz
[root@CENTOS7-128 opt ]# cd php-7.1.5
[root@CENTOS7-128 php-7.1.5 ]# ./configure --prefix=/data/php --with-mysql --with-mysql-sock --with-mysqli --enable-fpm --enable-soap --with-libxml-dir --with-openssl --with-mcrypt --with-mhash --with-pcre-regex --with-sqlite3 --with-zlib --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --with-cdb --enable-dom --enable-exif --enable-fileinfo --enable-filter --with-pcre-dir --enable-ftp --with-gd --with-openssl-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --enable-gd-native-ttf --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash --enable-json --enable-mbstring --disable-mbregex --disable-mbregex-backtrack --with-libmbfl --with-onig --enable-pdo --with-pdo-mysql --with-zlib-dir --with-pdo-sqlite --with-readline --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-libxml-dir --with-xsl --enable-zip --enable-mysqlnd-compression-support --with-pear --disable-fileinfo
[root@CENTOS7-128 php-7.1.5 ]# make && make install
[root@CENTOS7-128 php-7.1.5 ]# make test
[root@CENTOS7-128 php-7.1.5 ]# cd /data/php
[root@CENTOS7-128 php ]# cp /data/php/etc/php-fpm.conf.default /data/php/etc/php-fpm.conf
[root@CENTOS7-128 php ]# cp /opt/php-7.1.5/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@CENTOS7-128 php ]# cp /opt/php-7.1.5/php.ini-production /data/php/lib/php.ini
[root@CENTOS7-128 php ]# vim /data/php/etc/php-fpm.conf #并没有修改什么
[root@CENTOS7-128 php ]# cd /data/php/etc/php-fpm.d
[root@CENTOS7-128 php-fpm ]# cp www.conf.default www.conf
[root@CENTOS7-128 php-fpm.d]# vi www.conf
[root@CENTOS7-128 php ]# chmod a+x /etc/init.d/php-fpm
[root@CENTOS7-128 php ]# chkconfig php-fpm on #设置php开机自启
[root@CENTOS7-128 php ]# chmod +x /etc/profile
[root@CENTOS7-128 php ]# vim /etc/profile.d/php.sh
PATH=$PATH:/data/php/bin
export PATH
:x 退出保存
[root@CENTOS7-128 php ]# chmod +x /etc/profile.d/php.sh
[root@CENTOS7-128 php ]# source /etc/profile
[root@CENTOS7-128 php ]# ln -s /data/php/sbin/php /bin/php
# 公钥生成:
[root@CENTOS7-128 /]# cd ~/.ssh/
[root@CENTOS7-128 .ssh ]# ssh-keygen -t rsa
[root@CENTOS7-128 .ssh ]# cat id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDfpDfhJI+6RQfy2xsyDIk3xMcgOKsHa1dZEhmw1xch7b6qeEP3ZnC5Vovg3qAb41JHeXJ04+tUc/Fv1js1v2kcc7t/HVj7zOhiGyET353xJKirmpXRjHlz8Gppdf4NjpVweD5JXIuBmWZBQx/H67K9rYZos9aYvyvT6Hw8DR6wu1rGOTPjnW2f3W2rNV1zmkwWK8yFSORe8ucjFfvAYDiQlDfmTbcuGBHk3k82VFBTH5g8JdQ6UVXO3FBvK9zY4b6H/58e1YZi2/WrLSRuw1rmJiucIbIbYSivttdBVSJwVlC0l73iSKUoMafirptqD+LX2Xw1j5zn7UuslcA6+yL9 root@CENTOS7-128
10、安装git命令:
[root@CENTOS7-128 / ]# yum install git
# 安装中国镜像composer:
[root@CENTOS7-128 / ]#cd opt
[root@CENTOS7-128 opt ]# wget https://getcomposer.org/download/1.4.2/composer.phar
[root@CENTOS7-128 opt ]# mv composer.phar /usr/local/bin/composer
# 上面两个步骤要么缓慢要么错误: 卸载命令: yum -y remove composer
[root@CENTOS7-128 opt ]# yum install composer
[root@CENTOS7-128 opt ]# composer -V
# composer 从网址下载composer.phar 直接使用, 移动到
[root@CENTOS7-128 opt ]# mv composer.phar /user/local/bin/composer
[root@CENTOS7-128 opt ]# chown +x test:test /user/local/bin/composer
# 执行以下命令时,需要切换到普通用户:useradd test,passwd test设置用户名密码命令。
[test@CENTOS7-128 opt ]# composer config -g repo.packagist composer https://packagist.phpcomposer.com
[test@CENTOS7-128 opt ]# composer install
11、php服务重启命令:
[root@CENTOS7-128 / ]# /bin/systemctl restart php-fpm.service && service php-fpm restart
12、nginx修改配置文件后,需要-t 测试及 -s reload 重载生效。
[root@CENTOS7-128 nginx]# vi conf/nginx.conf
[root@CENTOS7-128 nginx]# ./sbin/nginx -t
the configuration file /data/nginx/conf/nginx.conf syntax is ok
configuration file /data/nginx/conf/nginx.conf test is successful
[root@CENTOS7-128 nginx]# ./sbin/nginx -s reload
13、查看php服务:ps -ef |grep php ps -ef | grep nginx
redis下载路径:http://download.redis.io/redis-stable.tar.gz
PHP的配置文件为:/usr/local/lib/php.ini
php-fpm的配置文件为:/usr/local/etc/php-fpm.conf
php-fpm的错误日志为:/usr/local/var/log/php-fpm.log
php-fpm.conf文件的在线说明文档:http://php.net/manual/en/install.fpm.configuration.php