Centos 7 Nginx + PHP 安装步骤

前端之家收集整理的这篇文章主要介绍了Centos 7 Nginx + PHP 安装步骤前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Centos 7 Nginx + PHP 安装步骤

Centos 7 下的 PHP7/Nginx/Memcached 安装步骤。

一、获取相关开源程序

1、安装环境所需的程序库

  1. sudo -s
  2. LANG=C
  3. yum -y update
  4. yum remove mariadb*
  5. 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
  6. yum -y install supervisor
  7. 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.5.tar.gz http://cn2.PHP.net/get/PHP-7.1.5.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.40.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.0.tar.gz
  12. wget http://pecl.PHP.net/get/msgpack-2.0.2.tgz
  13. wget http://pecl.PHP.net/get/igbinary-2.0.1.tgz
  14. wget http://pecl.PHP.net/get/memcached-3.0.3.tgz
  15. wget http://pecl.PHP.net/get/redis-3.1.2.tgz
  16. wget http://pecl.PHP.net/get/swoole-2.0.7.tgz

二、安装PHP 7(FastCGI模式)

1、编译安装PHP 7 所需的支持库:

  1. tar zxf libiconv-1.15.tar.gz
  2. cd libiconv-1.15/
  3. ./configure --prefix=/usr
  4. make && make install
  5. cd ../
  6.  
  7. tar zxf libmcrypt-2.5.8.tar.gz
  8. cd libmcrypt-2.5.8/
  9. ./configure --prefix=/usr
  10. make && make install
  11. ldconfig
  12. cd libltdl/
  13. ./configure --prefix=/usr --enable-ltdl-install
  14. make && make install
  15. cd ../../
  16.  
  17. tar zxf mhash-0.9.9.9.tar.gz
  18. cd mhash-0.9.9.9/
  19. ./configure --prefix=/usr
  20. make && make install
  21. cd ../
  22.  
  23. tar zxf mcrypt-2.6.8.tar.gz && cd mcrypt-2.6.8/
  24. /sbin/ldconfig
  25. ./configure --prefix=/usr
  26. make && make install
  27. cd ../
  28.  
  29. tar zxf icu4c-58_2-src.tgz && cd icu/source/
  30. ./configure --prefix=/usr
  31. make && make install
  32. cd ../../
  33.  
  34. tar zxf openssl-1.1.0e.tar.gz && cd openssl-1.1.0e
  35. ./config --prefix=/usr/local/ssl shared zlib-dynamic
  36. make && make install
  37. echo /usr/local/ssl/lib > /etc/ld.so.conf.d/openssl-x86_64.conf
  38. /sbin/ldconfig
  39. cd ../

2、编译安装PHP(FastCGI模式)

  1. tar zxf PHP-7.1.5.tar.gz
  2. cd PHP-7.1.5/
  3. ./configure --prefix=/usr/local --mandir=/usr/local/share/man --infodir=/usr/local/share/info --sysconfdir=/usr/local/etc --with-config-file-path=/usr/local/etc --with-config-file-scan-dir=/usr/local/etc/PHP --with-libxml-dir \
  4. --with-openssl=/usr/local/ssl --with-kerberos --with-zlib --enable-bcmath --with-bz2 --enable-calendar --with-curl --enable-exif --enable-fpm --enable-ftp --with-png-dir --with-gd --with-jpeg-dir --enable-gd-native-ttf --with-icu-dir=/usr --enable-mbstring --enable-mbregex --enable-shmop --enable-soap --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-xmlrpc --with-libedit \
  5. --with-iconv-dir=/usr/local --with-xsl --enable-zip --with-pcre-regex --with-pcre-jit --with-freetype-dir --enable-xml --with-MysqLi=MysqLnd --with-pdo-MysqL=MysqLnd --with-pdo-sqlite --with-sqlite3 --disable-rpath --enable-inline-optimization --with-mcrypt --with-mhash --enable-pcntl --enable-sockets --without-pear --with-gettext --enable-fileinfo --enable-intl --enable-opcache --enable-cli --with-gmp --with-tidy --with-pcre-dir --with-readline --with-fpm-systemd --with-zlib-dir
  6. make ZEND_EXTRA_LIBS='-liconv'
  7. make install
  8.  
  9. cp PHP.ini-production /usr/local/etc/PHP.ini
  10. cp /usr/local/etc/PHP-fpm.conf.default /usr/local/etc/PHP-fpm.conf
  11. cp sapi/fpm/PHP-fpm.service /usr/lib/systemd/system/PHP-fpm.service
  12. systemctl enable PHP-fpm.service

