1、下载nginx的源码包,我下载的是nginx-1.2.8.tar.gz
2、将源码包放到桌面上
3、解压压缩包,配置环境时重命名为nginx,放到/usr/local/nginx路径下
tar zxvf nginx-1.2.8.tar.gz
cd nginx-1.2.8.tar.gz
./configure --prefix=/usr/local/nginx
提示:gcc未找到
yum install -y gcc
4、 重新配置环境
./configure --prefix=/usr/local/nginx
提示:./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
意思是说pcre未找到,去官网上下载pcre安装包,安装一下再重新配置nginx
5、下载的pcre文件为pcre-8.12.tar.bz2 ,放到桌面上并解压
tar jxvf pcre-8.12.tar.bz2
cd pcre-8.12
ls
./configure --prefix=/usr/local/pcre //配置
出现错误:make[1]: *** [pcrecpp.lo] 错误 1
make[1]: Leaving directory `/root/Desktop/pcre-8.12'
make: *** [all] 错误 2
百度了下,这个错误是缺少gcc-c++安装包,运行如下命令:
yum install -y gcc-c++
安装好后会出现complete!
重新进行./configure --prefix=/usr/local/pcre //配置
如果没有出现错误后,进行编译(make)和安装(make install),这两步可以一起写,或者分开执行
这里采用一起执行
make&&make install
6、好啦,pcre安装好了后,我们就在此配置一下nginx,看看还缺不缺其他的东西,回到nginx解压后的路径
./configure --prefix=/usr/local/nginx
提示:./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
我们明明下载了pcre并且安装好了,为什么还是没有找到?因为他不知道我们安装到哪儿了。就需要我们告诉他路径,使用这个参数吧--with-pcre=<path>
./configure --prefix=/usr/local/nginx --with-pcre=/usr/local/pcre
7、提示信息:./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.
相信大家都会判断了,这是缺少了zlib的包
把zlib的源码包放到桌面上,解压,配置,编译,安装
tar zxvf zlib-1.2.8.tar.gz
./configure --prefix=/usr/local/zlib
make && make install
8、还需要一个openssl的安装包,我们再安装一下
tar zxvf openssl.tar.gz
./Configure --prefix=/usr/local/openssl
make&&make install
9、再回去安装nginx
./configure --prefix=/usr/local/nginx --with-pcre=/usr/local/pcre --with-zlib=/usr/local=zlib
make&&make install
提示信息:
make[1]: *** [/usr/local/pcre/Makefile] 错误 127
make[1]: Leaving directory `/root/Desktop/nginx-1.2.8'
make: *** [build] 错误 2
错误原因:--with-pcre force PCRE library usage
--with-pcre-opt=OPTIONS set additional options for PCRE building
./configure --prefix=/usr/local/nginx --with-pcre=../pcre --with-zlib=/usr/local=zlib --with-openssl=/usr/local/openssl
提示信息: [objs/src/http/modules/ngx_http_log_module.o] 错误 1
解决办法:
./configure --prefix=/usr/local/nginx --with-pcre=../pcre --with-zlib=../zlib --with-openssl=../openssl --with-http_ssl_module
注:pcre和openssl的路径写的是桌面的路径,不是安装路径
10、 make&&make install
这样我们的nginx就安装成功了。
注:如上的安装,编译,配置都要在相应目录下。
在Linux上安装软件有三种方式:
源码包安装
这里的nginx就是源码包安装,他就是在官网上下载的压缩包,让我们手动进行设置安装的路径和依赖包的安装;
yum源
上面提到过一个yum install -y gcc,这个就是使用的是yum源的安装,他直接把gcc所需要的依赖包都安装好了,但是我们无法更改安装路径,(因为我自己找不到他安装到哪儿了??);
rpm包
RPM Package Manager(RPM软件包管理器)的缩写,一种用于互联网下载包的打包及安装工具,它包含在某些Linux分发版中。它生成具有.RPM扩展名的文件。作为一个软件包管理工具,RPM管理着系统已安装的所有RPM程序组件的资料,RPM文件在Linux系统中的安装最为简便
常用命令
总结:安装软件时,如果缺少东西而提示的出错信息,就看出错信息指出的是缺少什么,我们可以在官网上下载源码包,手动安装,也可以使用其他两种方式进行安装,就是缺啥补啥,再重新编译重新安装!