wred 发表于 2017-11-23 15:22:13

CentOS7 搭建nginx+php+mysql运行环境

在centOS上有两种方式可以安装nginx、php、mysql,即通过yum指令来安装;通过编译源

码安装。CentOS 7上系统自带有yum源,下介绍nginx通过源码及yum安装的方法及php、

mysql通过yum指令安装的方法。


[*]安装nginx

通过源码安装:
[*]首先要安装依赖包

yum install gcc gcc-c++(如果没有安装,在安装nginx时会有有关cc的报错信息出现)
[*]安装pcre和zlib

这两个依赖包可以通过源码来安装,但centos可以直接通过yum源安装执行:yum install –ypcre pcre-develzlib zlib-devel

[*]进入到/usr/local/src目录(当然你可以选择其他位置),下载nginx源码

1 cd /usr/local/src2 wget http://nginx.org/download/nginx-1.13.6.tar.gz3 tar -zxvf nginx-1.13.6.tar.gz4 cd nginx-1.13.6

[*]添加nginx用户和用户组

1 groupadd -r nginx2 useradd -r -g nginx nginx

[*]配置nginx安装参数

1 ./configure \2 --prefix=/usr/local/nginx \3 --sbin-path=/usr/local/nginx/sbin/nginx \4 --conf-path=/usr/local/nginx/nginx.conf \5 --pid-path=/usr/local/nginx/nginx.pid \6 --user=nginx \7 --group=nginx \8 --with-http_ssl_module \9 --with-http_flv_module \10 --with-http_mp4_module\11 --with-http_stub_status_module \12 --with-http_gzip_static_module \13 --http-client-body-temp-path=/var/tmp/nginx/client/ \14 --http-proxy-temp-path=/var/tmp/nginx/proxy/ \15 --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \16 --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \17 --http-scgi-temp-path=/var/tmp/nginx/scgi \18 --with-pcre=/usr/local/src/pcre-8.39 \19 --with-zlib=/usr/local/src/zlib-1.2.8 \20 --with-openssl=/usr/local/src/openssl-1.1.0b \
这里18、19、20不用写进去,因为之前我们通过yum指令安装过了,就调用系统默认的路径,不用指定,不然会报错!!!!!
[*]编译安装

执行 make && make install安装成功目录这样的:
然后通过sbin/nginx来启动服务。然后通过指令:curlhttp://127.0.0.1来测试是否能打开页面如果要远程访问机器上的web,那需要开放80端口,或把http、https服务开放firewall-cmd--permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https


[*]通过yum指令安装nginx、php、mysql


想要通过yum来安装的比较新的php、nginx、mysq的话,我们需要给yum添加几个源,默认是没有这些源的。
添加EPEL和Remi源:EPEL源官方网站:https://fedoraproject.org/wiki/EPELRemi官方网站:http://rpms.famillecollet.com/
64位机器执行:rpm -ivh http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm32位机器执行:rpm -ivh http://mirrors.ustc.edu.cn/fedora/epel/6/i386/epel-release-6-8.noarch.rpm rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
另外Remi源默认是关闭的,我们需要手动来启用一下。修改/etc/yum.repos.d/remi.repo文件,把下的enabled=0修改为enabled=1。
下面就可以通过yum指令安装了安装php及扩展:yum install php php-fpm php-bcmatch php-gd php-mbstring php-mcrypt php-mysql安装mysql:yum install mysql-server 安装nginx:yum install nginx 到这里nginx+php+mysql环境就搭建完了。之后就是要配置配置文件了,这里不讲述。

chengostart 发表于 2017-11-27 08:07:54

学习学习!
页: [1]
查看完整版本: CentOS7 搭建nginx+php+mysql运行环境