LNMP景况搭建(Discuz论坛)

一、操作系统级环境及软件版本

操作系统:CentOS release 6.5 (Final)minimal

基本版本:2.6.32-431.el6.x86_64

MySQL版本:MySQL-5.6.28

nginx版本:nginx-1.8.1

php版本:php-5.6.19

二、安装MySQL-5.6.28

赢得地址:

mysql-5.6.28-linux-glibc2.5-x86_64.tar.gz这些版本是法定编写翻译好的本子,解压后平素初阶化就能够使用,假诺利用源码编写翻译安装须求细心的是MySQL5.5本子之后要用cmake举办编写翻译,编写翻译时必要事先安装cmake。

解压mysql-5.6.28-linux-glibc2.5-x86_64.tar.gz

# tar -zxvf mysql-5.6.28-linux-glibc2.5-x86_64.tar.gz

将解压后的文书移动到/usr/local/下并取名称为mysql

# mv mysql-5.6.28-linux-glibc2.5-x86_64 /usr/local/mysql

成立mysql客户没有家目录,而且无法登入

# useradd -M mysql -s /sbin/nologin

创办数据库文件存款和储蓄地方

# mkdir -p /database/mysql

将全体者和所属组改为mysql

# chown -R mysql.mysql /database/mysql/

伊始化数据库

# ./scripts/mysql_install_db –user=mysql –datadir=/database/mysql

将mysql的二进制bin目录加多到顾客的情形变量中

# vim ~/.bash_profile

将/usr/local/mysql/bin添加到PATH中

# source ~/.bash_profile

配置mysql的条件并且开机自运行

# cp mysql.server /etc/init.d/mysqld

必然要进行那些,不然追悔莫及,不表达

# sed -i ‘s#^datadir=#datadir=/database/mysql#’ /etc/init.d/mysqld

# chkconfig –add mysqld

# chkconfig mysqld on

编排mysql的配置文件

# vim /usr/local/mysql/my.cnf

丰裕如下内容不安插基本的情形下的铺排:

basedir=/usr/local/mysql

datadir=/database/mysql/data

port=3306

socket=/tmp/mysql.sock

lower_case_table_names=1

key_buffer_size=256M

sort_buffer_size=1M

read_buffer_size=1M

read_rnd_buffer_size=4M

myisam_sort_buffer_size=64M

thread_cache_size=16

query_cache_size=16M

thread_concurrency=4

interactive_timeout=8

wait_timeout=8

slow_query_log=on

long_query_time=1

slow-query-log-file=/database/mysql/slow.log

实际参数参照他事他说加以考察MySQL常用配备

三、安装php

安装php以前先安装大概用到的包

# yum -y install openssl-devel bzip2-devel libxml2-devel curl-devel
libpng-devel libjpeg-devel freetype-devel libtool-ltdl-devel perl-devel

安装epel-release扩展源

rpm -ivh ”

# yum -y install libmcrypt-devel

创建php-fpm用户

# useradd -M php-fpm -s /sbin/nologin

# tar zxvf php-5.6.19.tar.gz

# cd php-5.6.19

# ./configure –prefix=/usr/local/php
–with-config-file-path=/usr/local/php/etc –enable-fpm
–with-fpm-user=php-fpm –with-fpm-group=php-fpm
–with-mysql=/usr/local/mysql/ –with-mysql-sock=/tmp/mysql.sock
–with-libxml-dir –with-gd –with-jpeg-dir –with-png-dir
–with-freetype-dir –with-iconv-dir –with-zlib-dir –with-mcrypt
–enable-soap –enable-gd-native-ttf –enable-ftp –enable-mbstring
–enable-exif –disable-ipv6

# make -j 2

# make install

# cp php.ini-production /usr/local/php/etc/php.ini

将php-fpm加多到系统服务并安装为开机自运转

# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

# chmod 755 /etc/init.d/php-fpm

# chkconfig –add php-fpm

# chkconfig php-fpm on

# cd /usr/local/php/etc/

# mv php-fpm.conf.default php-fpm.conf

