LNMP架构搭建

php编译安装:

[[email protected] ~]# cd /usr/local/src/

[[email protected] src]# wget wget  http://cn2.php.net/distributions/php-5.4.37.tar.bz2

[[email protected] src]# rm -rf /usr/local/php/           //删除上次LAMP安装时做的PHP

[[email protected] src]# tar jxvf php-5.4.37.tar.bz2

[[email protected] src]# cd php-5.4.37

[[email protected] php-5.4.37]# ./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 \

> --enable-zend-multibyte \

> --disable-ipv6 \

> --with-pear \

> --with-curl \

> --with-openssl

如有报错,试试先执行如下命令:

[[email protected] php-5.4.37]#yum install -y gcc gcc-c++  make zlib zlib-devel pcre pcre-devel  libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers

[[email protected] php-5.4.37]# make

[[email protected] php-5.4.37]# echo $?

0

[[email protected] php-5.4.37]# echo $?

0

[[email protected] php-5.4.37]# cp php.ini-production /usr/local/php/etc/php.ini

//拷贝一份配置文件

[[email protected] php-5.4.37]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

//拷贝启动脚本

[[email protected] php-5.4.37]# vim !$          //查看脚本

vim /etc/init.d/php-fpm

[[email protected] php-5.4.37]# chmod 755 /etc/init.d/php-fpm           //授执行的权限

[[email protected] php-5.4.37]# chkconfig --add php-fpm                //加入系统服务项

[[email protected] php-5.4.37]# chkconfig php-fpm on                //开机自启动

[[email protected] php-5.4.37]# service php-fpm start

failed                                                //启动失败,还少相关配置

[[email protected] php-5.4.37]# cd /usr/local/php/etc/

[[email protected] etc]# mv php-fpm.conf.default php-fpm.conf       //重命名成php-fpm.conf

[[email protected] etc]# /usr/local/php/sbin/php-fpm -t             //检查配置文件是否有错

[[email protected] etc]# !ser                    //重启还是失败,无用户

service php-fpm start

[[email protected] etc]# useradd -s /sbin/nologin php-fpm            //增加用户

[[email protected] etc]# !ser

service php-fpm start

[[email protected] etc]# ps aux|grep php-fpm                       //查看进程是否启动

[[email protected] etc]# netstat -lnp                              //查看监听的端口

tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      19600/php-fpm

[[email protected] etc]#  ls

pear.conf  php-fpm.conf  php.ini

Nginx编译安装:

[[email protected] etc]# cd /usr/local/src/

[[email protected] src]# ls

[[email protected] src]# wget http://nginx.org/download/nginx-1.6.2.tar.gz

[[email protected] src]# tar zxvf nginx-1.6.2.tar.gz

[[email protected] src]# cd nginx-1.6.2

[[email protected] nginx-1.6.2]# ./configure   --prefix=/usr/local/nginx   --with-pcre

[[email protected] nginx-1.6.2]# echo $?

0

[[email protected] nginx-1.6.2]# make

[[email protected] nginx-1.6.2]# echo $?

0

[[email protected] nginx-1.6.2]# make install

[[email protected] nginx-1.6.2]# echo $?

0

[[email protected] nginx-1.6.2]# cd /usr/local/nginx/

[[email protected] nginx]# ls

conf  html  logs  sbin

[[email protected] nginx]# ls sbin/nginx                      //nginx的可执行文件

sbin/nginx

[[email protected] nginx]# /usr/local/nginx/sbin/nginx          //启动nginx,80端口被占用

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

[[email protected] nginx]# apachectl stop

[[email protected] nginx]# /usr/local/nginx/sbin/nginx          //启动nginx

[[email protected] nginx]# ps aux |grep nginx           //查看进程有一主一次

root     21901  0.0  0.0   5380   636 ?        Ss   05:18   0:00 nginx: master process /usr/local/nginx/sbin/nginx

nobody   21902  0.0  0.0   5564   988 ?        S    05:18   0:00 nginx: worker process

[[email protected] nginx]# netstat -lnp             //查看监听端口

tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      21901/nginx

nginx无自己的启动脚本(可以自己写一份)

解析php,使nginx、php联系在一起

测试php解析

[[email protected] ~]# 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;

}

//将目录改到web网站根目录下

客户端访问,到nginx默认页面

