ubuntu nginx安装目录(Ubuntu安装vim)

这篇文章给大家聊聊关于ubuntu nginx安装目录,以及Ubuntu安装vim对应的知识点,希望对各位有所帮助,不要忘了收藏本站哦。

如何在系统安装ARGB

nginx php-fpm安装配置

nginx本身不能处理PHP,它只是个web服务器,当接收到请求后,如果是php请求,则发给php解释器处理,并把结果返回给客户端。

nginx一般是把请求发fastcgi管理进程处理,fascgi管理进程选择cgi子进程处理结果并返回被nginx

本文以php-fpm为例介绍如何使nginx支持PHP

一、编译安装php-fpm

什么是PHP-FPM

PHP-FPM是一个PHP FastCGI管理器,是只用于PHP的,可以在 下载得到.

PHP-FPM其实是PHP源代码的一个补丁,旨在将FastCGI进程管理整合进PHP包中。必须将它patch到你的PHP源代码中,在编译安装PHP后才可以使用。

新版PHP已经集成php-fpm了,不再是第三方的包了,推荐使用。PHP-FPM提供了更好的PHP进程管理方式,可以有效控制内存和进程、可以平滑重载PHP配置,比spawn-fcgi具有更多优点,所以被PHP官方收录了。在./configure的时候带–enable-fpm参数即可开启PHP-FPM,其它参数都是配置php的,具体选项含义可以查看这里。

安装前准备

centos下执行

yum-y install gcc automake autoconf libtool make

yum-y install gcc gcc-c++ glibc

yum-y install libmcrypt-devel mhash-devel libxslt-devel \

libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel \

zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel \

ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel \

krb5 krb5-devel libidn libidn-devel openssl openssl-devel

新版php-fpm安装(推荐安装方式)

wget zvxf php-5.4.7.tar.gz

cd php-5.4.7./configure--prefix=/usr/local/php--enable-fpm--with-mcrypt \--enable-mbstring--disable-pdo--with-curl--disable-debug--disable-rpath \--enable-inline-optimization--with-bz2--with-zlib--enable-sockets \--enable-sysvsem--enable-sysvshm--enable-pcntl--enable-mbregex \--with-mhash--enable-zip--with-pcre-regex--with-mysql--with-mysqli \--with-gd--with-jpeg-dir

make all install

旧版手动打补丁php-fpm安装(旧版程序已经没有了,大家新版的吧,这里做个展示)

wget

wget

tar zvxf php-5.2.17.tar.gz

gzip-cd php-5.2.17-fpm-0.5.14.diff.gz| patch-d php-5.2.17-p1

cd php-5.2.17

./configure--prefix=/usr/local/php-with-config-file-path=/usr/local/php/etc\

-with-mysql=/usr/local/mysql\

-with-mysqli=/usr/local/mysql/bin/mysql_config-with-openssl-enable-fpm-enable-mbstring\

-with-freetype-dir-with-jpeg-dir-with-png-dir-with-zlib-dir-with-libxml-dir=/usr-enable-xml\

-with-mhash-with-mcrypt-enable-pcntl-enable-sockets-with-bz2-with-curl-with-curlwrappers\

-enable-mbregex-with-gd-enable-gd-native-ttf-enable-zip-enable-soap-with-iconv-enable-bcmath\

-enable-shmop-enable-sysvsem-enable-inline-optimization-with-ldap-with-ldap-sasl-enable-pdo\

-with-pdo-mysql

make all install

以上两种方式都可以安装php-fpm,安装后内容放在/usr/local/php目录下

以上就完成了php-fpm的安装。

下面是对php-fpm运行用户进行设置

cd/usr/local/php

cp etc/php-fpm.conf.default etc/php-fpm.conf

vi etc/php-fpm.conf

修改

user= www-data

group= www-data

如果www-data用户不存在,那么先添加www-data用户

groupadd www-data

useradd-g www-data www-data

二、编译安装nginx

然后nginx:

nginx可以使用各平台的默认包来安装,本文是介绍使用源码编译安装,包括具体的编译参数信息。

正式开始前,编译环境gcc g++开发库之类的需要提前装好,这里默认你已经装好。

ububtu平台编译环境可以使用以下指令

1

2

apt-get install build-essential

apt-get install libtool

centos平台编译环境使用如下指令

安装make:

1

yum-y install gcc automake autoconf libtool make

安装g++:

1

yum install gcc gcc-c++

下面正式开始

---------------------------------------------------------------------------

一般我们都需要先装pcre, zlib,前者为了重写rewrite,后者为了gzip压缩。

1.选定源码目录

可以是任何目录,本文选定的是/usr/local/src

1

cd/usr/local/src

2.安装PCRE库

下载最新的 PCRE源码包,使用下面命令下载编译和安装 PCRE包:

1

2

3

4

5

6

7

cd/usr/local/src

wget

tar-zxvf pcre-8.37.tar.gz

cd pcre-8.34

./configure

make

make install

3.安装zlib库

下载最新的 zlib源码包,使用下面命令下载编译和安装 zlib包:

1

2

3

4

5

6

7

8

cd/usr/local/src

wget

tar-zxvf zlib-1.2.8.tar.gz

cd zlib-1.2.8

./configure

make

make install

4.安装ssl(某些vps默认没装ssl)

1

2

3

cd/usr/local/src

wget

tar-zxvf openssl-1.0.1t.tar.gz

5.安装nginx

Nginx一般有两个版本,分别是稳定版和开发版,您可以根据您的目的来选择这两个版本的其中一个,下面是把 Nginx安装到/usr/local/nginx目录下的详细步骤:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

cd/usr/local/src

wget

tar-zxvf nginx-1.4.2.tar.gz

cd nginx-1.4.2

./configure--sbin-path=/usr/local/nginx/nginx \

--conf-path=/usr/local/nginx/nginx.conf \

--pid-path=/usr/local/nginx/nginx.pid \

--with-http_ssl_module \

--with-pcre=/opt/app/openet/oetal1/chenhe/pcre-8.37 \

--with-zlib=/opt/app/openet/oetal1/chenhe/zlib-1.2.8 \

--with-openssl=/opt/app/openet/oetal1/chenhe/openssl-1.0.1t

make

make install

--with-pcre=/usr/src/pcre-8.34指的是pcre-8.34的源码路径。

--with-zlib=/usr/src/zlib-1.2.7指的是zlib-1.2.7的源码路径。

安装成功后/usr/local/nginx目录下如下

1

2

3

4

5

6

fastcgi.confkoi-win nginx.conf.default

fastcgi.conf.defaultlogsscgi_params

fastcgi_paramsmime.typesscgi_params.default

fastcgi_params.defaultmime.types.defaultuwsgi_params

htmlnginx uwsgi_params.default

koi-utf nginx.confwin-utf

6.启动

确保系统的 80端口没被其他程序占用,运行/usr/local/nginx/nginx命令来启动 Nginx,

1

netstat-ano|grep 80

如果查不到结果后执行,有结果则忽略此步骤(ubuntu下必须用sudo启动,不然只能在前台运行)

1

sudo/usr/local/nginx/nginx

打开浏览器访问此机器的 IP,如果浏览器出现 Welcome to nginx!则表示 Nginx已经安装并运行成功。

-----------------------------------------------------

到这里nginx就安装完成了,如果只是处理静态html就不用继续安装了

如果你需要处理php脚本的话,还需要安装php-fpm。

下面安装排错

附:可能遇到的错误和一些帮助信息

1.1编译pcre错误

1

2

3

4

5

libtool: compile: unrecognized option `-DHAVE_CONFIG_H'

libtool: compile: Try `libtool--help' for more information.

make[1]:*** [pcrecpp.lo] Error 1

make[1]: Leaving directory `/usr/local/src/pcre-8.34'

make:*** [all] Error 2

解决办法:安装g++,别忘了重新configure

1

2

3

4

5

apt-get install g++

apt-get install build-essential

make clean

./configure

make

1.2 make出错

1

2

3

4

5

make:***Noruletomaketarget`build',neededby`default'.Stop.

./configure:error:SSLmodulesrequiretheOpenSSLlibrary.

Youcaneitherdonotenablethemodules,orinstalltheOpenSSLlibrary

intothesystem,orbuildtheOpenSSLlibrarystaticallyfromthesource

withnginxbyusing--with-openssl=<path>option.

按照第4步的安装方法或

ubuntu下

1

2

apt-getinstallopenssl

apt-getinstalllibssl-dev

centos下

1

yum-y install openssl openssl-devel

2.nginx编译选项

make是用来编译的,它从Makefile中读取指令,然后编译。

make install是用来安装的,它也从Makefile中读取指令,安装到指定的位置。

configure命令是用来检测你的安装平台的目标特征的。它定义了系统的各个方面,包括nginx的被允许使用的连接处理的方法,比如它会检测你是不是有CC或GCC,并不是需要CC或GCC,它是个shell脚本,执行结束时,它会创建一个Makefile文件。nginx的configure命令支持以下参数:

--prefix=path定义一个目录,存放服务器上的文件,也就是nginx的安装目录。默认使用/usr/local/nginx。

--sbin-path=path设置nginx的可执行文件的路径,默认为 prefix/sbin/nginx.

--conf-path=path设置在nginx.conf配置文件的路径。nginx允许使用不同的配置文件启动,通过命令行中的-c选项。默认为prefix/conf/nginx.conf.