反省php-fpm的岗位文件是不是正确

# /usr/local/php/sbin/php-fpm -t

启动php-fpm

# service php-fpm start

四、安装nginx

# tar -zxvf nginx-1.8.1.tar.gz

# cd nginx-1.8.1

# ./configure –prefix=/usr/local/nginx –with-pcre

# make -j 2

# make install

启动nginx

# /usr/local/nginx/sbin/nginx

去安顿文件里将php的布局项打开

# vim /usr/local/nginx/conf/nginx.conf

location ~ \.php$ {

            root          html;

            fastcgi_pass  127.0.0.1:9000;

            fastcgi_index  index.php;

            fastcgi_param  SCRIPT_FILENAME 
/usr/local/nginx/html$fastcgi_script_name;

            include        fastcgi_params;

        }

重复加载nginx配置文件

# /usr/local/nginx/sbin/nginx -s reload

在/usr/local/nginx/html目录先能够创设php的音讯页进行测量试验五五、php-fpm常用跟配置

[global]

pid = /usr/local/php/var/run/php-fpm.pid

error_log = /usr/local/php/var/log/php-fpm.log

[www]

listen = /tmp/www.sock

user = php-fpm

group = php-fpm

pm = dynamic

pm.max_children = 50

pm.start_servers = 20

pm.min_spare_servers = 5

pm.max_spare_servers = 35

pm.max_requests = 500

rlimit_files = 1024

slowlog = /tmp/phpslow.log

request_slowlog_timeout = 1

六、常见的502错误

首倘使因为nginx对php-fpm的sock未有读写权限变成的,还应该有少数正是在搭建discuz论坛的时候discuz目录下的权柄应该对php-fpm客商有度读写的权能才足以,实际不是nginx。

# chown -R php-fpm:php-fpm /web/discuz/

七、nginx客户认证

在discuz的布局文件中投入上面包车型客车剧情

location ~ .*admin\.php$ {

        auth_basic “fanjinbao auth”;

        auth_basic_user_file /usr/local/nginx/conf/.htpasswd;

        include fastcgi_params;

        fastcgi_pass unix:/tmp/discuz.sock;

        fastcgi_index index.php;

        fastcgi_param SCRIPT_FILENAME
/web/discuz$fastcgi_script_name;

}

.htpasswd文件需求正视apahce的密码生成工具才足以啊

八、nginx域名跳转

在discuz.conf的server中增多如下内容:

if ($host != ‘www.discuz.com’)

{

    rewrite ^/(.*)$ permanent;

}

九、nginx不记录钦赐文件类型日志

在discuz.conf的server中增多如下内容:

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$

{

    access_log off;

}

location ~ (static|cache)

{

    access_log off;

}

十、nginx的日记切割脚本

#!/bin/bash

d=`date -d “-1 day” +%F`

[ -d /tmp/nginx_log ] || mkdir /tmp/nginx_log

mv /web/discuz.log /tmp/nginx_log/$d.log

/etc/init.d/nginxd reload > /dev/null

cd /tmp/nginx_log/

gzip -f $d.log

十一、nginx配置静态文件过期时间

location ~ \.(js|css)

{

    access_log off;

    expires 2h;

}

十二、nginx配置防盗链

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$

    {

        access_log off;

        expires 15d;

        valid_referers none blocked *.discuz.com *.fansik.com;

        if ($invalid_referer)

        {

                return 403;

        }

    }

测量检验防盗链是不是布置成功能够使用curl命令实行测量试验:

# curl -e “” -x127.0.0.1:80
” -I

以此重临的状态码确定是403

# curl -e “” -x127.0.0.1:80
” -I

那个重临的状态码确定是200

十二、nginx的访问调整

直接在安排文件(只怕location中)增添

allow 127.0.0.1;

deny 1.1.1.1;

十三、nginx禁止钦定user_agent

if ($http_user_agent ~* ‘curl|baidu|11111’)

    {

        return 403;

    }

~*:不区分轻重缓急写

十四、nginx代理和负载