3、编译安装PHP扩展模块

  1. tar -zxvf libmemcached-1.0.18.tar.gz
  2. cd libmemcached-1.0.18
  3. ./configure --prefix=/usr
  4. make && make install
  5. cd ../
  6.  
  7. tar zxf msgpack-2.0.2.tgz
  8. cd msgpack-2.0.2
  9. PHPize
  10. ./configure
  11. make && make install
  12. cd ../
  13.  
  14. tar zxf igbinary-2.0.1.tgz
  15. cd igbinary-2.0.1
  16. PHPize
  17. ./configure
  18. make && make install
  19. cd ../
  20.  
  21. tar zxf memcached-3.0.3.tgz
  22. cd memcached-3.0.3
  23. PHPize
  24. ./configure --enable-memcached-igbinary --enable-memcached-json --enable-memcached-msgpack
  25. make && make install
  26. cd ../
  27.  
  28. tar zxf redis-3.1.2.tgz
  29. cd redis-3.1.2
  30. PHPize
  31. ./configure
  32. make && make install
  33. cd ../
  34.  
  35. tar zxf swoole-2.0.7.tgz
  36. cd swoole-2.0.7
  37. PHPize
  38. ./configure --enable-coroutine
  39. make && make install
  40. cd ../

三、安装Nginx

1、安装Pcre库

  1. tar zxf pcre-8.40.tar.gz
  2. cd pcre-8.40/
  3. ./configure --prefix=/usr --enable-utf8
  4. make && make install
  5. cd ../

2、安装Nginx

  1. tar zxf Nginx-1.13.0.tar.gz
  2. cd Nginx-1.13.0/
  3.  
  4. #using system OpenSSL
  5. yum -y install openssl openssl-devel
  6. ./configure --prefix=/usr/local --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 \
  7. --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 \
  8. --with-pcre-jit --with-http_flv_module --with-http_mp4_module --with-http_addition_module \
  9. --with-threads --with-http_ssl_module --with-http_gzip_static_module --without-mail_imap_module --without-mail_pop3_module --without-mail_smtp_module \
  10. --without-http_uwsgi_module --without-http_scgi_module --without-select_module \
  11. --with-cc-opt='-O2'
  12.  
  13. #use customize OpenSSL
  14. sed -i "s#/.openssl##g" auto/lib/openssl/conf
  15. ./configure --prefix=/usr/local --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 \
  16. --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 \
  17. --with-pcre-jit --with-http_flv_module --with-http_mp4_module --with-http_addition_module \
  18. --with-threads --with-http_ssl_module --with-http_gzip_static_module --without-mail_imap_module --without-mail_pop3_module --without-mail_smtp_module \
  19. --without-http_uwsgi_module --without-http_scgi_module --without-select_module \
  20. --with-openssl=/usr/local/ssl \
  21. --with-cc-opt='-O2'
  22.  
  23. make && make install
  24. cd ../
  25. mkdir /var/log/Nginx
  26. 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.  
  7. #other
  8. cat >>/etc/security/limits.conf<<eof
  9. * soft nproc 65535
  10. * hard nproc 65535
  11. * soft nofile 65535
  12. * hard nofile 65535
  13. eof
  14.  
  15. 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

猜你在找的CentOS相关文章