--pid-path=path设置nginx.pid文件,将存储的主进程的进程号。安装完成后,可以随时改变的文件名,在nginx.conf配置文件中使用 PID指令。默认情况下,文件名为prefix/logs/nginx.pid.

--error-log-path=path设置主错误,警告,和诊断文件的名称。安装完成后,可以随时改变的文件名,在nginx.conf配置文件中使用的error_log指令。默认情况下,文件名为prefix/logs/error.log.

--http-log-path=path设置主请求的HTTP服务器的日志文件的名称。安装完成后,可以随时改变的文件名,在nginx.conf配置文件中使用的access_log指令。默认情况下,文件名为prefix/logs/access.log.

--user=name设置nginx工作进程的用户。安装完成后,可以随时更改的名称在nginx.conf配置文件中使用的 user指令。默认的用户名是nobody。

--group=name设置nginx工作进程的用户组。安装完成后,可以随时更改的名称在nginx.conf配置文件中使用的 user指令。默认的为非特权用户。

--with-select_module--without-select_module启用或禁用构建一个模块来允许服务器使用select()方法。该模块将自动建立,如果平台不支持的kqueue,epoll,rtsig或/dev/poll。

--with-poll_module--without-poll_module启用或禁用构建一个模块来允许服务器使用poll()方法。该模块将自动建立,如果平台不支持的kqueue,epoll,rtsig或/dev/poll。

--without-http_gzip_module—不编译压缩的HTTP服务器的响应模块。编译并运行此模块需要zlib库。

--without-http_rewrite_module不编译重写模块。编译并运行此模块需要PCRE库支持。

--without-http_proxy_module—不编译http_proxy模块。

--with-http_ssl_module—使用https协议模块。默认情况下,该模块没有被构建。建立并运行此模块的OpenSSL库是必需的。

--with-pcre=path—设置PCRE库的源码路径。PCRE库的源码(版本4.4- 8.30)需要从PCRE网站下载并解压。其余的工作是Nginx的./ configure和make来完成。正则表达式使用在location指令和 ngx_http_rewrite_module模块中。

--with-pcre-jit—编译PCRE包含“just-in-time compilation”(1.1.12中, pcre_jit指令)。

--with-zlib=path—设置的zlib库的源码路径。要下载从 zlib(版本1.1.3- 1.2.5)的并解压。其余的工作是Nginx的./ configure和make完成。ngx_http_gzip_module模块需要使用zlib。

--with-cc-opt=parameters—设置额外的参数将被添加到CFLAGS变量。例如,当你在FreeBSD上使用PCRE库时需要使用:--with-cc-opt="-I/usr/local/include。.如需要需要增加select()支持的文件数量:--with-cc-opt="-D FD_SETSIZE=2048".

--with-ld-opt=parameters—设置附加的参数,将用于在链接期间。例如,当在FreeBSD下使用该系统的PCRE库,应指定:--with-ld-opt="-L/usr/local/lib".

典型实例(下面为了展示需要写在多行,执行时内容需要在同一行)

1

2

3

4

5

6

7

./configure

--sbin-path=/usr/local/nginx/nginx

--conf-path=/usr/local/nginx/nginx.conf

--pid-path=/usr/local/nginx/nginx.pid

--with-http_ssl_module

--with-pcre=../pcre-4.4

--with-zlib=../zlib-1.1.3

三、修改nginx配置文件以支持php-fpm

nginx安装完成后,修改nginx配置文件为,nginx.conf

其中server段增加如下配置,注意标红内容配置,否则会出现No input file specified.错误

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

#

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;

}

四、创建测试php文件

创建php文件

在/usr/local/nginx/html下创建index.php文件,输入如下内容

<?php

echo phpinfo();?>

五、启动服务

启动php-fpm和nginx

/usr/local/php/sbin/php-fpm

#手动打补丁的启动方式/usr/local/php/sbin/php-fpm startsudo/usr/local/nginx/nginx

php-fpm关闭重启见文章结尾

六、浏览器访问

访问http://你的服务器ip/index.php,皆可以见到php信息了。

安装php-fpm时可能遇到的错误:

1.php configure时出错

configure: error: XML configuration could not be found

apt-get install libxml2 libxml2-dev(ubuntu下)yum-y install libxml2 libxml2-devel(centos下)

2.Please reinstall the BZip2 distribution

wget bzip2-1.0.5.tar.gz

cd bzip2-1.0.5make

make install

3.php的配置文件中有一行--with-mysql=/usr。

安装的时候提示:

configure: error: Cannot find MySQL header files under yes.

Note that the MySQL client library is not bundled anymore.

这是由于安装mysql时没有安装mysql头文件,或者是路径指定不正确,php找不到mysql的头文件引起的错误提示。

解决方法。