upstream baidu{

        server 61.135.169.125:80;

        server 61.135.169.121:80;

}

server {

        listen 80;

        server_name www.baidu.com;

        location / {

                proxy_pass ;

                proxy_set_header Host $host;

        }

}

Ubuntu 14.04 LTS 安装 LNMP Nginx\PHP5 (PHP-FPM)\MySQL 

Ubuntu 13.04 安装 LAMP\Vsftpd\Webmin\phpMyAdmin 服务及安装

CentOS 6.4 下的LNMP 生产条件搭建及安装脚本

生产条件实用之LNMP架构的编写翻译安装+SSL加密实现

LNMP 全职能编写翻译安装 for CentOS 6.3笔记

CentOS 6.3 安装LNMP (PHP 5.4,MyySQL5.6)

在布局LNMP的时候遭逢Nginx运行战败的2个难点

Ubuntu安装Nginx php5-fpm MySQL(LNMP意况搭建)

本文永远更新链接地址:

)
一、操作系统级碰到及软件版本 操作系统:CentOS release 6.5 (Final)minimal
内核版本:2.6.32-431.el6.x86_64 MySQL版本:MySQL-…

LNMP碰着搭建(discuz论坛),lnmpdiscuz

一、操作系统级情状及软件版本

操作系统:CentOS release 6.5 (Final)minimal

基本版本:2.6.32-431.el6.x86_64

MySQL版本:MySQL-5.6.28

nginx版本:nginx-1.8.1

php版本:php-5.6.19

二、安装MySQL-5.6.28

赢得地址:

mysql-5.6.28-linux-glibc2.5-x86_64.tar.gz以此本子是法定编写翻译好的版本,解压后直接起首化就可以使用,假若选择源码编写翻译安装需求留心的是MySQL5.5本子之后要用cmake进行编写翻译,编写翻译时供给事先安装cmake。

解压mysql-5.6.28-linux-glibc2.5-x86_64.tar.gz

# tar -zxvf mysql-5.6.28-linux-glibc2.5-x86_64.tar.gz

将解压后的文本移动到/usr/local/下并取名字为mysql

# mv mysql-5.6.28-linux-glibc2.5-x86_64 /usr/local/mysql

始建mysql客户并没有家目录,並且不能够登陆

# useradd -M mysql -s /sbin/nologin

创造数据库文件存款和储蓄地方

# mkdir -p /database/mysql

将全体者和所属组改为mysql

# chown -R mysql.mysql /database/mysql/

初始化数据库

# ./scripts/mysql_install_db –user=mysql –datadir=/database/mysql

将mysql的二进制bin目录增多到客商的情状变量中

# vim ~/.bash_profile

将/usr/local/mysql/bin添加到PATH中

# source ~/.bash_profile

配备mysql的情形并且开机自运行

# cp mysql.server /etc/init.d/mysqld

必然要实行那一个,不然追悔莫及,不表明

# sed -i ‘s#^datadir=#datadir=/database/mysql#’ /etc/init.d/mysqld

# chkconfig –add mysqld

# chkconfig mysqld on

编写mysql的配置文件

# vim /usr/local/mysql/my.cnf

加多如下内容不安插中央的景观下的安排:

basedir=/usr/local/mysql

datadir=/database/mysql/data

port=3306

socket=/tmp/mysql.sock

lower_case_table_names=1

key_buffer_size=256M

sort_buffer_size=1M

read_buffer_size=1M

read_rnd_buffer_size=4M

myisam_sort_buffer_size=64M

thread_cache_size=16

query_cache_size=16M

thread_concurrency=4

interactive_timeout=8

wait_timeout=8

slow_query_log=on

long_query_time=1

slow-query-log-file=/database/mysql/slow.log

切实参数参照他事他说加以考察MySQL常用配备

三、安装php

安装php在此以前先安装差不离用到的包

# yum -y install openssl-devel bzip2-devel libxml2-devel curl-devel
libpng-devel libjpeg-devel freetype-devel libtool-ltdl-devel perl-devel

安装epel-release扩展源

rpm -ivh ”

