CentOS7 Configuring Nginx PHP php-fpm

Source: Internet
Author: User
Tags install php imap

The previous article said that installing PHP

After loading, there is no setup, this record is set. First set Nginx, Nginx online more like the stars of the settings but mostly simple, is the basic settings, so here only post the results of the set, with a red box to indicate some of their own changes or need to pay attention to the place

Nginx Basic setup is simple, set three times more than can be directly remembered. I configured the default display path for 400, 500 series errors, 404, 403 Errors are displayed 40x.html,500 several errors are displayed 50x.html error, so that the page can be defined by itself. For example, now 404 will show a page like this

Start Nginx encounters an episode

Because it is a compiled installation, it is started after installation

CD /usr/local/./nginx

Today, when I write a configuration, I find the online word can't start.

Start Nginx

Baidu Dafa Let's write a script, OK, write, open vim

#!/bin/SH# #nginx-this script starts and stops the Nginx daemon# chkconfig:-Description:nginx # is an HTTP (s) server, HTTP (s) reverse \ # Proxy and imap/POP3 Proxy Server#Processname:nginx# Config:/etc/nginx/nginx.conf# config:/etc/sysconfig/Nginx# Pidfile:/var/Run/nginx.PID# Source function library. . /etc/rc.d/init.d/functions# Source Networking configuration. . /etc/sysconfig/Network# Check that networking are up. [ "$NETWORKING" = "No"] &&Exit0Nginx= "/usr/local/nginx/sbin/nginx"Prog=$ (basename $nginx)Nginx_conf_file= "/usr/local/nginx/conf/nginx.conf"[-F/etc/sysconfig/nginx] &&. /etc/sysconfig/Nginx Lockfile=/var/lock/subsys/NginxStart(){[-X$nginx] | |Exit5[-F$NGINX _conf_file] | |Exit6Echo-N $ "Starting $prog:"Daemon$nginx-C $nginx_conf_file retval=$? Echo     [ $retval-eq 0] && Touch $Lockfilereturn$retval} Stop() {     Echo-N $ "stopping $prog:"Killproc$prog-quit retval=$? Echo     [ $retval-eq 0] && rm-f $Lockfilereturn$retval Killall-9Nginx} Restart(){configtest | |return$? Stop Sleep1Start} Reload(){configtest | |return$? Echo-N $ "reloading $prog:"Killproc$nginx-hup RETVAL=$? Echo} force_reload(){restart} configtest() { $nginx-T-C $Nginx_conf_file} rh_status(){Status$Prog} rh_status_q(){rh_status>/dev/null 2>&1} case"$"inchStart)rh_status_q &&Exit0 $;;Stop)Rh_status_q | |Exit0 $;;restart|configtest) $ n;;Reload)Rh_status_q | |Exit7 $;;Force-reload)Force_reload;;Status)Rh_status;;Condrestart|try-restart)Rh_status_q | |Exit0;;     *)Echo$ "Usage: $ {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"Exit2Esac#!/bin/SH# #nginx-this script starts and stops the Nginx daemon# chkconfig:-Description:nginx # is an HTTP (s) server, HTTP (s) reverse \ # Proxy and imap/POP3 Proxy Server#Processname:nginx# Config:/etc/nginx/nginx.conf# config:/etc/sysconfig/Nginx# Pidfile:/var/Run/nginx.PID# Source function library. . /etc/rc.d/init.d/functions# Source Networking configuration. . /etc/sysconfig/Network# Check that networking are up. [ "$NETWORKING" = "No"] &&Exit0Nginx= "/usr/local/nginx/sbin/nginx"Prog=$ (basename $nginx)Nginx_conf_file= "/usr/local/nginx/conf/nginx.conf"[-F/etc/sysconfig/nginx] &&. /etc/sysconfig/Nginx Lockfile=/var/lock/subsys/NginxStart(){[-X$nginx] | |Exit5[-F$NGINX _conf_file] | |Exit6Echo-N $ "Starting $prog:"Daemon$nginx-C $nginx_conf_file retval=$? Echo     [ $retval-eq 0] && Touch $Lockfilereturn$retval} Stop() {     Echo-N $ "stopping $prog:"Killproc$prog-quit retval=$? Echo     [ $retval-eq 0] && rm-f $Lockfilereturn$retval Killall-9Nginx} Restart(){configtest | |return$? Stop Sleep1Start} Reload(){configtest | |return$? Echo-N $ "reloading $prog:"Killproc$nginx-hup RETVAL=$? Echo} force_reload(){restart} configtest() { $nginx-T-C $Nginx_conf_file} rh_status(){Status$Prog} rh_status_q(){rh_status>/dev/null 2>&1} case"$"inchStart)rh_status_q &&Exit0 $;;Stop)Rh_status_q | |Exit0 $;;restart|configtest) $ n;;Reload)Rh_status_q | |Exit7 $;;Force-reload)Force_reload;;Status)Rh_status;;Condrestart|try-restart)Rh_status_q | |Exit0;;     *)Echo$ "Usage: $ {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"Exit2Esac

And then execute

: w /etc/init.d/nginx: Q755/etc/init.d/nginxsudo chkconfig--add nginx

When you are finished, you can use the following command to operate the Nginx (there are also episodes)

#start# Stop nginx Services sudo service nginx Stop# uninterrupted service restart sudo service nginx reload
The episode I'm going to describe is after the script has been edited, the command appears to be unable to stop nginx, after the execution of the command can still be browsed, can be through the form of sudo kill-quit nginx shutdown

Go ahead and install the PHP-FPM component.

sudo yum install php-fpm

Edit the/etc/php.ini (the configuration file under the Linux under the Spit slot in this position?) )

#/etc/php.ini/etc/php.ini. Backup  /etc/php. INI/cgi. ;
: Wq

Configure www.conf

#自愿备份一下 www.  /etc/php.fpm.d/www.conf/etc/php-fpm.d/www.conf. Backup  /etc/php.fpm.d/www. conf#将 user = xxxx to user = already existing privileged users #将 grouip = xxx to group = already existing privileged group #以上两句是百度出来的, in the virtual machine I changed the current user name on the

Start php-fpm and (Heavy) Start Nginx in turn

Start php-fpm# set php-fpm boot #sudo systemctl enable Php-fpmsudo systemctl restart Nginx

The episode here is that I encountered an error when I exited with the Kill-quit Nginx and then used the service start Nginx.

Then use Systemctl start Nginx boot, but a moment will also appear prompt

It's unclear so, but PHP can run.

Some records and Links:

    • Reference "Nginx startup failed failed to reload Nginx.service:Unit not found": http://blog.csdn.net/wangjinbao5566/article/details/72938783
    • Refer to "Configuring Nginx to support PHP under CentOS": http://www.cnblogs.com/mitang/p/5524540.html
    • Refer to "Centos7 Installation and Configuration nginx+php": http://www.cnblogs.com/cglWorkBook/p/5431571.html
    • Refer to "How to properly configure Nginx and PHP": http://blog.jobbole.com/50121/

CentOS7 Configuring Nginx PHP php-fpm

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.