Home > Backend Development > PHP Tutorial > How to install Nginx and PHP-FPM via YUM on CentOS 6

How to install Nginx and PHP-FPM via YUM on CentOS 6

WBOY
Release: 2016-08-08 09:28:19
Original
990 people have browsed it

Original address: http://www.lifelinux.com/how-to-install-nginx-and-php-fpm-on-centos-6-via-yum/


Before starting to install Nginx and PHP-FPM, you must uninstall the previously installed Apache and PHP in the system. Log in as root and enter the following command:

[plain] view plaincopy #Yum Remove HTTPD*PHP*


Increase the additional resource library By default, the official resources of CentOS are not PHP-FPM, but we can from Remi Obtained from RPM resources, it depends on EPEL resources. We can add two resource libraries like this:

[plain] view plaincopy
  1. # yum install yum-priorities -y
  2. # rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-7.noarch RPM
  3. [plain] view plaincopy
Retrieving http://download.fedora.redhat.com/pub/epel/6/x86_64/epel-release-6-7.noarch.rpm

warning: /var/tmp/ rpm-tmp.00kiDx: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY Preparing...######################## ################### [100%]

1:epel-release ################## ######################## [100%]
  1. Install Nginx
  2. Enter the following command
  3. [plain] view plaincopy

#yum install nginx Output sample

    [plain] view plaincopy
    1. Dependencies Resolved  
    2.   
    3. ================================================================================  
    4.  Package                  Arch      Version                    Repository  Size  
    5. ================================================================================  
    6. Installing:  
    7.  nginx                    x86_64    0.8.54-1.el6               epel       358 k  
    8. Installing for dependencies:  
    9.  GeoIP                    x86_64    1.4.8-1.el6                epel       620 k  
    10.  fontconfig               x86_64    2.8.0-3.el6                base       186 k  
    11.  freetype                 x86_64    2.3.11-6.el6_1.8           updates    358 k  
    12.  gd                       x86_64    2.0.35-10.el6              base       142 k  
    13.  libX11                   x86_64    1.3-2.el6                  base       582 k  
    14.  libX11-common            noarch    1.3-2.el6                  base       188 k  
    15.  libXau                   x86_64    1.0.5-1.el6                base        22 k  
    16.  libXpm                   x86_64    3.5.8-2.el6                base        59 k  
    17.  libjpeg                  x86_64    6b-46.el6                  base       134 k  
    18.  libpng                   x86_64    2:1.2.46-1.el6_1           base       180 k  
    19.  libxcb                   x86_64    1.5-1.el6                  base       100 k  
    20.  libxslt                  x86_64    1.1.26-2.el6               base       450 k  
    21.  perl                     x86_64    4:5.10.1-119.el6_1.1       base        10 M  
    22.  perl-Module-Pluggable    x86_64    1:3.90-119.el6_1.1         base        37 k  
    23.  perl-Pod-Escapes         x86_64    1:1.04-119.el6_1.1         base        30 k  
    24.  perl-Pod-Simple          x86_64    1:3.13-119.el6_1.1         base       209 k  
    25.  perl-libs                x86_64    4:5.10.1-119.el6_1.1       base       575 k  
    26.  perl-version             x86_64    3:0.77-119.el6_1.1         base        49 k  
    27.   
    28. Transaction Summary  
    29. ================================================================================  
    30. Install      19 Package(s)  
    31. Upgrade       0 Package(s)  
    32.   
    33. Total download size: 14 M  
    34. Installed size: 47 M  
    35. Is this ok [y/N]: y  

    如果你想在系统启动时自动运行nginx,输入下列命令:

    [plain] view plaincopy

    1. # chkconfig --level 345 nginx on  

    第一次启动nginx,输入下列命令:

    [plain] view plaincopy

    1. # /etc/init.d/nginx start  

    输出样例

    [plain] view plaincopy

    1. Starting nginx:                                            [  OK  ]  

    安装PHP-FPM输入下列命令:

    [plain] view plaincopy

    1. # yum --enablerepo=remi install php php-fpm

    Output sample

    [plain] view plaincopy

    1. Dependencies Resolved  
    2.   
    3. ====================================================================================  
    4.  Package            Arch        Version                          Repository    Size  
    5. ====================================================================================  
    6. Installing:  
    7.  php                x86_64      5.3.10-2.el6.remi                remi         2.3 M  
    8.  php-fpm            x86_64      5.3.10-2.el6.remi                remi         1.1 M  
    9. Installing for dependencies:  
    10.  apr                x86_64      1.3.9-3.el6_1.2                  base         123 k  
    11.  apr-util           x86_64      1.3.9-3.el6_0.1                  base          87 k  
    12.  apr-util-ldap      x86_64      1.3.9-3.el6_0.1                  base          15 k  
    13.  httpd              x86_64      2.2.15-15.el6.centos.1           updates      813 k  
    14.  httpd-tools        x86_64      2.2.15-15.el6.centos.1           updates       70 k  
    15.  libedit            x86_64      2.11-4.20080712cvs.1.el6         base          74 k  
    16.  mailcap            noarch      2.1.31-2.el6                     base          27 k  
    17.  php-cli            x86_64      5.3.10-2.el6.remi                remi         2.2 M  
    18.   
    19. Transaction Summary  
    20. ====================================================================================  
    21. Install      10 Package(s)  
    22. Upgrade       0 Package(s)  
    23.   
    24. Total download size: 6.8 M  
    25. Installed size: 21 M  
    26. Is this ok [y/N]: y  

    If you want to run php-fpm automatically when the system starts, enter the following command:

    [plain] view plaincopy

    1. # chkconfig --level 345 php-fpm on

    PHP only installs the core module, you are likely to need to install other modules, such as MySQL, XML, GD, etc., you You can enter the following commands:

    [plain] view plaincopy

    1. # yum --enablerepo=remi install php-gd php-mysql php-mbstring php-xml php-mcrypt

    Start php-fpm for the first time, enter the following command:

    [plain] view plaincopy

    1. # /etc/init.d/php-fpm restart

    Output sample

    [plain] view plaincopy

    1. Starting php-fpm: Configure PHP-FPM and Nginx and let them Work together
    nginx configuration file is in /etc/nginx/nginx.conf , enter the following command to edit this file:

    [plain] view plaincopy View plaincopy

    1. ...
    2. location / {
    3. index index.html index.htm index.php;
    4. }
    5.                      … gi_pass 127.0.0.1:9000;
    6. fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $ document_root$fastcgi_script_name;
    7.                                                                                                                                                                                                                           document_root$fastcgi_script_
    8. Restarting Nginx will re-read the configuration file, enter
    9. [plain] view plaincopy
    10. # /etc/init.d/nginx reload
    11. Now create the following PHP file in the
    12. document root directory
    [plain] view plaincopy


    # vi /usr/share/nginx/html/info.php

    The file content is as follows:
    [plain] view plaincopy

      phpinfo();

    Nginx virtual host settingsSetup example

    IP: 192.168.1.113
      Domain: domain.local
    1. Hosted at: /home/www/domain.local
    2. Enter the following commands Create a new user named "www"
    [plain] view plaincopy
    # useradd www
    Create the necessary directories
    [plain] view plaincopy
    1. # mkdir -p /home/www/domain.local/public_html
    2. # mkdir -p /home/www/domain.local/log
    3. # chown -R www.www /home /www/
    4. # chmod 755 /home/www/

    Create virtual host configuration file

    [plain] view plaincopy

    1. # cd /etc/nginx/conf.d/
    2. # cp virtual.conf www.conf

    Enter the following command to open the www.conf file

    [plain] view plaincopy

    1. # vi /etc/nginx/conf.d/www.conf

    Add the following configuration

    [plain] view plaincopy

    1. server Access_log /home/www/domain.local/log/ domain.local-access.log;
    2.               error_log   /home/www/domain.local/log/domain.local-error.log;
    3.                                                                                                    ,,,,,,,,,,,,,,,,,,,, html index.htm index.php;
    4.                                                                                                                                                                                 gi_params;
    5.                                                                                                                                                                                                  ​fastcgi_index index.php;
    6.                                                                                                                                                                                                                                                                        
    7. You can use the following method to check whether the configuration file has syntax errors
    8. [plain] view plaincopy
    9. # /etc/init.d/nginx configtest
    10. Output sample
    11. [plain] view plaincopy
    12. the configuration file /etc/nginx/nginx.conf syntax is ok
    configuration file /etc/nginx/nginx.conf test is successful

    Now edit the /etc/php-fpm.d/www.conf file, change the user running the php-fpm process to "www", enter

    [plain] view plaincopy

    1. # vi /etc/php-fpm.d/www.conf
    Find "group of processes" and edit it as follows:

    [plain] view plaincopy

    1. ; Unix user/group of processes
    2. ; Note: The user is mandatory. will be used.
    3. ; RPM: apache Choosed to be able to access some dir as httpd
    4. user = www
    5. ; RPM: Keep a group allowed to write in log dir.
    6. group = www
    7. Finally restart nginx

    [plain] view plaincopy

    # /etc/init.d/nginx restart
    1. # /etc/init.d/php-fpm restart
    2. From: http://blog.csdn.net /seanchan/article/details/7680354
    The above introduces how to install Nginx and PHP-FPM through YUM on CentOS 6, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template