# yum -y install libmcrypt-devel

创建php-fpm用户

# useradd -M php-fpm -s /sbin/nologin

# tar zxvf php-5.6.19.tar.gz

# cd php-5.6.19

# ./configure –prefix=/usr/local/php
–with-config-file-path=/usr/local/php/etc –enable-fpm
–with-fpm-user=php-fpm –with-fpm-group=php-fpm
–with-mysql=/usr/local/mysql/ –with-mysql-sock=/tmp/mysql.sock
–with-libxml-dir –with-gd –with-jpeg-dir –with-png-dir
–with-freetype-dir –with-iconv-dir –with-zlib-dir –with-mcrypt
–enable-soap –enable-gd-native-ttf –enable-ftp –enable-mbstring
–enable-exif –disable-ipv6

# make -j 2

# make install

# cp php.ini-production /usr/local/php/etc/php.ini

将php-fpm增加到系统服务并安装为开机自运行

# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

# chmod 755 /etc/init.d/php-fpm

# chkconfig –add php-fpm

# chkconfig php-fpm on

# cd /usr/local/php/etc/

# mv php-fpm.conf.default php-fpm.conf

反省php-fpm的岗位文件是不是科学

# /usr/local/php/sbin/php-fpm -t

启动php-fpm

# service php-fpm start

四、安装nginx

# tar -zxvf nginx-1.8.1.tar.gz

# cd nginx-1.8.1

# ./configure –prefix=/usr/local/nginx –with-pcre

# make -j 2

# make install

启动nginx

# /usr/local/nginx/sbin/nginx

去安顿文件里将php的布局项展开

# vim /usr/local/nginx/conf/nginx.conf

location ~ \.php$ {

            root           html;

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;

            fastcgi_param  SCRIPT_FILENAME 
/usr/local/nginx/html$fastcgi_script_name;

            include        fastcgi_params;

        }

重复加载nginx配置文件

# /usr/local/nginx/sbin/nginx -s reload

在/usr/local/nginx/html目录先可以创立php的音讯页举行测验五五、php-fpm常用跟配置

[global]

pid = /usr/local/php/var/run/php-fpm.pid

error_log = /usr/local/php/var/log/php-fpm.log

[www]

listen = /tmp/www.sock

user = php-fpm

group = php-fpm

pm = dynamic

pm.max_children = 50

pm.start_servers = 20

pm.min_spare_servers = 5

pm.max_spare_servers = 35

pm.max_requests = 500

rlimit_files = 1024

slowlog = /tmp/phpslow.log

request_slowlog_timeout = 1

六、常见的502错误

关键是因为nginx对php-fpm的sock未有读写权限形成的,还会有一点点正是在搭建discuz论坛的时候discuz目录下的权能应该对php-fpm顾客有度读写的权位才方可,而不是nginx。

# chown -R php-fpm:php-fpm /web/discuz/

七、nginx客商认证

在discuz的陈设文件中参预上边包车型大巴始末

location ~ .*admin\.php$ {

        auth_basic “fanjinbao auth”;

        auth_basic_user_file /usr/local/nginx/conf/.htpasswd;

        include fastcgi_params;

        fastcgi_pass unix:/tmp/discuz.sock;

        fastcgi_index index.php;

        fastcgi_param SCRIPT_FILENAME
/web/discuz$fastcgi_script_name;

}

.htpasswd文件供给借助apahce的密码生成工具才方可啊

八、nginx域名跳转

在discuz.conf的server中增多如下内容:

if ($host != ‘www.discuz.com’)

{

    rewrite ^/(.*)$ permanent;

}

九、nginx不记录内定文件类型日志

在discuz.conf的server中增多如下内容:

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$

{

    access_log off;

}

location ~ (static|cache)

{

    access_log off;

}

十、nginx的日志切割脚本

#!/bin/bash

d=`date -d “-1 day” +%F`

[ -d /tmp/nginx_log ] || mkdir /tmp/nginx_log

mv /web/discuz.log /tmp/nginx_log/$d.log

/etc/init.d/nginxd reload > /dev/null

