Php7+nginx Configuration and installation tutorial PHP7 mysql php7 installation tutorial Ubuntu php

Source: Internet
Author: User
Tags configuration php php session php error php error log zts automake
System environment: centos6.5 x64

Software version: nginx-1.10.0 php-7.0.6

Installing Nginx

Nginx Official website: http://nginx.org/

Install some components that are dependent on compilation first

Yum install pcre pcre-devel OpenSSL openssl-devel-y

1. Unpacking the Package

Tar XF nginx-1.10.0.tar.gz CD nginx-1.10.0

2. Pre-compile configuration parameters

./configure--user=www \--group=www \--prefix=/data/server/nginx \--with-http_stub_status_module \-- Without-http-cache \--with-http_ssl_module \--with-http_gzip_static_module

3. Perform compilation

Make && make install

4. Replace the configuration file

Nginx.conf

User www www;worker_processes 1;error_log/u01/data/log/nginx/error.log crit;pid/u01/data/server/nginx/logs/ Nginx.pid; #Specifies the value for maximum file descriptors the can is opened by this process.worker_rlimit_nofile 65535; Events{use epoll;worker_connections 65535;} HTTP {include Mime.types;default_type application/octet-stream; #charset gb2312;server_names_hash_bucket_size 128; Client_header_buffer_size 32k;large_client_header_buffers 4 32k;client_max_body_size 8m;sendfile on;tcp_nopush on; Keepalive_timeout 60;tcp_nodelay on;fastcgi_connect_timeout 300;fastcgi_send_timeout 300;fastcgi_read_timeout 300; Fastcgi_buffer_size 64k;fastcgi_buffers 4 64k;fastcgi_busy_buffers_size 128k;fastcgi_temp_file_write_size 128k;gzip On;gzip_min_length 1k;gzip_buffers 4 16k;gzip_http_version 1.0;gzip_comp_level 2;gzip_types text/plain application/ X-javascript text/css application/xml;gzip_vary on; #limit_zone crawler $binary _remote_addr 10m;log_format main ' $ REMOTE_ADDR-"$request _time" [$time _locaL] "$request" "$status" $body _bytes_sent "$http _referer" "$http _user_agent" $http _x_forwarded_for '; Log_format ' $ remote_addr-$remote _user [$time _local] "$request" "$status $body _bytes_sent" $http _referer "" "$http _user_agent" $ Http_x_forwarded_for "$request _time"; include/u01/alidata/server/nginx/conf/vhosts/*.conf;


Virtual Host profile Template


