LNMP集合lnmp环境

linux 安装 nginx+PHP+mysql之安装nginx

2019-10-12  本文已影响0人  你在终点等我i

linux 安装 nginx+PHP+mysql之安装nginx

1.安装前的准备需要安装 gcc gcc-c++

命令 yum install gcc gcc-c++

2.安装nginx首先需要下载nginx文件

http://nginx.org/en/download.html

使用ftp命令上传 或者安装了lrzsz的可以使用rz命令进行上传

上传存放路径 /home/

首先需要设置一个用户组,并在这个用户组下边添加一个用户,并且这个用户不允许登录

[root@localhost home]# groupadd www

[root@localhost home]# useradd -g www www -M -s /sbin/nologin

执行完成之后输入以下命令检查是否添加成功

[root@localhost home]# cat /etc/passwd

在最后一行中出现

www:x:501:501::/home/www:/sbin/nologin

即为创建成功

接下来进行安装nginx

 将刚刚上传的压缩文件进行解压

[root@localhost home]# tar xf nginx-1.16.1.tar.gz

解压完成后 会出现 nginx-1.16.1 这个目录

 进入到这个目录

接下来就是进行编译nginx

--prefix=/usr/local/nginx 存放路径

--user=www --group=www 用户和用户组

--with-http_ssl_module 添加ssl

--with-http_gzip_static_module 添加 gzip

--with-pcre 添加pcre

缺少什么设置什么

[root@localhost nginx-1.16.1]# ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_gzip_static_module --with-pcre

执行上边这段后会报如下错误

./configure: error: the HTTP rewrite module requires the PCRE library.You can either disable the module by using --without-http_rewrite_moduleoption, or install the PCRE library into the system, or build the PCRE librarystatically from the source with nginx by using --with-pcre=option.

这个原因是缺少 PCRE库 只需要添加上就可以了

直接执行

[root@localhost nginx-1.16.1]# yum install pcre-devel -y

再执行[root@localhost nginx-1.16.1]# ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_gzip_static_module --with-pcre

又会出现如下错误

./configure: error: SSL modules require the OpenSSL library.You can either do not enable the modules, or install the OpenSSL libraryinto the system, or build the OpenSSL library statically from the sourcewith nginx by using --with-openssl= option.

这个是因为缺少openssl库 同样

直接执行 [root@localhost nginx-1.16.1]# yum install openssl-devel -y

再执行 [root@localhost nginx-1.16.1]# ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_gzip_static_module --with-pcre

执行完成之后安装nginx成功

然后再执行

[root@localhost nginx-1.16.1]# make && make install

等待最多一分钟之后安装完成

然后进入/usr/local/nginx/sbin

执行命令开启nginx

 [root@localhost sbin]# ./nginx

未报错则开启成功

查看是否开启成功

[root@localhost sbin]# ps -ef| grep nginx

出现如下则开启成功

root 17602 1 0 02:31 ? 00:00:00

nginx: master process

./nginx www 17603 17602 0 02:31 ? 00:00:00

nginx: worker process root 17606 11015 0 02:32 pts/0 00:00:00 grep

nginx 查看端口号命令

[root@localhost sbin]# netstat -nltp

这个时候可以在浏览器中输入ip进行访问nginx了

 但是会出现访问不到的情况,这个时候就需要关闭防火墙试一下

[root@localhost sbin]# /etc/init.d/iptables stop

 iptables: Flushing firewall rules: [ OK ] iptables: Setting chains to policy ACCEPT: filter [ OK ] iptables: Unloading modules: [ OK ]

这个时候再访问ip 就可以访问到了!

上一篇下一篇

猜你喜欢

热点阅读