cd /tmp/nginx_log/

gzip -f $d.log

十一、nginx配置静态文件过期时间

location ~ \.(js|css)

{

    access_log off;

    expires 2h;

}

十二、nginx配置防盗链

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$

    {

        access_log off;

        expires 15d;

        valid_referers none blocked *.discuz.com *.fansik.com;

        if ($invalid_referer)

        {

                return 403;

        }

    }

测量试验防盗链是不是配备成功足以行使curl命令进行测量检验:

# curl -e “” -x127.0.0.1:80
” -I

本条重返的状态码明确是403

# curl -e “” -x127.0.0.1:80
” -I

其一重回的状态码断定是200

十二、nginx的访问调整

平昔在布局文件(恐怕location中)加多

allow 127.0.0.1;

deny 1.1.1.1;

十三、nginx禁止内定user_agent

if ($http_user_agent ~* ‘curl|baidu|11111’)

    {

        return 403;

    }

~*:不区分轻重缓急写

十四、nginx代理和负载

upstream baidu{

        server 61.135.169.125:80;

        server 61.135.169.121:80;

}

server {

        listen 80;

        server_name www.baidu.com;

        location / {

                proxy_pass ;

                proxy_set_header Host $host;

        }

}

一、操作系统级景况及软件版本 操作系统:CentOS release 6.5 (Final)minimal
内核版本:2.6.32-431.el6.x86_64 MySQL版本…

CentOS 7源码安装新型版LNMP意况

鉴于商城需要须求最新版的ZABBIX2.4.4索要最新版的类别CentOS7和最新版的LNMP境况,所以自身探求着使用新型版的条件搭建了LNMP系统,蒙受版本如下:
系统:CentOS 7 x86_64
NGINX:nginx-1.7.12
数据库:mariadb-10.0.13
PHP:php-5.5.23
首先做一些预备干活,先把centos7的防火墙退换到iptables,能够敬仰如下链接
centos7防火墙改为iptables

修改成iptables之后就可以清空iptables里面包车型客车过滤准则了,然后再关闭selinux服务。记得不要忘了先安装gcc
gcc-c++ wget net-tools等成效哦。

首先安装mariadb

应该为数据库编译须要相当长日子,所以自身这里下载的是一度编写翻译好了的二进制包,下载版本为
mariadb-10.0.13-linux-glibc_214-x86_64.tar.gz

1、下载二进制包到/usr/local/src 目录下:
[[email protected]
~]# cd /usr/local/src/
[[email protected]
src]# wget

2、将核减包解压到/usr/local 目录下:
[[email protected]
src]# tar zvxf mariadb-10.0.13-linux-glibc_214-x86_64.tar.gz -C
/usr/local/
3、创造mariadb 数据初阶化目录/data/mysql:
[[email protected]
src]# mkdir -p /data/mysql
4、增添系统客户mysql,禁止登入系统,同一时候,将mariadb
数据伊始化目录所属主和组都修改为mysql:
[[email protected]
src]# useradd -r -s /sbin/nologin mysql ;chown -R mysql.mysql
/data/mysql/
5、重命名解压出来的mariadb 目录:
[[email protected]
src]# mv /usr/local/mariadb-10.0.13-linux-x86_64/ /usr/local/mysql
6、踏入重命名后的目录,早先化mariadb:
[[email protected]
src]# cd /usr/local/mysql/
[[email protected]
mysql]# ./scripts/mysql_install_db –datadir=/data/mysql
–user=mysql
Installing MariaDB/MySQL system tables in ‘/data/mysql’ …
140906  2:03:19 [Note] InnoDB: Using mutexes to ref count buffer pool
pages
140906  2:03:19 [Note] InnoDB: The InnoDB memory heap is disabled
140906  2:03:19 [Note] InnoDB: Mutexes and rw_locks use GCC atomic
builtins
140906  2:03:19 [Note] InnoDB: Compressed tables use zlib 1.2.3
140906  2:03:19 [Note] InnoDB: Using Linux native AIO
140906  2:03:19 [Note] InnoDB: Using CPU crc32 instructions
140906  2:03:19 [Note] InnoDB: Initializing buffer pool, size =
128.0M
………………………………………………………………
The latest information about MariaDB is available at
.
You can find additional information about the MySQL part at:

Support MariaDB development by buying support/new features from
SkySQL Ab. You can contact us about this at
[email protected]
Alternatively consider joining our community based development effort:

报错:WARNING: The host ‘test4’ could not be looked up with resolveip.
化解办法:vim /etc/hosts 在最后一行增添192.168.1.242 test4
报错:./bin/mysqld: error while loading shared libraries: libaio.so.1:
cannot open shared object file: No such file or directory
化解办法:yum -y install libaio-devel libaio
7、复制配置文件到/etc目录覆盖此前的my.cnf:
[[email protected]
mysql]# cp support-files/my-large.cnf /etc/my.cnf
cp:是或不是覆盖”/etc/my.cnf”? y
8、复制mysql 运转脚本文件到/etc/init.d 目录下玉石俱焚命名叫mysqld:
[[email protected]
mysql]# cp support-files/mysql.server /etc/init.d/mysqld
再者修改运转脚本的权能为755:
[[email protected]
mysql]# chmod 755 !$
chmod 755 /etc/init.d/mysqld
9、编辑运营脚本,定义datadir 路线:
[[email protected]
mysql]# vim /etc/init.d/mysqld
定义数据贮存路线:
datadir=/data/mysql
10、将mariadb自带命令归入$PATH
[[email protected]
~]# PATH=$PATH:/etc/init.d/#当下立竿见影,重启shell就失效
[[email protected]
~]# echo “export PATH=$PATH:/etc/init.d/” >>/etc/profile
[[email protected]
~]# echo “export PATH=$PATH:/usr/local/mysql/bin/”
>>/etc/profile
[[email protected]
~]# source !$

11、启动mariadb:
[[email protected]
mysql]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS!

其次步,初步设置php

此处要先声美赞臣(Meadjohnson)下,针对Nginx的php安装和针对apache的php安装是有分别的,因为Nginx中的php是以fastcgi的措施结合nginx的,能够领略为nginx代理了php的fastcgi,而apache是把php作为友好的模块来调用的。同样的,php官方下载地址:

下载php
[[email protected]
src]# cd /usr/local/src
[[email protected]
src]# wget
解压php
[[email protected]
src]# tar zxf php-5.5.23.tar.gz
开创连锁账户
[[email protected]
src]# useradd -s /sbin/nologin php-fpm
配置编写翻译参数
[[email protected]
src]# cd php-5.5.23
[[email protected]
src]# yum -y install gcc make gd-devel libjpeg-devel libpng-devel
libxml2-devel bzip2-devel libcurl-devel
[[email protected]
php-5.5.23]# ./configure –prefix=/usr/local/php
–with-config-file-path=/usr/local/php/etc –enable-fpm
–with-fpm-user=php-fpm –with-fpm-group=php-fpm –with-mysql=mysqlnd 
–with-pdo-mysql=mysqlnd –with-mysqli=mysqlnd –with-libxml-dir
–with-gd –with-jpeg-dir –with-png-dir –with-freetype-dir
–with-iconv-dir –with-zlib-dir –with-mcrypt –enable-soap
–enable-gd-native-ttf –enable-ftp –enable-mbstring –enable-exif
–disable-ipv6 –with-pear –with-curl –enable-bcmath –enable-mbstring
–enable-sockets –with-gd –with-libxml-dir=/usr/local –with-gettext
错误:configure: error: xml2-config not found. Please check your libxml2
installation.
化解办法:yum -y install libxml2-devel
错误:configure: error: Please reinstall the libcurl distribution
-easy.h should be in <curl-dir>/include/curl/
消除办法:yum -y install libcurl-devel
错误:configure: error: jpeglib.h not found.
化解办法:yum -y install libjpeg-turbo-devel
错误:configure: error: png.h not found.
化解办法:um -y install libpng-devel
错误:configure: error: freetype-config not found.
消除办法:configure: error: mcrypt.h not found. Please reinstall
libmcrypt.
错误:configure: error: mcrypt.h not found. Please reinstall
libmcrypt.
化解办法:yum -y install libmcrypt-devel

 