(1.)查看你的系统有没有安装mysql header

find/-name mysql.h

如果有。请指定--with-mysql=/跟你的正常路径。

如果没有。请看下一步。

(2.)redhat安装

rpm-ivh MySQL-devel-4.1.12-1.i386.rpm

(3.)ubuntu安装

apt-get install libmysqlclient15-dev

(4.)最后一步php的配置选项添加--with-mysql=/usr即可!

4.No input file specified.

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;

}

5.如果php configure时缺库,可以先安装库(ubuntu下)

sudo apt-get install make bison flex gcc patch autoconf subversion locate

sudo apt-get install libxml2-dev libbz2-dev libpcre3-dev libssl-dev zlib1g-dev libmcrypt-dev libmhash-dev libmhash2 libcurl4-openssl-dev libpq-dev libpq5 libsyck0-dev

6.mcrypt.h not found. Please reinstall libmcrypt

apt-get install libmcrypt-dev

或者

cd/usr/local/src

wget

tar-zxvf libmcrypt-2.5.8.tar.gz

cd/usr/local/src/libmcrypt-2.5.8

./configure--prefix=/usr/local

make

make install

7.php-fpm 5.4.7如何关闭重启?

php 5.4.7下的php-fpm不再支持 php-fpm以前具有的/usr/local/php/sbin/php-fpm(start|stop|reload)等命令,需要使用信号控制:

master进程可以理解以下信号

INT, TERM立刻终止 QUIT平滑终止 USR1重新打开日志文件 USR2平滑重载所有worker进程并重新载入配置和二进制模块

示例:

php-fpm关闭:

kill-INT `cat/usr/local/php/var/run/php-fpm.pid`

php-fpm重启:

kill-USR2 `cat/usr/local/php/var/run/php-fpm.pid`

查看php-fpm进程数:

ps aux| grep-c php-fpm

8.命令行下执行php,提示找不到命令

-bash:/usr/bin/php: No such file or directory

vi/etc/profile

在文件底部增加一行配置

export PATH=/usr/local/php/bin:$PATH

保存退出

source/etc/profile

附加pathinfo配置

location~ ^(.+\.php)(.*)${

fastcgi_split_path_info ^(.+\.php)(.*)$;

fastcgi_param SCRIPT_FILENAME/path/to/php$fastcgi_script_name;

fastcgi_param PATH_INFO$fastcgi_path_info;

ubuntu如何离线安装nginx

离线环境下在Ubuntu中安装Nginx需额外步骤,由于正常APT包管理无法使用,以下步骤将指导完成离线安装。

首先,在有互联网的环境下下载所需的软件包。通过以下命令进行下载,以获取Nginx的.deb文件。

执行命令后,将.deb文件复制至离线机器。若通过USB驱动器传输,手动操作完成此步骤。

在离线机器上安装.deb文件。先将文件复制至/tmp目录,使用dpkg命令进行安装。替换`/path/to/nginx_1.2.3-1_amd64.deb`为实际路径及版本号`1.2.3-1`。

执行dpkg命令时,若找不到依赖关系,可能需手动下载并安装依赖。使用以下命令下载所有依赖包。

下载后,将包复制至离线机器,并用dpkg命令安装。注意:这些步骤可能会依据Ubuntu版本和特定需求有所不同。在部分情况下,需手动解决依赖关系问题或配置Nginx的配置文件。

完成上述步骤后,即可启动Nginx服务。确保环境设置正确以实现成功安装。

【Linux】Ubuntu安装Nginx(在线安装&源码编译安装)

在Ubuntu 20.04环境中,有两种常见的Nginx安装方式,分别是在线安装和源码编译安装,版本为1.18.0。以下是对这两种方法的详细步骤:

首先,对于在线安装(apt安装):

1.检查当前版本并了解安装详情,可以看到它会自动设置一些路径,比如--prefix和--conf-path,并预装常用的https模块,如--with-http_ssl_module。

其次,如果之前已经通过apt安装了Nginx,源码编译安装前需要卸载并清除相关配置:

1.使用--purge卸载,确保完全移除,但要注意,sudo apt autoremove可能导致未预期的错误。

2.需要手动删除相关依赖。

源码编译安装则包括以下步骤:

2.2.1从nginx官网下载源码。

2.2.2安装过程中,首先解压缩文件,接着配置编译选项,可能会提示缺少pcre和zlib模块。

3.安装这些依赖。

4.开始编译并安装Nginx。

5.启动Nginx后,通过nginx-V检查,由于是自定义编译,可能不会显示所有预装模块。

6.查看安装后的模块,需要在编译目录中查找,通常比apt安装的模块更多。

总的来说,apt安装方式更便捷,而源码编译安装则提供更大的灵活性,可以根据实际需求定制安装。

阅读剩余
THE END