Home php教程 php手册 Linux/Unix下nginx+php安装简明教程

Linux/Unix下nginx+php安装简明教程

Jun 06, 2016 pm 08:00 PM
linux unix install Install Concise tutorial

一、安装nginx: 1. 安装pcre库,nginx的rewrite模板需用到pcre库: 1. mkdir -p /works 2. cd /works 3. wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.20.tar.gz 4. tar -zxvf pcre-8.20.tar.gz 5. ./configure 6. make make install 7

 

一、安装nginx:

1. 安装pcre库,nginx的rewrite模板需用到pcre库:

1.    mkdir -p /works 

2.    cd /works 

3.    wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.20.tar.gz 

4.    tar -zxvf pcre-8.20.tar.gz 

5.    ./configure 

6.    make && make install 

7.    cd .. 

2. 安装nginx: www.2cto.com

1.    wget http://nginx.org/download/nginx-1.0.10.tar.gz 

2.    tar -zxvf nginx-1.0.10.tar.gz 

3.    cd nginx-1.0.10 

4.    ./configure 

5.    make && make install 

6.    cd .. 

3. 新建用户和组:

1.    groupadd www 

2.    useradd -r -g www www 

二、安装PHP5

1. 安装依赖包:

1.    libcurl: 

2.    wget http://curl.haxx.se/download/curl-7.23.1.tar.gz 

3.    tar -zxvf curl-7.23.1.tar.gz 

4.    cd curl-7.23.1/ 

5.    ./configure 

6.    make && make install 

7.    cd .. 

 

libxml2:

1.    wget ftp://xmlsoft.org/libxml2/libxml2-2.7.6.tar.gz 

2.    tar -zxvf libxml2-2.7.6.tar.gz 

3.    cd libxml2-2.7.6 

4.    ./configure 

5.    make && make install 

6.    cd ..  

libxslt:

1.    wget ftp://xmlsoft.org/libxml2/libxslt-1.1.24.tar.gz 

2.    tar -zxvf libxslt-1.1.24.tar.gz 

3.    cd libxslt-1.1.24 

4.    ./configure  make && make install 

5.    cd ..  

freetype:

1.    wget http://download.savannah.gnu.org/releases/freetype/freetype-2.4.6.tar.gz 

2.    tar -zxvf freetype-2.4.6.tar.gz 

3.    cd freetype-2.4.6  ./configure 

4.    make && make install 

5.    cd .. 

libpng:

1.    wget "http://prdownloads.sourceforge.net/libpng/libpng-1.5.6.tar.gz?download"

2.    tar -zxvf libpng-1.5.6.tar.gz 

3.    cd libpng-1.5.6  ./configure 

4.    make && make install 

5.    cd .. 

libjpeg:

1.    wget http://ijg.org/files/jpegsrc.v8c.tar.gz 

2.    tar -zxvf jpegsrc.v8c.tar.gz 

3.    cd jpeg-8c/ 

4.    ./configure 

5.    make && make install 

6.    cd .. 

2. 安装php5和php-fpm:

1.    wget http://museum.php.net/php5/php-5.2.16.tar.gz 

2.    wget http://php-fpm.org/downloads/php-5.2.16-fpm-0.5.14.diff.gz 

3.    tar -zxvf php-5.2.16.tar.gz  

4.    gunzip php-5.2.16-fpm-0.5.14.diff.gz  

5.    cd php-5.2.16/ 

6.    patch -p1

7.   

8.    ./configure \ 

9.    --with-curl \ 

10.   --enable-calendar \ 

11.   --with-xsl \ 

12.   --with-libxml-dir \ 

13.   --enable-ftp \ 

14.   --with-gd \ 

15.   --with-freetype-dir \ 

16.   --with-jpeg-dir \ 

17.   --with-png-dir \ 

18.   --enable-mbstring \ 

19.   --with-zlib \ 

20.   --enable-shared \ 

21.   --with-mysql \ 

22.   --enable-fastcgi \ 

23.   --enable-fpm  

24.   ./configure && make && make install 

修改php-fpm的配置文件/usr/local/etc/php-fpm.conf,设置执行php-fpm的用户和组名:

大约在第62行:

1.    Unix user of processes 

2.                                 

3.    Unix group of processes 

4.     

修改为:

1.    Unix user of processes 

2.    www                           

3.    Unix group of processes 

4.    www

启动php-fpm:

1.    /usr/local/sbin/php-fpm start 

2.    lsof -i:9000  

3.    netstat -ant|grep 9000   

4.    #9000为php-fpm的默认端口,可以在/usr/local/etc/php-fpm.conf中修改。 