安装php
[[email protected] 
php-5.3.27]# make && make install
如上每三个手续,若无完全施行不利,那么下一步是无力回天开展的,使用 echo
$? 看结果是还是不是为 “0” , 即使不是,正是未有举行科学。
修改配置文件
cp php.ini-production /usr/local/php/etc/php.ini
vim /usr/local/php/etc/php-fpm.conf
把之类内容写入该公文:
[global]
pid = /usr/local/php/var/run/php-fpm.pid
error_log = /usr/local/php/var/log/php-fpm.log
[www]
listen = /tmp/php-fcgi.sock
user = php-fpm
group = php-fpm
listen.owner = nobody
listen.group = nobody
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024
保存配置文件后,核准配置是还是不是正确的章程为:
/usr/local/php/sbin/php-fpm -t
假定出现诸如 “test is successful” 字样,表达配置未有失水准。
启动php-fpm
cp /usr/local/src/php-5.5.23/sapi/fpm/init.d.php-fpm
/etc/init.d/php-fpm
chmod 755 /etc/init.d/php-fpm
service php-fpm start
比方想让它开机运营,实施:
chkconfig php-fpm on
检查实验是或不是运行:
ps aux |grep php-fpm
探望是否有为数比相当多个经过(大概20多少个)。

安装nginx

下载nginx
cd /usr/local/src/
wget
解压nginx
tar zxvf nginx-1.7.12.tar.gz
布署编写翻译参数
cd nginx-1.7.12
./configure \
–prefix=/usr/local/nginx \
–with-http_realip_module \
–with-http_sub_module \
–with-http_gzip_static_module \
–with-http_stub_status_module  \
–with-pcre
报错:./configure: error: the HTTP rewrite module requires the PCRE
library.
解决办法:yum -y install pcre-devel
报错:./configure: error: the HTTP gzip module requires the zlib
library.
消除办法:yum install -y zlib-devel

编译nginx
make
安装nginx
make install

编写nginx运转脚本,并投入连串服务
vim /etc/init.d/nginx
写入如下内容:
#!/bin/bash
# chkconfig: – 30 21
# description: http service.
# Source Function Library
. /etc/init.d/functions
# Nginx Settings

NGINX_SBIN=”/usr/local/nginx/sbin/nginx”
NGINX_CONF=”/usr/local/nginx/conf/nginx.conf”
NGINX_PID=”/usr/local/nginx/logs/nginx.pid”
RETVAL=0
prog=”Nginx”

start() {
        echo -n $”Starting $prog: “
        mkdir -p /dev/shm/nginx_temp
        daemon $NGINX_SBIN -c $NGINX_CONF
        RETVAL=$?
        echo
        return $RETVAL
}

stop() {
        echo -n $”Stopping $prog: “
        killproc -p $NGINX_PID $NGINX_SBIN -TERM
        rm -rf /dev/shm/nginx_temp
        RETVAL=$?
        echo
        return $RETVAL
}

reload(){
        echo -n $”Reloading $prog: “
        killproc -p $NGINX_PID $NGINX_SBIN -HUP
        RETVAL=$?
        echo
        return $RETVAL
}

restart(){
        stop
        start
}

configtest(){
    $NGINX_SBIN -c $NGINX_CONF -t
    return 0
}

case “$1” in
  start)
        start
        ;;
  stop)
        stop
        ;;
  reload)
        reload
        ;;
  restart)
        restart
        ;;
  configtest)
        configtest
        ;;
  *)
        echo $”Usage: $0 {start|stop|reload|restart|configtest}”
        RETVAL=1
esac

