查看: 161|回复: 0

[PHP实例] Centos 7 x86_64 Nginx + PHP 安装步骤

发表于 4 天前
尚学堂AD
Centos 7 Nginx + PHP 安装步骤

Centos 7 下的 PHP7/Nginx/Memcached 安装步骤。跟上一篇 Centos 7 Nginx + PHP 安装步骤 的区别是,这次是编译的64位的,所有的库均编译到 /usr/local/lib64 目录中,网上那些教程一般没有指定编译路径,实际上是错的,全部编译到默认路径是在
/usr/local/lib 下然后在软连接到 lib64 里简直是有病。另外 Centos 7.4 已经升级了openssl 库,故本篇不在单独安装新版的 Openssl 。特别说明,对于大批量部署的机器,在编译完成后,除了 yum 安装得部分,/usr/local 可以直接打包,在其他的Centos 同版本机器上直接运行,省去了编译的时间,云环境请直接克隆!

一、获取相关开源程序 1、安装环境所需的程序库
  1. yum -y update
  2. yum remove mariadb*
  3. yum -y install patch make cmake gcc gcc-c++ bison flex file libtool libtool-libs autoconf kernel-devel libjpeg libjpeg-devel libpng libpng-devel gd gd-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 libidn libidn-devel gmp-devel gettext gettext-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers vim-minimal nano gmp-devel unzip libcap diffutils readline-devel libxslt libxslt-devel ntp wget ctags libedit libedit-devel libaio git mailx jwhois bind-utils systemd systemd-devel libtidy libtidy-devel openssl openssl-devel
  4. yum -y install supervisor
  5. yum -y install memcached
复制代码
2、准备环境变量
  1. echo -e "/lib64\n/usr/lib64\n/usr/local/lib64\n/lib\n/usr/lib\n/usr/local/lib\n`cat /etc/ld.so.conf`" > /etc/ld.so.conf
  2. /sbin/ldconfig
复制代码
3、下载程序源码包
  1. cd /usr/local/src
  2. wget http://7xk96f.com1.z0.glb.clouddn.com/software/libiconv/libiconv-1.15.tar.gz
  3. wget -O php-7.1.10.tar.gz http://cn2.php.net/get/php-7.1.10.tar.gz/from/this/mirror
  4. wget http://7xk96f.com1.z0.glb.clouddn.com/software/mcrypt/libmcrypt-2.5.8.tar.gz
  5. wget http://7xk96f.com1.z0.glb.clouddn.com/software/mcrypt/mcrypt-2.6.8.tar.gz
  6. wget http://7xk96f.com1.z0.glb.clouddn.com/software/mhash/mhash-0.9.9.9.tar.gz
  7. wget http://7xk96f.com1.z0.glb.clouddn.com/software/icu/icu4c-58_2-src.tgz
  8. wget http://7xk96f.com1.z0.glb.clouddn.com/software/libmemcached/libmemcached-1.0.18.tar.gz
  9. wget http://7xk96f.com1.z0.glb.clouddn.com/software/pcre/pcre-8.41.tar.gz
  10. wget http://7xk96f.com1.z0.glb.clouddn.com/software/openssl/openssl-1.1.0e.tar.gz
  11. wget http://7xk96f.com1.z0.glb.clouddn.com/software/nginx/nginx-1.13.5.tar.gz
  12. wget http://pecl.php.net/get/msgpack-2.0.2.tgz
  13. wget http://pecl.php.net/get/igbinary-2.0.4.tgz
  14. wget http://pecl.php.net/get/memcached-3.0.3.tgz
  15. wget http://pecl.php.net/get/redis-3.1.4.tgz
  16. wget http://pecl.php.net/get/yaml-2.0.2.tgz
  17. wget http://pecl.php.net/get/mongodb-1.3.0.tgz
复制代码
二、安装PHP 7(FastCGI模式) 1、编译安装PHP 7 所需的支持库:
  1. tar zxf libiconv-1.15.tar.gz && cd libiconv-1.15/
  2. ./configure --prefix=/usr/local --libdir=/usr/local/lib64 --enable-static
  3. make && make install
  4. cd ../
  5. tar zxf libmcrypt-2.5.8.tar.gz && cd libmcrypt-2.5.8/
  6. ./configure --prefix=/usr/local --libdir=/usr/local/lib64 --enable-static
  7. make && make install
  8. ldconfig
  9. cd libltdl/
  10. ./configure --prefix=/usr/local --libdir=/usr/local/lib64 --enable-ltdl-install
  11. make && make install
  12. cd ../../
  13. tar zxf mhash-0.9.9.9.tar.gz && cd mhash-0.9.9.9/
  14. ./configure --prefix=/usr/local --libdir=/usr/local/lib64
  15. make && make install
  16. cd ../
  17. tar zxf mcrypt-2.6.8.tar.gz && cd mcrypt-2.6.8/
  18. /sbin/ldconfig
  19. ./configure --prefix=/usr/local --libdir=/usr/local/lib64
  20. make && make install
  21. cd ../
  22. tar zxf icu4c-58_2-src.tgz && cd icu/source/
  23. ./configure --prefix=/usr/local --libdir=/usr/local/lib64 --enable-static
  24. make && make install
  25. cd ../../
  26. tar -zxvf libmemcached-1.0.18.tar.gz && cd libmemcached-1.0.18
  27. ./configure --prefix=/usr/local --libdir=/usr/local/lib64
  28. make && make install
  29. cd ../
  30. tar zxf pcre-8.41.tar.gz && cd pcre-8.41/
  31. ./configure --prefix=/usr/local --libdir=/usr/local/lib64 --enable-utf
  32. make && make install
  33. cd ../