[[email protected] ~]# cat /usr/local/nginx/html/index.html

//查看文件,刚访问的页面配置为该文件

[[email protected] ~]# cd /usr/local/nginx/html/

[[email protected] html]# vim info.php

<?php

phpinfo();

?>

[[email protected] html]# /usr/local/nginx/sbin/nginx -t          //查看配置文件有无错误

[[email protected] html]# /usr/local/nginx/sbin/nginx -s reload      //重新加载

客户端访问,正常解析

[[email protected] html]# curl localhost

[[email protected] html]# curl localhost/info.php

//使用curl测试

nginx启动脚本和配置文件

nginx无apachect 文件工具重启,需手动写一个

[[email protected] html]# 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

[[email protected] html]# chmod 755 !$

chmod 755 /etc/init.d/nginx

[[email protected] html]# chkconfig --add nginx

[[email protected] html]# chkconfig nginx on

[[email protected] html]# service nginx start

[[email protected] html]# service nginx stop

[[email protected] html]# service nginx restart

[[email protected] html]# vim /usr/local/nginx/conf/nginx.conf  //打开默认配置文件,使用gg调整光标到首行,然后使用dG命令清空原先配置,写入:

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  wang  ‘$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;

include vhosts/*.conf;

}

[[email protected] html]# pwd

/usr/local/nginx/html

[email protected] html]# cd /usr/local/nginx/conf/

[[email protected] conf]# mkdir vhosts

[[email protected] conf]# cd vhosts/

[[email protected] conf]# vim default.conf

server

{

listen 80 default_server;

server_name localhost;

index index.html index.htm index.php;

root /tmp/1233;

deny all;

}

//使默认为错误403

[email protected] conf]# /usr/local/nginx/sbin/nginx -t

[[email protected] conf]# /etc/init.d/nginx reload

[[email protected] vhosts]# curl -x127.0.0.1:80 111.com

<head><title>403 Forbidden</title></head>

//curl测试出现403错误

[[email protected] vhosts]# vim 111.conf

server

{

listen 80;

server_name 111.com;

index index.html index.htm index.php;

root /data/www;

location ~ \.php$ {

include fastcgi_params;

# fastcgi_pass unix:/tmp/php-fcgi.sock;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;

}

}

[email protected] conf]# /usr/local/nginx/sbin/nginx -t

[[email protected] conf]# /etc/init.d/nginx reload

[[email protected] vhosts]# /etc/init.d/nginx reload

tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      19600/php-fpm

[[email protected] vhosts]# curl -x127.0.0.1:80 111.com -I

HTTP/1.1 301 Moved Permanently

[[email protected] vhosts]# curl -x127.0.0.1:80 111.com/forum.php -I

HTTP/1.1 200 OK

php-fpm配置文件

[[email protected] ~]# ls /usr/local/php/etc/php-fpm.conf

/usr/local/php/etc/php-fpm.conf

// php-fpm.conf服务相关配置文件

[[email protected] ~]# ls /usr/local/php/etc/php.ini

/usr/local/php/etc/php.ini

//全局服务配置

[[email protected] ~]# vim /usr/local/php/etc/php-fpm.conf         //查看配置

[[email protected] ~]# > /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/www.sock

user = php-fpm

group = php-fpm

listen.owner = nobody                       //和后面的nginx的一致

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

[[email protected] ~]# /usr/local/php/sbin/php-fpm -t

[[email protected] ~]# /etc/init.d/php-fpm restart

[[email protected] ~]# ps aux |grep php-fpm                     //(查看pool、www)

[[email protected] ~]# ls /usr/local/nginx/conf/vhosts/

111.conf  default.conf

[[email protected] ~]# cat /usr/local/nginx/conf/vhosts/111.conf

[[email protected] ~]# vim /usr/local/php/etc/php-fpm.conf

[www]

slowlog = /tmp/www_slow.log

request_slowlog_timeout = 1

php_admin_value[open_basedir]=/data/www/:/tmp/

//慢反应日志,反应慢时记录日志

配置文件参考

[[email protected] html]# vim /usr/local/nginx/conf/nginx.con

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 wang  ‘$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;

include vhosts/*.conf;

}

时间: 2024-10-23 12:31:55

LNMP架构搭建的相关文章

企业级LNMP架构搭建实例(基于Centos6.x)

1.1 部署LNMP架构说明 1.1.1 LNMP架构内容 01.部署linux系统 02.部署nginx网站服务 03.部署mysql数据库服务 04.部署php动态解析服务 1.1.2 配置LNMP架构步骤 01.配置Nginx配置文件 02.配置mysql数据库信息(SQL语句) 03.配置wordpress博客网站 1.1.3 架构服务器串联 01.数据库数据信息迁移(web服务器上的mysql数据 迁移到10.0.0.51 数据库服务器上) 02.将本地储存数据挂载到NFS共享储存服务

LNMP架构搭建Discuz论坛(实战!)

什么是LNMP架构 LNMP平台就是Linux.Ngnix. MySQL. PHP的组合架构,需要Linux服务器.MySQL数据库.PHP解析环境 MySQL安装配置 为了与Nginx.PHP环境保持一致,此处选择采用源代码编译的方式安装MySQL组件 MySQL部署的方法 编译安装MySQL 优化调整 初始化数据库 启动mysq|服务并设置root数据库账号的密码 PHP解析环境的安装 配置网页动静分离,解析PHP,有两种方法可以选择 使用PHP的FPM模块 将访问PHP页面的Web请求转交

LNMP架构搭建(基础入门级)

LNMP架构介绍 LNMP = Linux + Ningx + Mysql + PHP 由Nginx取代apache,提供web服务: PHP作为一个独立服务存在而非apache的一个模块,这个服务为php-fpm: Nginx直接处理静态请求,动态请求会转发给php-fpm. Nginx在处理静态文件的速率较Apache要快的多,这时两者的底层设计所决定的.同时Nginx可以处理的并发访问量也较Apache要大的多,毕竟Apache创建之初并没有考虑到当今的高并发访问量的规模会如此之大.Apa

基于lnmp架构搭建论坛

LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构. 实验环境: 系统环境: RHEL6 x86-64 selinux and iptables disabled 一.Mysql 安装 1.安装软件包依赖性: [[email protected] ~]# yum install -y gcc gcc-c++ ncurses-devel bison openssl-devel zlib-devel [[email protected] ~]# yum instal

LNMP架构搭建详细部署

LNMP简介LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构. Linux是一类Unix计算机操作系统的统称,是目前最流行的免费操作系统.代表版本有:debian.centos.ubuntu.fedora.gentoo等. Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器. Mysql是一个小型关系型数据库管理系统. PHP是一种在服务器端执行的嵌入HTML文档的脚本语言. 这四种软件均为免费.高效.扩展性强的网

LNMP架构搭建与优化

1,1php编译与安装 LAMP apache.mysql.php LNMP nginx.mysql.php mysql的安装与LAMP的mysql安装方法一样 先安装mysql再安装php cd /usr/local/src wget http://cn2.php.net/distributions/php-5.4.37.tar.bz2  下载 tar jxvf php-5.4.37.tar.bz2 解压 cd php-5.4.37 ./configure --prefix=/export/s

LNMP架构搭建论坛(3)

配置php服务libmcrypt源码包是用于加密算法的扩展库程序libvpx源码包是用于提供视频编码器的服务程序,libvpx-v1.3.0.tar.bz2,则此处解压方式为:tar xjvftiff源码包是用于提供标签图像文件格式的服务程序libpng源码包是用于提供png图片格式支持函数库的服务程序freetype源码包是用于提供字体支持引擎的服务程序jpeg源码包是用于提供jpeg图片格式支持函数库的服务程序libgd源码包是用于提供图形处理的服务程序,在编译libgd源码包时,请记得写入

LNMP架构搭建论坛(三)

配置PHP服务(1)cd /usr/local/src(2)解压编译生成安装yasm源码包(3)安装libmcrypt源码包(4)安装libvpx源码包(5)安装tiff源码包(6)安装libpng源码包(7)安装freetype 源码包(8)安装jpegsrc源码包(9)安装libgb源码包(10)安装t1lib源码包tar zxvf t1lib-5.1.2.tar.gzcd t1lib-5.1.2./configure --prefix=/usr/local/t1lib --enable-s

LNMP 架构搭建与优化

安装 MySQL 安装 PHP 安装 Nginx 解析 PHP Nginx 启动脚本 Nginx 配置文件 Nginx 502 问题 php-fpm 配置文件 Nginx 配置默认虚拟主机