一、PHP 安装
1.安装扩展包并更新系统内核:
# yum install epel-release -y
#yum update
2.安装php依赖组件(包含Nginx赖):
# yum -y install wget vim pcre pcre-devel openssl openssl-devel libicu-devel gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses ncurses-devel curl curl-devel krb5-devel libidn libidn-devel openldap openldap-devel nss_ldap jemalloc-devel cmake boost-devel bison automake libevent libevent-devel gd gd-devel libtool* libmcrypt libmcrypt-devel mcrypt mhash libxslt libxslt-devel readline readline-devel gmp gmp-devel libcurl libcurl-devel openjpeg-devel
3.创建用户及组
useradd www -s /sbin/nologin -M
4.系统环境设置
ulimit -SHn 65535 //设置linux高负载参数
5.编译安装PHP
#cd /usr/local/src/
#tar xf php-7.1.11.tar.gz
# cd php-7.1.11
#cp -frp /usr/lib64/libldap* /usr/lib/
# ./configure --prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--enable-mysqlnd-compression-support \
--with-iconv-dir \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-mbstring \
--enable-intl \
--with-mcrypt \
--with-libmbfl \
--enable-ftp \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--with-gettext \
--disable-fileinfo \
--enable-opcache \
--with-pear \
--enable-maintainer-zts \
--with-ldap=shared \
--without-gdbm \
# make -j 4 && make install
6.完成安装后配置php.ini文件:
# cp php.ini-development /usr/local/php/etc/php.ini
# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
7. 修改 php.ini 相关参数:
#vim /usr/local/php/etc/php.ini
expose_php = Off
short_open_tag = ON
max_execution_time = 300
max_input_time = 300
memory_limit = 128M
post_max_size = 32M
date.timezone = Asia/Shanghai
mbstring.func_overload=2
extension = "/usr/local/php/lib/php/extensions/no-debug-zts-20160303/ldap.so"
8. 配置php-fpm.conf
取下以下注释并填写完整路径:
pid = /usr/local/php/var/run/php-fpm.pid
9. 创建system系统单元文件php-fpm启动脚本:
#vim /usr/lib/systemd/system/php-fpm.service
添加如下变量内容:
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=simple
PIDFile=/usr/local/php/var/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
[Install]
WantedBy=multi-user.target
10.启动php-fpm服务并加入开机自启动:
#systemctl enable php-fpm.service
# systemctl start php-fpm.service
二、Nginx 安装过程
1.Nginx 编译安装
# cd /usr/local/src/
#tar xf openssl-1.1.0e.tar.gz
# tar xf nginx-1.13.2.tar.gz
./configure \
--prefix=/usr/local/nginx \
--user=www \
--group=www \
--with-openssl=/usr/local/src/openssl-1.1.0e \
--with-pcre \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-http_image_filter_module \
--with-http_slice_module \
--with-mail \
--with-threads \
--with-file-aio \
--with-stream \
--with-mail_ssl_module \
--with-stream_ssl_module \
# make -j8 && make install //编译并安装
1. 创建systemctl 系统Nginx 服务启动文件
# vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=The nginx HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP /usr/local/nginx/logs/nginx.pid
ExecStop=/bin/kill -s QUIT /usr/local/nginx/logs/nginx.pid
PrivateTmp=true
[Install]
WantedBy=multi-user.target
2. 加入开机自启动并启动Nginx
#systemctl enable nginx.service
#systemctl start nginx.service
3. 启动和查看Nginx 启动状态
#systemctl restart nginx.service
#systemctl status nginx.service
#ss -ntlp
4. nginx和php-fpm整合
5. 编辑/usr/local/nginx/nginx.conf
#vim /usr/local/nginx/nginx.conf
红框中“#”号去掉
6. 红框中“#”号去掉
添加红框中内容
7. 改成如下
8. 重新载入nginx的配置文件
# systmctl restart nginx.service
9.测试php文件
在/usr/local/nginx/html下创建phpinfo.php文件,输入如下内容
<?php
phpinfo();
?>
5、浏览器访问
访问http://你的服务器ip/phpinfo.php,皆可以见到php信息了。
---------------------------------------------------------------------------------------------------
发表评论