LNMP source code compilation and installation

Keywords: Nginx MySQL PHP zlib

Linux system is CentOS 6.7

Start preparations

Switch to Package Directory

cd /usr/local/src

Clean up installed packages

rpm -e httpd
rpm -e mysql
rpm -e php
yum -y remove httpd
yum -y remove mysql
yum -y remove php

#Search apache packages
rpm -qa http*

#Mandatory unloading of apache packages
rpm -e --nodeps File name queried

#Check whether unloading is clean
rpm -qa|grep http*

selinux may cause compilation and installation to fail. Let's disable it first. Permanent Ban, Need to Restart Effectiveness

sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
Temporarily disabled without restarting setenforce 0

Installation of necessary tools

yum -y install make gcc gcc-c++ gcc-g77 flex bison file libtool libtool-libs autoconf kernel-devel libjpeg libjpeg-devel libpng libpng-devel libpng10 libpng10-devel gd gd-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glib2 glib2-devel bzip2 bzip2-devel libevent libevent-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel gettext gettext-devel ncurses-devel gmp-devel pspell-devel unzip libcap lsof


Install MySQL 5.6.17

Create users and user groups for mysql according to standard requirements

#Create Group
groupadd mysql
#Create a user that does not allow login and does not create a home directory 
useradd -s /sbin/nologin -g mysql -M mysql
#Check Create User
tail -1 /etc/passwd
Delete the mysql database that comes with the system

Check installation or not
rpm -qa|grep mysql 
Forced Uninstall 
rpm -e mysql-libs-5.1.73-3.el6_5.x86_64 --nodeps
* Do not do this if the mysql database is not installed in the system

MySQL has been compiled and configured with. / configure since version 5.5 and has been replaced by the cmake tool. Therefore, we first need to install the cmake tool in the system source code compilation.

wget http://www.cmake.org/files/v2.8/cmake-2.8.12.2.tar.gz 
tar zxvf cmake-2.8.12.2.tar.gz 
cd cmake-2.8.12.2 
./configure 
make && make install

Use cmake to compile and install MySQL 5.6.17

wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.17.tar.gz
tar zxvf mysql-5.6.17.tar.gz
cd mysql-5.6.17
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DMYSQL_USER=mysql \
-DWITH_DEBUG=0 \
-DWITH_SSL=system
make && make install

Modify / usr/local/mysql permissions

chmod +w /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql

About my.cnf configuration file:

When launching MySQL service, I will search my.cnf in a certain order. If I can't find it, I will search it in the / etc directory. If I can't find it, "$basedir/my.cnf" is the default location of the new version of MySQL configuration file under the installation directory, / usr/local/mysql/my.cnf! Note: After the minimum installation of the CentOS 6.x operating system, there will be a my.cnf in the / etc directory, which needs to be renamed by another name. For example: / etc/my.cnf.bak, otherwise, the file will interfere with the correct configuration of MySQL installed in the source code, causing it to be unable to start. Since we have uninstalled the minimum installed mysq library, there is no need to operate.


Enter the support-files directory

cd support-files/
If you still have my.cnf, please backup
mv /etc/my.cnf /etc/my.cnf.bak
 If you like, you can also copy the configuration file to etc
cp my-default.cnf /etc/my.cnf
Execute the initialization configuration script, create the database and tables that come with the system, and pay attention to the path of the configuration file

/usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
Copy the support-files service script from the mysql installation directory to the init.d directory

#Copy script
cp support-files/mysql.server /etc/init.d/mysqld
#Grant authority
chmod +x /etc/init.d/mysqld

Set up boot start

chkconfig mysqld on
//Start MySQL
service mysqld start
//perhaps
/etc/init.d/mysql start
After mysql 5.6.x started successfully, root defaults to no password, we need to set the root password. Before setting up, we need to set up PATH, or mysql cannot be called directly.

Modify / etc/profile file
vi /etc/profile
 Add at the end of the file
PATH=/usr/local/mysql/bin:$PATH
export PATH
Let configuration take effect immediately