exit $RETVAL
保存后,更改���限:
chmod 755 /etc/init.d/nginx
chkconfig –add nginx
比如想开机运营,请实施:
chkconfig nginx on
更改nginx配置
率先把原本的铺排文件清空:
> /usr/local/nginx/conf/nginx.conf
“>” 那些标识为重定向的意趣,单独用它,能够把叁个文本文书档案飞快清空。
vim /usr/local/nginx/conf/nginx.conf
写入如下内容:
user nobody nobody;
worker_processes 2;
error_log /usr/local/nginx/logs/nginx_error.log crit;
pid /usr/local/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;

events
{
    use epoll;
    worker_connections 6000;
}

http
{
    include mime.types;
    default_type application/octet-stream;
    server_names_hash_bucket_size 3526;
    server_names_hash_max_size 4096;
    log_format combined_realip ‘$remote_addr $http_x_forwarded_for
[$time_local]’
    ‘$host “$request_uri” $status’
    ‘”$http_referer” “$http_user_agent”‘;
    sendfile on;
    tcp_nopush on;
    keepalive_timeout 30;
    client_header_timeout 3m;
    client_body_timeout 3m;
    send_timeout 3m;
    connection_pool_size 256;
    client_header_buffer_size 1k;
    large_client_header_buffers 8 4k;
    request_pool_size 4k;
    output_buffers 4 32k;
    postpone_output 1460;
    client_max_body_size 10m;
    client_body_buffer_size 256k;
    client_body_temp_path /usr/local/nginx/client_body_temp;
    proxy_temp_path /usr/local/nginx/proxy_temp;
    fastcgi_temp_path /usr/local/nginx/fastcgi_temp;
    fastcgi_intercept_errors on;
    tcp_nodelay on;
    gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 8k;
    gzip_comp_level 5;
    gzip_http_version 1.1;
    gzip_types text/plain application/x-javascript text/css text/htm
application/xml;

server
{
    listen 80;
    server_name localhost;
    index index.html index.htm index.php;
    root /usr/local/nginx/html;

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass unix:/tmp/php-fcgi.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME
/usr/local/nginx/html$fastcgi_script_name;
    }

}

}
保留配置后,先检查一下配置文件是或不是有错误存在:
/usr/local/nginx/sbin/nginx  -t
如果呈现内容如下,则安排不错,不然须求依赖错误提示修改配置文件:
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is
ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is
successful
启动nginx:
service nginx start
一经不能够运维,请查看 “/usr/local/nginx/logs/error.log”
文件,检查nginx是或不是运维:
ps aux |grep nginx
看是否有进度。

测验是或不是剖判php文件

创设测量试验文件:
vim /usr/local/nginx/html/2.php
剧情如下:
<?php echo phpinfo();?>
测试:
[[email protected]
nginx]# curl localhost/2.php
抑或利用浏览器张开

首要:若是条分缕析不了,检查日志开采连续不到php,我的php版本为5.5.23,比较新的版本,要求在php/etc/php-fpm.conf文件中加多
listen.owner = nobody
listen.group = nobody
这两行,再重启一下劳动就能够选择php了
原因是/tmp/php-fcgi.sock那么些文件并没有读权限
时至前些天,最新版的LNMP情形源码编写翻译安装完结。

Ubuntu 14.04 LTS 安装 LNMP Nginx\PHP5 (PHP-FPM)\MySQL 

Ubuntu 13.04 安装 LAMP\Vsftpd\Webmin\phpMyAdmin 服务及安装

CentOS 6.4 下的LNMP 生产景况搭建及安装脚本

生产条件实用之LNMP架构的编写翻译安装+SSL加密达成

LNMP 全职能编写翻译安装 for CentOS 6.3笔记

CentOS 6.3 安装LNMP (PHP 5.4,MyySQL5.6)

在布局LNMP的时候蒙受Nginx运转战败的2个难题

Ubuntu安装Nginx php5-fpm MySQL(LNMP境况搭建)

7源码安装新型版LNMP际遇由于公司供给供给最新版的ZABBIX2.4.4急需最新版的连串CentOS7和新星版的LNMP蒙受,所以自身研究着使用新型版…

Author

发表评论

电子邮件地址不会被公开。 必填项已用*标注