修改nginx配置文件/usr/local/nginx/conf/nginx.conf,我的nginx配置文件如下:

1.    worker_processes  10; 

2.    events { 

3.        worker_connections  1024; 

4.    } 

5.    http { 

6.        include       mime.types; 

7.        default_type  application/octet-stream; 

8.        sendfile        on; 

9.        keepalive_timeout  65; 

10.       gzip  on; 

11.       server { 

12.           listen       80; 

13.           server_name  ead; 

14.   root /data/faceshow/www; 

15.           location / { 

16.               root   html; 

17.               index  index.php index.html index.htm; 

18.           } 

19.           error_page   500 502 503 504  /50x.html; 

20.           location = /50x.html { 

21.               root   html; 

22.           } 

23.     

24.   #此段代码为关键 

25.           location  ~ \.php$ { 

26.               fastcgi_pass   127.0.0.1:9000; #对应php-fmp的端口 

27.               fastcgi_index  index.php; 

28.               fastcgi_param  SCRIPT_FILENAME  /data/faceshow/www/$fastcgi_script_name;   

29.            #php文件的物理路径 

30.               include        fastcgi_params; 

31.           } 

32.     

33.   location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ 

34.        { 

35.           expires      30d; 

36.        } 

37.        location ~ .*\.(js|css)?$ 

38.        { 

39.           expires      1h; 

40.        }     

41.       } 

42.   } 

43.  

启动nginx:

1.    /usr/local/nginx/bin/nginx  

2.    /usr/local/nginx/bin/nginx -s reload 

三、常见问题:

问题:nginx ./configure时报如下错误

1.    ./configure: error: the HTTP rewrite module requires the PCRE library. 

2.    You can either disable the module by using --without-http_rewrite_module 

3.    option, or install the PCRE library into the system, or build the PCRE library 

4.    statically from the source with nginx by using --with-pcre= option. 

解决:这是由于未PCRE库,请安装PCRE库在运行./configure。也可以使用带--without-http_rewrite_module参数进行./configure,但是这将导致nginx不支持rewrite功能!

 

四、相关文件下载地址:

libcurl: http://curl.haxx.se/download.html

libxml2:ftp://xmlsoft.org/libxml2/

libxslt:ftp://xmlsoft.org/libxml2/

libpng:http://www.libpng.org/pub/png/libpng.html

libjpeg: http://ijg.org/files/

freetype:http://download.savannah.gnu.org/releases/freetype/

pcre:http://www.pcre.org/

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

php-fpm:http://php-fpm.org/

php5:http://www.php.net/releases/

MySQL:http://www.mysql.com/downloads/mirror.php?id=404683#mirrors

  摘自 爱E族

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1268
29
C# Tutorial
1248
24
Linux Architecture: Unveiling the 5 Basic Components Linux Architecture: Unveiling the 5 Basic Components Apr 20, 2025 am 12:04 AM

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

How to check the warehouse address of git How to check the warehouse address of git Apr 17, 2025 pm 01:54 PM

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

How to run sublime after writing the code How to run sublime after writing the code Apr 16, 2025 am 08:51 AM

There are six ways to run code in Sublime: through hotkeys, menus, build systems, command lines, set default build systems, and custom build commands, and run individual files/projects by right-clicking on projects/files. The build system availability depends on the installation of Sublime Text.

How to run java code in notepad How to run java code in notepad Apr 16, 2025 pm 07:39 PM

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

What is the main purpose of Linux? What is the main purpose of Linux? Apr 16, 2025 am 12:19 AM

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

laravel installation code laravel installation code Apr 18, 2025 pm 12:30 PM

To install Laravel, follow these steps in sequence: Install Composer (for macOS/Linux and Windows) Install Laravel Installer Create a new project Start Service Access Application (URL: http://127.0.0.1:8000) Set up the database connection (if required)

git software installation git software installation Apr 17, 2025 am 11:57 AM

Installing Git software includes the following steps: Download the installation package and run the installation package to verify the installation configuration Git installation Git Bash (Windows only)

How to use VSCode How to use VSCode Apr 15, 2025 pm 11:21 PM

Visual Studio Code (VSCode) is a cross-platform, open source and free code editor developed by Microsoft. It is known for its lightweight, scalability and support for a wide range of programming languages. To install VSCode, please visit the official website to download and run the installer. When using VSCode, you can create new projects, edit code, debug code, navigate projects, expand VSCode, and manage settings. VSCode is available for Windows, macOS, and Linux, supports multiple programming languages ​​and provides various extensions through Marketplace. Its advantages include lightweight, scalability, extensive language support, rich features and version

See all articles