source /etc/profile
Login test, default is no password, direct return can enter

mysql -uroot -p

Setting mysql password

/usr/local/mysql/bin/mysqladmin -uroot -p password 'Your password'

Log-in command line mode

mysql -uroot -p
View Users

select user,host from mysql.user;
Delete unnecessary users

drop user ""@localhost;
drop user ""@c65mini.localdomain; 
drop user root@c65mini.localdomain; 
drop user root@'::1';

Give remote access to accounts

GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1' IDENTIFIED BY 'Your password' WITH GRANT OPTION; 
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'Your password' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'c65mini.localdomain' IDENTIFIED BY 'Your password' WITH GRANT OPTION;
Default root user reference for deleting MySQL: http://blog.chinaunix.net/uid-16844903-id-3377690.html
Other information queries: check the mysql version

mysql -uroot -p"Password" -e "select version();"
Verify mysql installation path

ls -ld /usr/local/mysql/

Install PHP 5.5.12

Installation dependencies

The libiconv library provides a function of iconv() for applications that need to be converted to achieve the conversion from one character encoding to another character encoding. Error prompt: configure: error: Please reinstall the iconv library.

wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
tar zxvf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local/libiconv
make && make install
cd ..

libmcrypt is an extended library of encryption algorithms. Error prompt: configure: error: Cannot find imap library (libc-client.a). Please check your c-client installation.

wget http://iweb.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make && make install
cd ..

mhash is a non-reversible php encryption expansion Library Based on Discrete Mathematics principle, and it does not open by default. mhash can be used to create validation values, message digests, message authentication codes, and save error prompts without the need for the original key information: configure: error:"You need at least libmhash 0.8.15 to compile this program. http://mhash.sf.net/"

wget http://hivelocity.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.bz2
tar jxvf mhash-0.9.9.9.tar.bz2
cd mhash-0.9.9.9
./configure
make && make install
cd ..
wget Packet may be wrong when downloading a package address to the official website: https://sourceforge.net/projects/mhash/?Source=type_redirect

Mcrypt is an important encryption support extension library in php. mrypt extension library can realize encryption and decryption function, that is, it can encrypt plaintext and restore ciphertext.

wget http://iweb.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
./configure
make && make install
cd ..

Compiling mcrypt may cause errors: configure: error: *** libmcrypt was not found

vi  /etc/ld.so.conf
#Last line adds
/usr/local/lib/
#wq save
#load
ldconfig

