写在前边
安装环境
centos最小安装,只安装调试工具
需要的软件包在下边地址
链接: https://pan.baidu.com/s/1UOfNWi0YmrqbKfoIvlcYfQ
提取码: shrv
下载出来后上传到/usr/local/src
目录中,要是不放心文件安全性的自己去官网下载也可以
01.安装依赖库
检查系统更新
yum check-update
安装依赖库
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype-devel libxml2-devel glib2-devel bzip2 bzip2-devel ncurses-devel curl-devel e2fsprogs-devel krb5-devel libidn-devel openssl-devel openldap-devel openldap-clients openldap-servers gd-devel bison zlib* libxml* libtool-ltdl-devel* icu libicu* wget lrzsz mysql-devel unzip rsync ntp cmake vim
02.安装Nginx
主配置文件:/usr/local/nginx/conf/nginx.conf
服务控制:service nginx (start|stop|restart|reload|configtest)
安装依赖包
定位软件目录
cd /usr/local/src
安装openssl
tar zxf openssl-1.0.1t.tar.gz
修改文件夹名为openssl
mv openssl-1.0.1t openssl
安装zlib
tar zxf zlib-1.2.11.tar.gz
修改文件夹名称为zlib
mv zlib-1.2.11 zlib
安装pcre
tar zxf pcre-8.40.tar.gz
修改文件夹名称为pcre
mv pcre-8.40 pcre
开始安装Nginx
groupadd www
#添加一个www的新用户组
useradd -r -g www www -s /sbin/nologin
cd /usr/local/src/
tar zxf nginx-1.12.2.tar.gz
cd nginx-1.12.2
./configure \
--prefix=/usr/local/nginx \
"--http-client-body-temp-path=/tmp/clientbody" \
"--http-proxy-temp-path=/tmp/proxy" \
"--http-fastcgi-temp-path=/tmp/fastcgi" \
"--http-uwsgi-temp-path=/tmp/uwsgi" \
"--http-scgi-temp-path=/tmp/scgi" \
"--user=www" \
"--group=www" \
"--with-file-aio" \
"--with-http_realip_module" \
"--with-http_ssl_module" \
"--with-openssl=/usr/local/src/openssl" \
"--with-http_gzip_static_module" \
"--with-zlib=/usr/local/src/zlib" \
"--with-http_stub_status_module" \
"--with-pcre=/usr/local/src/pcre"
make
make install
创建相关目录
mkdir /usr/local/nginx/conf/vhosts
mkdir -p /data/nginx/logs/shop
mkdir -p /var/run/nginx
chown -R www:www /data/nginx
chown -R www:www /var/run/nginx
mkdir /wwwroot
添加
主配置文件(/usr/local/nginx/conf/nginx.conf
)
配置文件内容在共享里有现成的,权限记得改755就可以
由于博客字数的限制,配置文件单开一篇博客,名字为nginx编译的配置文件,需要的自取
网站配置文件(/usr/local/nginx/conf/vhost/shop.conf
)
同上,名字为网站编译的配置文件
服务脚本文件(/etc/init.d/nginx
)
同第一,名字为服务脚本编译的配置文件
添加到系统服务并开机启动
chmod +x /etc/init.d/nginx
chkconfig --add nginx
chkconfig nginx on
02.安装PHP
安装依赖库
cd /usr/local/src
tar zxf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7/
./configure
make
make install
/sbin/ldconfig
cd libltdl/
./configure --enable-ltdl-install
make
make install
ln -s /usr/lib64/libXpm.so* /usr/lib/
安装PHP
cd /usr/local/src
tar zxf php-5.6.34.tar.gz
cd php-5.6.34
./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-libxml-dir \
--with-pcre-dir \
--with-mcrypt \
--with-openssl \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-xpm-dir \
--with-gettext \
--with-freetype-dir \
--with-bz2 \
--with-iconv-dir \
--with-zlib \
--with-zlib-dir \
--with-curl \
--with-xmlrpc \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--with-icu-dir=/usr \
--enable-pcntl \
--enable-intl \
--enable-sockets \
--enable-gd-native-ttf \
--enable-gd-jis-conv \
--enable-ftp \
--enable-zip \
--enable-calendar \
--enable-mbstring \
--enable-exif \
--enable-soap \
--enable-wddx \
--enable-bcmath \
--enable-fd-setsize=4096 \
--disable-short-tags \
--disable-ipv6
make
make install
创建配置文件
cp /usr/local/src/php-5.6.34/php.ini-production /usr/local/php/etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
安装redis 扩展
cd /usr/local/src
unzip phpredis-master.zip
cd phpredis-master/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
echo "extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/redis.so" >>/usr/local/php/etc/php.ini
安装zendloader 扩展
cd /usr/local/src
tar zxf zend-loader-php5.6-linux-x86_64.tar.gz
cd zend-loader-php5.6-linux-x86_64
mv ZendGuardLoader.so /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/ZendGuardLoader.so
vi /usr/local/php/etc/php.ini
# 追加以下内容
[zendloader]
zend_loader.enable=1
zend_extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/ZendGuardLoader.so
zend_loader.disable_licensing=0
zend_loader.obfuscation_level_support=3
zend_loader.license_path=
service php-fpm restart
创建php 运行所需要目录并设置权限
mkdir /var/run/php
mkdir /var/log/php
chown -R www:www /var/run/php/
chown -R www:www /var/log/php/
php-fpm 加入系统服务并开机启动
cp /usr/local/src/php-5.6.34/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
编辑PHP 相关路径(/etc/init.d/php-fpm)
chmod +x /etc/init.d/php-fpm
chkconfig --add php-fpm
service php-fpm start
chkconfig php-fpm on
启动nginx服务
service nginx start
防火墙开放80端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
重启防火墙
systemctl reload firewalld.service
安装成功