一、Nginx安装
1、安装nginx依赖的软件
nginx是C写的,需要用GCC编译;nginx中的rewrite module需要PCRE;nginx中的gzip module需要zlib;nginx中的HTTP SSL module需要OpenSSL。
1.1、GCC安装
[root@localhost ~]# yum -y install gcc*
1.2、zlib源码安装
[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# wget http://prdownloads.sourceforge.net/libpng/zlib-1.2.11.tar.gz
[root@localhost src]# tar zxvf zlib-1.2.11.tar.gz
[root@localhost src]# cd zlib-1.2.11
[root@localhost zlib-1.2.11]# ./configure
[root@localhost zlib-1.2.11]# make
[root@localhost zlib-1.2.11]# make install
1.3、PCRE源码安装
[root@localhost src]# wget http://downloads.sourceforge.net/project/pcre/pcre/8.41/pcre-8.41.tar.gz
[root@localhost src]# tar zxvf pcre-8.41.tar.gz
[root@localhost src]# cd pcre-8.41[root@localhost pcre-8.41]# ./configure
[root@localhost src]# cd pcre-8.41 [root@localhost pcre-8.41]#make
[root@localhost src]# cd pcre-8.41 [root@localhost pcre-8.41]# make install
1.4、OpenSSL源码安装
注明:因源码安装OpenSSL需要Perl5以上的版本,故先编译安装perl5.24,过程如下:
[root@localhost src]# wget http://www.cpan.org/src/5.0/perl-5.24.0.tar.gz
[root@localhost src]# tar zxvf perl-5.24.0.tar.gz
[root@localhost src]# cd perl-5.24.0
[root@localhost perl-5.24.0]# ./Configure -des -Dprefix=$HOME/localperl
[root@localhost perl-5.24.0]# make
[root@localhost perl-5.24.0]# make install
接着安装openssl:
[root@localhost src]# wget https://www.openssl.org/source/openssl-1.0.2n.tar.gz
[root@localhost src]# tar zxvf openssl-1.0.2n.tar.gz
[root@localhost src]# cd openssl-1.0.2n
[root@localhost openssl-1.0.2n]# ./config
[root@localhost openssl-1.0.2n]# make
[root@localhost openssl-1.0.2n]# make install
2、源码安装nginx
[root@localhost src]# wget wget http://nginx.org/download/nginx-1.12.2.tar.gz
[root@localhost src]# tar zxvf nginx-1.12.2.tar.gz
[root@localhost src]# cd nginx-1.12.2
[root@localhost nginx-1.12.2]# ./configure --with-http_ssl_module --with-pcre=../pcre-8.41 --with-zlib=../zlib-1.2.11 --with-openssl=../openssl-1.0.2n
[root@localhost nginx-1.12.2]# make
[root@localhost nginx-1.12.2]# make install
[root@localhost nginx-1.12.2]#/usr/local/nginx/sbin/nginx -t
[root@localhost nginx-1.12.2]# /usr/local/nginx/sbin/nginx
3、打开浏览器,输入:http://10.1.83.175 ,测试nginx是否已安装成功
如果打不开,请先关闭防火墙再试:
[root@localhost nginx-1.12.2]# systemctl stop firewalld.service
二、MySQL安装
从CentOS 7.0发布以来,yum源中开始使用mariadb来代替MySQL的安装。
1、卸载mariadb
[root@localhost src]#yum list installed | grep mariadb
[root@localhost src]#yum -y remove mariadb*
2、安装MySQL
[root@localhost src]# rpm -ivh https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm // 安装官方提供的yum rpm包
[root@localhost src]# yum repolist enabled | grep "mysql.*-community.*" //检查mysql的yum源是否安装成功
[root@localhost src]# yum -y install mysql-server
[root@localhost src]# service mysqld start
[root@localhost src]# cat /var/log/mysqld.log|grep 'A temporary password' //查看初始密码
三、PHP安装
1、安装PHP
[root@localhost ~]# yum -y install php
[root@localhost ~]# php -v //查看版本
[root@localhost ~]# php -m //查看支持的扩展
[root@localhost ~]# yum -y install php-mysqlnd //安装php-mysqlnd
2、要让PHP以FastCGI的方式与nginx进行交互,需要有PHP-FPM模块的支持
[root@localhost ~]# yum -y install php-fpm
[root@localhost ~]# php-fpm -v //查看版本
[root@localhost ~]# systemctl start php-fpm
四、配置Nginx支持PHP
[root@localhost ~]# vi /usr/local/nginx/conf/nginx.conf
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
变更为:
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
[root@localhost ~]# /usr/local/nginx/sbin/nginx -s reload
五、测试搭建结果
1、创建测试页面文件
[root@localhost ~]# vi /usr/local/nginx/html/phpinfo.php
<?php
phpinfo();
?>
网友评论