Compiling mcrypt may cause errors: / bin/rm: cannot remove `libtool T': No such file or directory

Modify the configuration file and change RM='$RM'to RM='$RM-f'. There must be a space after $RM. If there is no space in the back, the minus sign will be directly connected, and the error will still be reported.

Start compiling php!

wget http://mirrors.sohu.com/php/php-5.5.12.tar.gz
tar zxvf php-5.5.12.tar.gz
cd php-5.5.12
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-magic-quotes --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts
make && make install
When compiling, there may be some extensions that have been discarded. You can not install them. Compile and install the hints after installation.

Modify the FPM configuration php-fpm.conf.default file name

cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
Copy the php.ini configuration

cp php.ini-production /usr/local/php/etc/php.ini
Copy php-fpm startup script to init.d

cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
Give executive authority

chmod +x /etc/init.d/php-fpm
Add as startup item

chkconfig php-fpm on
Create a specified user and group for php-fpm according to the standard

#Create Group
groupadd www
#Create a user that does not allow login and does not create a home directory 
useradd -s /sbin/nologin -g www -M www
Start php-fpm immediately

service php-fpm start
#perhaps
/etc/init.d/php-fpm start

Back to / usr/local/src / directory

cd /usr/local/src

Install nginx 1.7

Generally, we need to install pcre, zlib to rewrite and gzip to compress the dependencies required by nginx. It doesn't matter if the system has yum installed these libraries, no uninstallation is required. Just compile and install the latest ones. To complete the compilation at once, prepare to compile the following dependencies first!

1. Installing the PCR E Library

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.35.tar.gz 
tar -zxvf pcre-8.35.tar.gz
cd pcre-8.35
./configure
make && make install
ps:wget package may have an invalid address. Download a package address directly to the official website: https://sourceforge.net/projects/pcre/files/pcre/8.35/pcre-8.35.tar.gz/download.


2. Install zlib Library

wget http://zlib.net/zlib-1.2.8.tar.gz
tar -zxvf zlib-1.2.8.tar.gz
cd zlib-1.2.8
./configure
make && make install
wget package may not exist when the next package to the official website, http://www.zlib.net/zlib-1.2.11.tar.gz, pay attention to download the version of the package, the above decompression package, switch directory appropriate modification

3. Install ssl

#I don't install the compiler because when compiling nginx, I just need to make it in the openssl directory.
wget http://www.openssl.org/source/openssl-1.0.1g.tar.gz
tar -zxvf openssl-1.0.1g.tar.gz
4. Installing ngx_pagespeed library ngx_pagespeed is an extension module of Nginx, which can speed up your website and reduce page loading time. It will automatically apply some practices of improving web performance to web pages and related resources (CSS, JS and pictures), without requiring you to modify the content and process.

	According to Google, the ngx_pagespeed module has been used by some customers in the production environment, including MaxCDN, the CDN provider. According to its report, the module reduces the average page load time by 1.57 seconds, the jump-out rate by 1% and the exit percentage by 2.5%. Zippy Kid, a host service for WordPress, said that after using PageSpeed in NGINX, "page size has been reduced by 75% and page rendering time has been increased by 50%.
wget https://github.com/pagespeed/ngx_pagespeed/archive/v1.8.31.2-beta.zip
unzip v1.8.31.2-beta.zip
cd ngx_pagespeed-1.8.31.2-beta/
wget https://dl.google.com/dl/page-speed/psol/1.8.31.2.tar.gz
tar -xzvf 1.8.31.2.tar.gz


5. Optimize nginx and mysql using TCMalloc tools provided by google-perftools

TCMalloc (google-perftools) is a multithreaded application for optimizing C++ writing, faster than glibc 2.3 malloc. This module can be used to make MySQL memory usage more stable under high concurrency.

TCMalloc is one of the tools of google-perftools, which is used to optimize the efficiency and speed of memory allocation and help control memory usage in high concurrency.

In mysql and nginx performance optimization schemes, most tutorials use TCMalloc tools provided by google-perftools. TCMalloc is much more efficient and faster in memory allocation than malloc.

Error tip: configure: error: No frame pointers and no libunwind. The compilation will fail because you started compiling gperftools without installing the libunwind library, so you must first libunwind

wget http://download.savannah.gnu.org/releases/libunwind/libunwind-1.1.tar.gz 
tar zxvf libunwind-1.1.tar.gz 
cd libunwind-1.1 
CFLAGS=-fPIC ./configure 
make CFLAGS=-fPIC 
make CFLAGS=-fPIC install

According to the official instructions, the latest version must be selected.

wget https://googledrive.com/host/0B6NtGsLhIcf7MWxMMF9JdTN3UVk/gperftools-2.2.tar.gz 
tar zxvf gperftools-2.2.tar.gz 
cd gperftools-2.2 
./configure 
make && make install


google is walled and can only download packages through GitHub at https://github.com/gperftools/gperftools/releases


Preparations are complete. Now start installing nginx! Here we add the library relationship we prepared earlier, pay attention to the path!

There are two ways of installation.

1: The following is the optimized installation, which includes the fourth and fifth steps of nginx installation.

2: Just install nginx and run with php.

Method 1:

wget http://nginx.org/download/nginx-1.7.0.tar.gz
tar zxvf nginx-1.7.0.tar.gz
cd nginx-1.7.0
./configure \
--user=www \
--group=www \
--prefix=/usr/local/nginx \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_gzip_static_module \
--with-pcre=/usr/local/src/pcre-8.35 \
--with-zlib=/usr/local/src/zlib-1.2.8 \
--with-openssl=/usr/local/src/openssl-1.0.1g \
--add-module=/usr/local/src/ngx_pagespeed-1.8.31.2-beta \
--with-google_perftools_module
cd ..

6. Modify nginx.conf configuration file

Open the ngx_pagespeed module in the server block

pagespeed on; 
pagespeed FileCachePath /var/ngx_pagespeed_cache;

location ~ ".pagespeed.([a-z].)?[a-z]{2}.[^.]{10}.[^.]+" { add_header "" ""; } 
location ~ "^/ngx_pagespeed_static/" { } 
location ~ "^/ngx_pagespeed_beacon$" { } 
location /ngx_pagespeed_statistics { allow 127.0.0.1; deny all; } 
location /ngx_pagespeed_global_statistics { allow 127.0.0.1; deny all; } 
location /ngx_pagespeed_message { allow 127.0.0.1; deny all; } 
location /pagespeed_console { allow 127.0.0.1; deny all; }
Turn on google_perftools Tuning Support
#Create tcmalloc in tmp first
mkdir /tmp/tcmalloc
#Grant authority
chmod 0777 /tmp/tcmalloc/
#Usually we add it under pid
google_perftools_profiles /tmp/tcmalloc;
#It must be restarted. Timely loading of the configuration will not take effect. The nginx restart script is listed below.
service nginx restart
Verify that tcmalloc is running, which is the effect of only one worker_processes turned on

[root@bin2aliyun ~]# lsof -n|grep tcmalloc
nginx     24471   www   16w      REG              202,1         0     821485 /tmp/tcmalloc/.24471
TCMalloc (google-perftools) can be used to make MySQL memory usage more stable under high concurrency.
Start adding in mysqld_safe script file
vi /usr/local/mysql/bin/mysqld_safe
LD_PRELOAD="/usr/local/lib/libtcmalloc.so"
service mysql restart

Use xcache to optimize php performance.

wget http://xcache.lighttpd.net/pub/Releases/3.1.0/xcache-3.1.0.tar.gz
tar zxvf xcache-3.1.0.tar.gz
cd xcache-3.1.0
/usr/local/php/bin/phpize
./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config
make && make install

//Copy the xcache viewer to the website directory
cp htdocs/ /home/wwwroot/htdocs/xcache -rf

cat >>/usr/local/php/etc/php.ini<<EOF
[xcache-common]
;Attention Path
extension = /usr/local/php/lib/php/extensions/no-debug-zts-20121212/xcache.so

[xcache.admin]
xcache.admin.enable_auth = on
xcache.admin.user = "admin"
xcache.admin.pass = "e10adc3949ba59abbe56e057f20f883e"
;Function: echo -n "password" |md5sum |awk '{print $1}' Calculated MD5 Encrypted passwords
;replace xcache.admin.pass=Value

[xcache]
xcache.shm_scheme = "mmap"
xcache.size = 64M
xcache.count = 1
xcache.slots = 8K
xcache.ttl = 3600
xcache.gc_interval = 60
xcache.var_size = 16M
xcache.var_count = 1
xcache.var_slots = 8K
xcache.var_ttl = 3600
xcache.var_maxttl = 0
xcache.var_gc_interval = 300
xcache.readonly_protection = Off
xcache.mmap_path = "/dev/zero"
xcache.coredump_directory = "/tmp/phpcore"
xcache.coredump_type = 0
xcache.disable_on_crash = Off
xcache.experimental = Off
xcache.cacher = On
xcache.stat = On
xcache.optimizer = Off

[xcache.coverager]
xcache.coverager = Off
xcache.coverager_autostart =  On
xcache.coveragedump_directory = "/tmp/pcov"
EOF

Install phpmyadmin

wget http://iweb.dl.sourceforge.net/project/phpmyadmin/phpMyAdmin/4.2.2/phpMyAdmin-4.2.2-all-languages.tar.gz
tar zxvf phpMyAdmin-4.2.2-all-languages.tar.gz
mv phpMyAdmin-4.2.2-all-languages phpmyadmin
cd phpMyAdmin
mkdir config 
chmod o+rw config
mv config/config.inc.php config.inc.php
chmod o-rw config.inc.php
rm -rf config

Rewrite nginx restart, start files and place them in the system startup directory

vi /etc/init.d/nginx
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig:   - 85 15
# 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 is up.
[ "$NETWORKING" = "no" ] && exit 0

nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)

sysconfig="/etc/sysconfig/$prog"
lockfile="/var/lock/subsys/nginx"
pidfile="/usr/local/nginx/logs/nginx.pid"

NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"

[ -f $sysconfig ] && . $sysconfig


start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
    echo -n $"Starting $prog: "
    daemon $nginx -c $NGINX_CONF_FILE
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}

stop() {
    echo -n $"Stopping $prog: "
    killproc -p $pidfile $prog
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}

restart() {
    configtest_q || return 6
    stop
    start
}

reload() {
    configtest_q || return 6
    echo -n $"Reloading $prog: "
    killproc -p $pidfile $prog -HUP
    echo
}

configtest() {
    $nginx -t -c $NGINX_CONF_FILE
}

configtest_q() {
    $nginx -t -q -c $NGINX_CONF_FILE
}

rh_status() {
    status $prog
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}

# Upgrade the binary with no downtime.
upgrade() {
    local oldbin_pidfile="${pidfile}.oldbin"

    configtest_q || return 6
    echo -n $"Upgrading $prog: "
    killproc -p $pidfile $prog -USR2
    retval=$?
    sleep 1
    if [[ -f ${oldbin_pidfile} && -f ${pidfile} ]];  then
        killproc -p $oldbin_pidfile $prog -QUIT
        success $"$prog online upgrade"
        echo 
        return 0
    else
        failure $"$prog online upgrade"
        echo
        return 1
    fi
}

# Tell nginx to reopen logs
reopen_logs() {
    configtest_q || return 6
    echo -n $"Reopening $prog logs: "
    killproc -p $pidfile $prog -USR1
    retval=$?
    echo
    return $retval
}

case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest|reopen_logs)
        $1
        ;;
    force-reload|upgrade) 
        rh_status_q || exit 7
        upgrade
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    status|status_q)
        rh_$1
        ;;
    condrestart|try-restart)
        rh_status_q || exit 7
        restart
        ;;
    *)
        echo $"Usage: $0 {start|stop|reload|configtest|status|force-reload|upgrade|restart|reopen_logs}"
        exit 2
esac

Note that you need to grant permission to execute: Chmod +x/etc/init.d/nginx

Optimized nginx.cnf configuration file

user  www www;

worker_processes 1;

error_log  /home/wwwlogs/nginx_error.log  crit;

pid        /usr/local/nginx/logs/nginx.pid;

google_perftools_profiles /tmp/tcmalloc;

#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;

events
    {
        use epoll;
        worker_connections 51200;
    }

http
    {
        include       mime.types;
        default_type  application/octet-stream;

        server_names_hash_bucket_size 128;
        client_header_buffer_size 32k;
        large_client_header_buffers 4 32k;
        client_max_body_size 50m;

        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 256k;

        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;
        gzip_proxied        expired no-cache no-store private auth;
        gzip_disable        "MSIE [1-6]\.";

        #limit_zone  crawler  $binary_remote_addr  10m;

        server_tokens off;
        #log format
        log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
             '$status $body_bytes_sent "$http_referer" '
             '"$http_user_agent" $http_x_forwarded_for';

server
    {
        listen       80;
        server_name www.cnhzz.com;
        index index.html index.htm index.php;
        root  /home/wwwroot/htdocs;

            location ~ \.php$ {
                    fastcgi_pass   127.0.0.1:9000;
                    fastcgi_index  index.php;
                    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
                    include        fastcgi_params;
            }

        location /status {
            stub_status on;
            access_log   off;
        }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
            {
                expires      30d;
            }

        location ~ .*\.(js|css)?$
            {
                expires      12h;
            }

        access_log  /home/wwwlogs/access.log  access;
    }
include vhost/*.conf;
}
Adding ngx_pagespeed google_perftools (multiple virtual machines are configured with multiple server s) to the virtual host as needed
log_format  www.cnhzz.com  '$remote_addr - $remote_user [$time_local] "$request" '
             '$status $body_bytes_sent "$http_referer" '
             '"$http_user_agent" $http_x_forwarded_for';
server
        {
                listen       80;
                server_name www.cnhzz.com cnhzz.com;
                if ($host != 'www.cnhzz.com' )
                        {
                        rewrite ^/(.*)$ http://www.cnhzz.com/$1 permanent;
                        }
                index index.php index.html index.htm;
                root  /home/wwwroot/www.cnhzz.com;
                pagespeed on;
                pagespeed FileCachePath /var/ngx_pagespeed_cache;
log_format  www.cnhzz.com  '$remote_addr - $remote_user [$time_local] "$request" '
             '$status $body_bytes_sent "$http_referer" '
             '"$http_user_agent" $http_x_forwarded_for';
server
        {
                listen       80;
                server_name www.cnhzz.com cnhzz.com;
                if ($host != 'www.cnhzz.com' )
                        {
                        rewrite ^/(.*)$ http://www.cnhzz.com/$1 permanent;
                        }
                index index.php index.html index.htm;
                root  /home/wwwroot/www.cnhzz.com;
                pagespeed on;
                pagespeed FileCachePath /var/ngx_pagespeed_cache;

                location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" { add_header "" ""; }
                location ~ "^/ngx_pagespeed_static/" { }
                location ~ "^/ngx_pagespeed_beacon$" { }
                location /ngx_pagespeed_statistics { allow 127.0.0.1; deny all; }
                location /ngx_pagespeed_global_statistics { allow 127.0.0.1; deny all; }
                location /ngx_pagespeed_message { allow 127.0.0.1; deny all; }
                location /pagespeed_console { allow 127.0.0.1; deny all; }

                location ~ \.php$ {
                        fastcgi_pass   127.0.0.1:9000;
                        fastcgi_index  index.php;
                        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
                        include        fastcgi_params;
                }

                location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
                        {
                                expires      30d;
                        }

                location ~ .*\.(js|css)?$
                        {
                                expires      12h;
                        }

                access_log  /home/wwwlogs/www.cnhzz.com.log  www.cnhzz.com;
        }

php-fpm optimization, note that an FPM process about 20M, my machine is a small memory cloud host, so open two can. If there is large memory, convert it according to the situation.

vi php-fpm.conf
pm = dynamic
pm.max_children = 20
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 6
request_terminate_timeout = 100

The second way: // Installed by my local virtual machine

Compile and install nginx

wget http://nginx.org/download/nginx-1.7.0.tar.gz
tar zxvf nginx-1.7.0.tar.gz
cd nginx-1.7.0
./configure \
--user=www \
--group=www \
--prefix=/usr/local/nginx \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_gzip_static_module \
--with-pcre=/usr/local/src/pcre-8.35 \
--with-zlib=/usr/local/src/zlib-1.2.8 \
--with-openssl=/usr/local/src/openssl-1.0.1g
make && make install
cd ..

Configuring nginx to support php

cp /etc/nginx/nginx.conf /etc/nginx/nginx.confbak#Back up the original configuration file
vi /etc/nginx/nginx.conf #edit
user www www; #Modify the running account of nginx to nginx user of nginx group
index index.php index.html index.htm; #Increase index.php
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
#Cancel the comment on FastCGI server partial location, and note that the parameters of the fastcgi_param line are changed to $document_root$fastcgi_script_name, or use the absolute path.
:wq #Save out
#start nginx
/usr/local/nginx/sbin/nginx
##Restart/usr/local/nginx/sbin/nginx-s reload

Up to this point, the lnmp has been fully installed.




















Posted by Digital Wallfare on Sun, 23 Jun 2019 10:21:26 -0700