nginx源码安装
说明:使用nginx源码编译的方式安装时,需要先安装nginx的依赖库pcre、zlib、oppenssl。
官网下载地址
http://nginx.org/en/download.html
$ wget http://nginx.org/download/nginx-1.15.3.tar.gz
$ tar -zxvf nginx-1.15.3.tar.gz
$ cd nginx-1.15.3
$ sudo ./configure --prefix=/usr/local/nginx --with-pcre=../pcre-8.38 --with-zlib=../zlib-1.2.11 --with-openssl=../openssl-1.0.1f --with-http_ssl_module
$ sudo make && sudo make install
Tips:
--with-pcre=../pcre-8.38 //pcre-8.38为pcre的源码目录(不是安装目录)
--with-zlib=../zlib-1.2.11 //zlib-1.2.11为zlib的源码目录(不是安装目录)
--with-openssl=../openssl-1.0.1f //openssl-1.0.1f为源码安装目录(不是安装目录)
--with-http_ssl_module
如果安装过程出现错误,有可能是pcre的版本不兼容,
依赖库
1、pcre
官网下载地址
https://ftp.pcre.org/pub/pcre/
$ wget https://ftp.pcre.org/pub/pcre/pcre-8.00.tar.gz
$ tar -zxvf pcre-8.00.tar.gz
$ cd pcre-8.00.tar.gz
$ ./configure --prefix=/usr/local/pcre
$ make
$ make check
$ sudo make install
安装pcre错误信息
configure: error: You need a C++ compiler for C++ support
解决办法:
$ sudo apt-get install build-essential
2、zlib
官网下载地址
https://zlib.net/
$ wget https://zlib.net/zlib-1.2.11.tar.gz
$ tar -zxvf zlib-1.2.11.tar.gz
$ cd zlib-1.2.11
$ ./config --prefix=/usr/local/zlib
$ make
$ make check
$ sudo make install
$ make clean
$ make distclean
3.OpenSSL
官网下载地址
https://www.openssl.org/source/
检查openssl是否安装过
$ openssl -v
如果系统默认没有安装
$ wget https://www.openssl.org/source/old/1.0.1/openssl-1.0.1f.tar.gz
$ tar -zxvf openssl-1.0.1f.tar.gz
$ cd openssl-1.0.1f
$ sudo ./configure
$ sudo make && sudo make install
如果操作系统已默认安装过openssl,也需要下载openssl任意版本的源码包,我下载和我主机上一致的版本openssl-1.0.1f。
使用openssl生成证书
具体教程可以参考https://ningyu1.github.io/site/post/51-ssl-cert/
nginx: [emerg] PEM_read_bio_X509_AUX("/usr/local/nginx-1.15.3/conf/certs-b/server.csr") failed (SSL: error:0906D06C:PEM routines:PEM_read_bio:no start line:Expecting: TRUSTED CERTIFICATE)
linux ubuntu系统下 安装 php
源码编译安装php,--prfix=/usr/local/php-7.2.9参数可以设定安装目录,可以默认安装需要的模块,启用需要的模块,关闭不需要的模块
./configure --prefix=/usr/local/php-7.2.9 \
--enable-opcache \
--with-config-file-path=/usr/local/php-7.2.9/etc \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--enable-fpm \
--enable-fastcgi \
--enable-static \
--enable-inline-optimization \
--enable-sockets \
--enable-wddx \
--enable-zip \
--enable-calendar \
--enable-bcmath \
--enable-soap \
--with-zlib \
--with-iconv \
--with-gd \
--with-xmlrpc \
--enable-mbstring \
--without-sqlite \
--with-curl \
--enable-ftp \
--with-mcrypt \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--disable-ipv6 \
--disable-debug \
--with-openssl \
--disable-maintainer-zts \
--disable-safe-mode \
--disable-fileinfo
错误一:error: Cannot find OpenSSL's <evp.h>
解决办法:
$ sudo apt-get install libcurl4-openssl-dev pkg-config
错误二:configure: error: jpeglib.h not found.
解决办法:
$ sudo apt-get install libjpeg-dev
错误三:configure: error: png.h not found.
解决办法:
$ sudo apt-get install libpng-dev
错误四:configure: error: freetype-config not found.
解决办法:
$ sudo apt-get -y install libfreetype6-dev
错误五:configure: error: Please reinstall the iconv library.
解决办法:
官网下载libiconv
https://ftp.gnu.org/pub/gnu/libiconv/
$ cd ~/Downloads/
$ wget https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.15.tar.gz
$ tar -zxvf libiconv-1.15.tar.gz
$ cd libiconv-1.15
$ sudo ./configure --prefix=/usr/local/libiconv-1.15
$ sudo make && sudo make install
Tips:
每台机器在配置./configure, 编译(make) 安装过程中出现的错误可能不会一样,需要根据错误信息解决问题。
安装成功后:
+--------------------------------------------------------------------+
| License: |
| This software is subject to the PHP License, available in this |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+--------------------------------------------------------------------+
Thank you for using PHP.
Installing PEAR environment: /usr/local/php-7.2.9/lib/php/
[PEAR] Archive_Tar - installed: 1.4.3
[PEAR] Console_Getopt - installed: 1.4.1
[PEAR] Structures_Graph- installed: 1.1.1
[PEAR] XML_Util - installed: 1.4.2
[PEAR] PEAR - installed: 1.10.5
Wrote PEAR system config file at: /usr/local/php-7.2.9/etc/pear.conf
You may want to add: /usr/local/php-7.2.9/lib/php to your php.ini include_path
/home/zqh/Downloads/php-7.2.9/build/shtool install -c ext/phar/phar.phar /usr/local/php-7.2.9/bin
ln -s -f phar.phar /usr/local/php-7.2.9/bin/phar
Installing PDO headers: /usr/local/php-7.2.9/include/php/ext/pdo/
php添加环境变量:
在/etc/profile文件中添加变量
$ vi /etc/profile
在文件末尾加上如下两行代码
PATH=/usr/local/php-7.2.9/bin:$PATH
export PATH
要是刚才的修改马上生效,需要执行以下代码
source /etc/profile
配置nginx和php
配置php.ini和php-fpm.conf
1、php.ini
复制php-7.2.9目录下的php.ini-developement 到 /usr/local/php-7.2.9/etc/,修改名字为php.ini
2、phpfpm
$ cd /usr/local/php-7.2.9/etc/
$ cp phpfpm.conf.default phpfpm.conf
$ cd php-fpm.d/
$ cp www.conf.default www.conf
3.nginx 配置
$ groupadd www //添加www分组
$ useradd -g www www //在www分组下添加www用户
cd /usr/local/nginx-1.15.3/conf/打开nginx.conf修改配置文件。
group = www
user = www
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;
}
配置参考:
http://www.nginx.cn/231.html