server {Listen 8080;server_name localhost;index index.html index.htm index.php;root/u01/data/www;location ~. *\. ( PHP|PHP5)? ${fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;fastcgi_index index.php;include fastcgi.conf;} Location ~. *\. (gif|jpg|jpeg|png|bmp|swf) ${expires 30d;} Location ~. *\. (JS|CSS)? ${expires 1h;} # # #this is the use of open website Lianjie like on apache# #location/{if (!-e $request _filename) {rewrite ^ (. *) $/index.php?s =$1 Last;break;}} Location ~/.svn/{deny all;} # # # #end # #access_log/u01/data/log/nginx/access/test.log main;}


5. Provide nginx startup script


#!/bin/bash#nginxd=/u01/data/server/nginx/sbin/nginxnginx_config=/u01/data/server/nginx/conf/nginx.confnginx_ pid=/u01/data/server/nginx/logs/nginx.pidretval=0prog= "Nginx" [-X $nginxd] | | Exit 0# Start Nginx daemons Functions.start () {If [-e $nginx _pid] && netstat-tunpl | grep nginx &>/dev/ Null;thenecho "Nginx already running ..." Exit 1fiecho-n $ "Starting $prog!"  $nginxd-C ${nginx_config}retval=$?echo[$RETVAL = 0] && touch/var/lock/nginxreturn $RETVAL}# Stop nginx daemons Functions.stop () {echo-n $ "stopping $prog!" $nginxd-S stopretval=$?echo[$RETVAL = 0] && rm-f/var/lock/nginx}# reload Nginx Service Functions.reload () {EC Ho-n $ "Reloading $prog!" Stop () {echo-n $ "stopping $prog!" $nginxd-S stopretval=$?echo[$RETVAL = 0] && rm-f/var/lock/nginx}# reload Nginx Service Functions.reload () {EC Ho-n $ "Reloading $prog!" #kill-hup ' cat ${nginx_pid} ' $nginxd-s reloadretval=$?echo}# See how we were Called.case "$" instart) start; stop) stop;; reload) reload;; restart) Stopstart;; *) echo $ "Usage: $prog {start|stop|restart|reload|help}" exit 1esacexit $RETVAL

You just need to modify the program path to use it immediately.

Installing PHP7

PHP Official website: http://php.net/

PHP Extension: http://pecl.php.net/

Install some build-dependent builds first

Yum-y install gcc gcc-c++ gcc-g77 make libtool autoconf patch unzip automake libxml2 libxml2-devel ncurses ncurses-devel Libtool-ltdl-devel Libtool-ltdl libmcrypt libmcrypt-devel libpng libpng-devel libjpeg-devel OpenSSL Openssl-devel Curl Curl-devel libxml2 libxml2-devel ncurses ncurses-devel libtool-ltdl-devel libtool-ltdl autoconf automake libaio*

1. Unpacking the Package

Tar XF php-7.0.6.tar.bz2cd php-7.0.6

2, install the compilation dependent picture library

Jpegsrc.v6b.tar.gzlibpng-1.2.50.tar.gzfreetype-2.1.10.tar.gz
# install jpegsrc.v6b.tar.gz# This need to create a folder to store the program before the error mkdir/usr/local/jpeg.6/{bin,lib,include,man/man1}-pvtar XF jpegsrc.v6b.tar.gz CD jpeg-6b/./configure--prefix=/usr/local/jpeg.6/make && make install# installation Libpng-1.2.50.tar.gztar XF LIBPNG-1.2.50.TAR.GZCD libpng-1.2.50./configure--prefix=/usr/local/libpng.1.2.50make && make install# install Freetype-2.1.10.tar.gztar XF freetype-2.1.10.tar.gzcd freetype-2.1.10./configure--prefix= /usr/local/freetype.2.1.10/make && make Install


3. Pre-compile configuration parameters

./configure--prefix=/data/server/php \--enable-opcache \--with-config-file-path=/u01/data/server/php/etc \-- Enable-mysqlnd \--with-mysqli=mysqlnd \--with-pdo-mysql=mysqlnd \--enable-fpm \--enable-static \-- Enable-inline-optimization \--enable-sockets \--enable-wddx \--enable-zip \--enable-calendar \--with-gd \-- With-iconv \--with-openssl \--with-zlib \--enable-bcmath \--enable-soap \--with-xmlrpc \--enable-mbstring \-- enable-shared \--with-curl \--enable-xml \--enable-ftp \--with-mcrypt \--with-mhash \--enable-shmop \--enable-sysvsem \--enable-mbregex \--enable-gd-native-ttf \--enable-pcntl \--enable-session \--with-gettext \--with-freetype-dir=/ usr/local/freetype.2.1.10 \--with-jpeg-dir=/usr/local/jpeg.6 \--with-png-dir=/usr/local/libpng.1.2.50 \-- Disable-ipv6 \--disable-debug \--disable-maintainer-zts \--disable-rpath \--disable-fileinfo \--without-gdbm \


4. Perform compilation

Make && make install

5. Provide php.ini file

CP Php.ini-production/u01/data/server/php/etc/php.ini

Configure PHP.ini


# Around 840 lines-set PHP opcache and memcache Extension library zend_extension=opcache.soextension=memcache.so# 722 rows or so-set PHP extension library path Extension_ dir = "/u01/data/server/php7/lib/php/extensions/no-debug-non-zts-20151012/" # to prevent PHP information from being exposed in the HTTP header expose_php = Off# Avoid exposing PHP error messages called MySQL display_errors = off# open PHP error log (path is configured in php-fpm.conf) log_errors = on# set php time zone Date.timezone = prc# Turn on Opcache (about 1733 rows) opcache.enable=1# set PHP script to allow access to the directory # open_basedir =/usr/share/nginx/html;


6, Configuration php-fpm

php-fpm.conf Process Service Master configuration file

# Set the error log path error_log =/var/log/php-fpm/error.log# Introduce the configuration in the www.conf file include=/usr/local/php7/etc/php-fpm.d/*.conf#  Set the maximum number of files opened by the main process rlimit_files = 102400www.conf Process Service Extension profile # Set user and user group users = wwwgroup = www# Set PHP listener Mode # listen = 127.0.0.1:9000 # Note that this is to set the permissions of the PHP socket file, which is Root,nginx inaccessible by default. Listen =/var/run/php-fpm/php-fpm.sock# Open Slow Log slowlog =/var/log/php-fpm/php-slow.logrequest_slowlog_timeout = 10s# Set number of worker processes (set according to the actual situation) Pm.max_children = 50# Here, it is important to note that Pm.start_servers cannot be less than pm.min_spare_serverspm.start_servers = 5pm.min_ Spare_servers = 5pm.max_spare_servers = 10pm.max_requests = 10240# Set PHP Session Directory (both the owning user and the user group are WWW) php_value[ Session.save_handler] = Filesphp_value[session.save_path] =/var/tmp/php/session


7. Provide php-fpm startup script

#! /bin/sh#prefix=/u01/data/server/php7exec_prefix=${prefix}php_fpm_bin=${exec_prefix}/sbin/php-fpmphp_fpm_conf=$ {prefix}/etc/php-fpm.confphp_fpm_pid=${prefix}/var/run/php-fpm.pidphp_opts= "--fpm-config $php _fpm_conf--pid $php _fpm_pid "Wait_for_pid () {try=0while test $try-lt, docase" $ "in ' created ') if [-F" $ "]; Thentry= ' BREAKFI; Removed ') if [!-F "$"]; Thentry= ' BREAKFI; Esacecho-n. try= ' expr $try + 1 ' sleep 1done}case "$" instart) echo-n "Starting php-fpm" $php _fpm_bin--daemonize $php _opt SIF ["$?"! = 0]; Thenecho "Failed" exit 1fiwait_for_pid created $php _fpm_pidif [-N "$try"]; Thenecho "Failed" Exit 1elseecho "Done" FI; Stop) echo-n "Gracefully shutting down php-fpm" if [! -R $php _fpm_pid]; Thenecho "Warning, no PID file found-php-fpm is not running?" Exit 1fikill-quit ' cat $php _fpm_pid ' wait_for_pid removed $php _fpm_pidif [-N ' $try "]; Thenecho "failed. Use Force-quit "Exit 1elseecho" Done "FI;; status) if [!-R $php _fpm_pid]; Thenecho "PHP-FPM is stopped "Exit 0fipid= ' cat $php _fpm_pid ' if ps-p $PID | Grep-q $PID; Thenecho "PHP-FPM (PID $PID) is running ..." Elseecho "php-fpm dead but PID file exists" FI; Force-quit) echo-n "terminating php-fpm" if [! -R $php _fpm_pid]; Thenecho "Warning, no PID file found-php-fpm is not running?" Exit 1fikill-term ' cat $php _fpm_pid ' wait_for_pid removed $php _fpm_pidif [-N ' $try "]; Thenecho "Failed" Exit 1elseecho "Done" FI; restart) stop$0 start; Reload) echo-n "Reload service php-fpm" if [! -R $php _fpm_pid]; Thenecho "Warning, no PID file found-php-fpm is not running?" Exit 1FIKILL-USR2 ' cat $php _fpm_pid ' echo ' done ';; *) echo "Usage: $ Start|stop|force-quit|restart|reload|status}" exit 1;; Esac

Eight, start the PHP-FPM program

/ETC/INIT.D/PHP-FPM start# Modify Socket file permissions Chown-r/var/run/php-fpm/

The above is Php7+nginx configuration and installation tutorial detailed PHP7 mysql php7 installation tutorial ubuntu PHP content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • 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.