复制代码
2、编译安装PHP(FastCGI模式)
  1. tar zxf php-7.1.10.tar.gz
  2. cd php-7.1.10/
  3. /sbin/ldconfig
  4. ./configure --prefix=/usr/local --libdir=/usr/local/lib64 --with-config-file-path=/usr/local/etc --with-config-file-scan-dir=/usr/local/etc/php \
  5. --with-libxml-dir --with-openssl --with-kerberos --with-zlib --enable-bcmath --with-bz2 --enable-calendar --with-curl \
  6. --enable-exif --enable-fpm --enable-ftp --with-png-dir --with-gd --with-jpeg-dir --enable-gd-native-ttf \
  7. --with-icu-dir=/usr/local --enable-mbstring --enable-mbregex --enable-shmop --enable-soap --enable-sockets \
  8. --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-xmlrpc --with-libedit --with-iconv-dir=/usr/local \
  9. --with-xsl --enable-zip --with-pcre-regex --with-pcre-jit --with-freetype-dir --enable-xml --with-mysqli=mysqlnd \
  10. --with-pdo-mysql=mysqlnd --with-pdo-sqlite --with-sqlite3 --disable-rpath --enable-inline-optimization --with-mcrypt \
  11. --with-mhash --enable-pcntl --without-pear --with-gettext --enable-fileinfo --enable-intl --enable-opcache --enable-cli \
  12. --with-gmp --with-tidy --with-pcre-dir=/usr/local --with-readline --with-fpm-systemd --with-zlib-dir --with-libdir=lib64
  13. make ZEND_EXTRA_LIBS='-liconv'
  14. make install
  15. cp php.ini-production /usr/local/etc/php.ini
  16. cp /usr/local/etc/php-fpm.conf.default /usr/local/etc/php-fpm.conf
  17. cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/php-fpm.service
  18. systemctl enable php-fpm.service
  19. cd ../
复制代码
3、编译安装PHP扩展模块
  1. tar zxf msgpack-2.0.2.tgz
  2. cd msgpack-2.0.2
  3. phpize
  4. ./configure
  5. make && make install
  6. cd ../
  7. tar zxf igbinary-2.0.4.tgz
  8. cd igbinary-2.0.4
  9. phpize
  10. ./configure
  11. make && make install
  12. cd ../
  13. tar zxf memcached-3.0.3.tgz
  14. cd memcached-3.0.3
  15. phpize
  16. ./configure --with-libdir=lib64 --enable-memcached --enable-memcached-igbinary --enable-memcached-json --enable-memcached-msgpack
  17. make && make install
  18. cd ../
  19. tar zxf redis-3.1.3.tgz
  20. cd redis-3.1.3
  21. phpize
  22. ./configure
  23. make && make install
  24. cd ../
  25. tar zxf yaml-2.0.2.tgz
  26. cd yaml-2.0.2
  27. phpize
  28. ./configure
  29. make && make install
  30. cd ../
  31. tar zxf mongodb-1.2.9.tgz
  32. cd mongodb-1.2.9
  33. phpize
  34. ./configure
  35. make && make install
  36. cd ../
复制代码
三、安装Nginx
  1. tar zxf nginx-1.13.5.tar.gz
  2. cd nginx-1.13.5/
  3. ./configure --prefix=/usr/local --libdir=/usr/local/lib64 --conf-path=/usr/local/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/var/lib/nginx/proxy --lock-path=/run/lock/nginx.lock --pid-path=/run/nginx.pid \
  4. --with-http_ssl_module --with-http_v2_module --with-http_image_filter_module --with-http_xslt_module --with-http_realip_module --with-http_stub_status_module \
  5. --with-pcre-jit --with-http_flv_module --with-http_mp4_module --with-http_addition_module \
  6. --with-threads --with-http_ssl_module --with-http_gzip_static_module --without-mail_imap_module --without-mail_pop3_module --without-mail_smtp_module \
  7. --without-http_uwsgi_module --without-http_scgi_module --without-select_module \
  8. --with-cc-opt='-O2'
  9. make && make install
  10. cd ../
  11. mkdir /var/log/nginx
  12. mkdir /var/lib/nginx
复制代码
四、收尾 1、添加www用户
  1. /usr/sbin/groupadd www
  2. /usr/sbin/useradd -M -g www www
复制代码
2、优化内核
  1. #for aliyun
  2. cat >>/etc/security/limits.conf<<eof
  3. * soft nproc 65535
  4. * hard nproc 65535
  5. eof
  6. #other
  7. cat >>/etc/security/limits.conf<<eof
  8. * soft nproc 65535
  9. * hard nproc 65535
  10. * soft nofile 65535
  11. * hard nofile 65535
  12. eof
  13. echo "fs.file-max=65535" >> /etc/sysctl.conf
复制代码
3、设置开机启动
  1. systemctl enable nginx.service
  2. systemctl enable php-fpm.service
  3. systemctl enable memcached.service
  4. systemctl enable supervisord.service
复制代码


回复

使用道具 举报