How to install nginx and php in centos-php Tutorial

Source: Internet
Author: User
Install nginx and php in centos: in order to have a complete experience, I installed centos, nginx, and php on my own. There were a lot of problems in the process, and I kept a note.

Step 3 is to install Vmware. there is nothing to say about it. just click next step;

Step 2 is to create a new virtual machine and load the ios image to install Centos6.3. this is nothing to mention. There are many graphic tutorials on the Internet,
Note 1: When partitioning, I added a/home area, and I did not install the gui graphical environment. I installed it by base server;
Note 2: After the installation is complete, the network mode I select is NAT. in the "edit" menu of VmWare, there is a "virtual network editor". select NAT mode and click OK, then, enable the local connection attribute of the host Windows machine and enable "allow other network users to connect through the Internet connection of this computer", so that the virtual machine can access the Internet;
Note 3: After sharing is enabled, a problem occurs, that is, the Cisco VPN client in Windows cannot be connected. if sharing is canceled, the connection can be established. if sharing is enabled again, it is invalid, you can only select either of them for work.

Step 2: configure some environments:
1. adjust the Shell resolution (this step can be done or not, and I will access it through the terminal later). enter vim/boot/grub. conf in the command line,
Add vga = ask at the end of the kenel line so that the resolution will be queried every restart. if vga = 0x369 is added, the terminal resolution is fixed to 1280*800.

2. modify the IP address. because the Nat gateway IP address is 192.168.137.1 after sharing is enabled in Windows, set the Centos IP address to 192.168.137.8:

Edit the corresponding Nic configuration file, the local is the ifcfg-eth0: # vim/etc/sysconfig/network-scripts/the content of the ifcfg-eth0 is as follows DEVICE = eth0 # describe the DEVICE alias for the Nic BOOTPROTO = static # set to obtain the ip address, the possible option is static, dhcp or bootpBROADCAST = 192.168.137.255 # corresponding subnet broadcast address ONBOOT = yesIPADDR = 192.168.137.8 # set the Nic static IP address NETMASK = 255.255.255.0 # network mask GATEWAY = 192.168.137.1 # GATEWAY IPDNS1 = subnet # DNS1 IP
After modifying the IP address, remember to use the command to restart the Centos network for the IP address to take effect.
Service network restart

Now, the preparations are complete. you have to start deploying the environment.

Step 2. create a work account in the simulated production system. the command line is as follows:
Useradd work
Passwd work: Enter the new password of the work account twice.
Then add the work User to sudoer.

Chmod u + w/etc/sudoers first set the sudoers file to write vim/etc/sudoers to open the sudoers file and edit it. in "root ALL = (ALL) add "kiwi ALL = (ALL) ALL" under "ALL ". chmod u-w/etc/sudoers revoke write permission

Step 2. use yum to install php and nginx php-fpm. the command line is as follows and confirm step by step as instructed:
Yum install php
Note: The next step is to set the source; otherwise, nginx cannot be installed in yum.
Rpm-ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
Yum install nginx

Step 2: configure the nginx running user and web parameters
Nginx configuration file location:/etc/nginx. conf first remove the include configuration in the configuration file,
Then, change the user nginx to user work and use the work user to execute the nginx process;
The server configuration in the http configuration section is as follows:

Server {listen 80; # listener Port server_name localhost; # host header. if only one server is configured, the host header will ignore location/{# default path pointing to root/home/work/web; # site root directory index index.html index.htm; # default homepage file of the site} error_page 500 502 503 504/50 x.html; location =/50x.html {root/usr/share/nginx/html;} location ~ \. Php $ {# php request path regular root/home/work/web; # fastcgi_pass 127.0.0.1: 9000 in the php request file root directory; # php-fpm listening port # $ document_root in the next line is the above root configuration fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name; include fastcgi_params ;}}
Note: If you do not modify the running user of nginx, the error 403 may be reported when accessing files under the site.
The strange thing is that I use the command Chmod-R 777/home/work/webIf the maximum permission is set, the error 403 still appears when accessing the site. do you know this?

Step 3: configure the php-fpm running User:
Php-fpm configuration file location:/etc/php-fpm.conf, which has a sentence: include =/etc/php-fpm.d/*. conf
Open the contained configuration file:/etc/php-fpm.d/www. conf, find user = apache, change it to user = work
Note: If you do not modify the php-fpm running user, the system will always report the File not found error when accessing the php File. Similarly, I cannot set the 777 permission for the directory.

Step 3: Start the php-fpm service and nginx service:
Service php-fpm restart
Service nginx restart

Now, the configuration is complete. place an index. php file on the site, and use the command line: curl http: // 127.0.0.1/index. php to access the file.

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.