Installing Nginx and PHP ordeal under CentOS

Source: Internet
Author: User
In order to have a complete experience of the process, I installed the CentOS and Nginx, PHP, the middle of a lot of problems, notes.

The 1th step, of course, is to install VMware, which is nothing to say, step by step next is good;

The 2nd step is to create a new virtual machine and load the iOS image installation Centos6.3, this is not much to say, the online many graphic tutorials,
Note 1: When partitioning, I added a/home area, and I did not install GUI graphics environment, according to the installation of base server;
Note 2: After the installation is complete, I select the network mode is NAT, in the VMware Menu "edit" has a "virtual network Editor", select Nat mode, OK, and then open the host Windows machine local connection properties, open " Allow other network users to connect through this computer's Internet connection, so that the virtual machine can be connected to the Internet;
Note 3: After opening the share, there is a problem, that is, the Cisco VPN Client in Windows does not connect, cancel sharing, you can connect, connect, and then turn on sharing is not valid, only two select one to work.

3rd Step, configure some environments:
1, adjust the shell resolution (this step can not, I have access through the terminal after the command line input: vim/boot/grub/grub.conf,
Add Vga=ask at the end of the Kenel line so that each reboot will ask for resolution, and if you add vga=0x369, the terminal resolution is fixed to 1280*800

2, modify the IP, because the NAT gateway IP is 192.168.137.1 when Windows opens the share, so I set the CentOS IP to 192.168.137.8:

Edit the corresponding NIC configuration file, this machine is ifcfg-eth0:# vim/etc/sysconfig/network-scripts/ifcfg-eth0 content as follows Device=eth0 #描述网卡对应的设备别名BOOTPROTO = Static #设置获得ip方式, the possible options are static,dhcp or bootpbroadcast=192.168.137.255 #对应的子网广播地址ONBOOT =yesipaddr=192.168.137.8    # Set the network card static IP address netmask=255.255.255.0   #网卡对应的网络掩码GATEWAY =192.168.137.1   #网关IPDNS1 =114.114.114.114    #DNS1的IP
After modifying the IP, remember to restart the CentOS network with a command to make the IP effective
Service Network restart

Okay, the prep work is done, and we're going to start deploying the environment.

The 1th step, the simulation production system, added a work account, the command line is as follows:
Useradd work
passwd work here, you enter the new password for your work account and enter it 2 times.
Then add the work user to Sudoer

chmod u+w/etc/sudoers  First set sudoers file writable vim/etc/sudoers open sudoers file for editing, add "all= Kiwi (All) under" root all= (All) All ". chmod u-w/etc/sudoers  Revoke Write permission

2nd step, use Yum to install PHP and nginx php-fpm, command line as follows, follow the instructions step by step to confirm:
Yum Install PHP
Note: The next step is to set the source, otherwise you cannot install Nginx with Yum
RPM-IVH http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
Yum Install Nginx

3rd Step, configure Nginx running user and Web parameters
Nginx configuration file Location:/etc/nginx/nginx.conf First remove the include configuration from the configuration file,
Then change user nginx to user work, using working users to perform nginx process;
The server configuration in the HTTP configuration section is then as follows:

server {    listen       ;   # Listening Port    server_name  localhost; # host header, if there is only one server configuration, this host head ignores the location    /{# default path to        root   /home/work /web; # site Root        index  index.html index.htm; # site default home file    }    error_page   502 503    504/50x.html; Location =/50x.html {        root   /usr/share/nginx/html;    }    Location ~ \.php$ {# PHP request path regular        root    /home/work/web; # PHP request file root directory        fastcgi_pass   127.0.0.1:9000; PHP-FPM Listening Port        # The next line of $document_root is the root configuration above        fastcgi_param  script_filename  $document _root$ Fastcgi_script_name;         Include        fastcgi_params;    }}
Note: If you do not modify Nginx's running user, you may be reported a 403 error when accessing files under the site.
Strangely, without changing the user, I use the command chmod-r 777/home/work/webSet the maximum permissions, access to the site is still prompted 403 error, a warrior know?

4th step, configure the PHP-FPM User:
PHP-FPM configuration file Location:/etc/php-fpm.conf, there is a sentence: include=/etc/php-fpm.d/*.conf
Then open the included configuration file:/etc/php-fpm.d/www.conf, find User=apache, change it to user=work.
Note: If you do not modify the running user of the PHP-FPM, then when accessing the PHP file, will be reported: File not found error, the same I set the directory of 777 permissions also no, pit AH

5th step, start php-fpm service and Nginx service:
Service PHP-FPM Restart
Service Nginx Restart

All right, here we go. Configuration is complete, place a index.php file at the site, and then try it through the command line: Curl http://127.0.0.1/index.php.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.