LNMP架构(1)编译安装在centos6

前言:LNMP简介

LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构。Linux是一类Unix计算机操作系统的统称,是目前最流行的免费操作系统。
代表版本有:debian、centos、ubuntu、fedora、gentoo等。Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器。Mysql是一个小型关系型数据库管理系统。
PHP是一种在服务器端执行的嵌入HTML文档的脚本语言。这四种软件均为免费开源软件,组合到一起,成为一个免费、高效、扩展性强的网站服务系统。
系统环境:适合centos6.x x86_64位 minimal操作系统源码编译安装方式
优势:

  • 自定义软件功能
  • 优化编译参数,提高性能
  • 解决不必要的软件间依赖

一、下载解压源码包

  • mysql免编译二进制包下载并解压 (5.1.72)
  • php源码包下载并解压 (5.3.27)
  • nginx 源码包下载并解压(1.4.4)
[root@coderblog ~]# wget -cP /usr/local/src http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.72-linux-x86_64-glibc23.tar.gz
[root@coderblog ~]# cd /usr/local/src/ && tar -xzvf mysql-5.1.72-linux-x86_64-glibc23.tar.gz 
 #下载并解压mysql免编译二进制包
[root@coderblog src]# wget -c http://mirrors.sohu.com/php/php-5.3.27.tar.gz 

[root@coderblog src]# tar -xzvf php-5.3.27.tar.gz 
#下载并解压php源码包
[root@coderblog src]# wget -c [root@coderblog src]# tar -xzvf nginx-1.4.4.tar.gz
#下载并解压nginx源码包

二、安装

<h2>安装顺序mysql > php > nginx</h2>

2.0 mysql安装

[root@coderblog src]# mv mysql-5.1.72-linux-x86_64-glibc23 /usr/local/mysql
#移动并重命名至/usr/local/mysql
[root@coderblog src]# useradd -s /sbin/nologin mysql
#建立mysql账户
[root@coderblog src]# cd /usr/local/mysql
[root@coderblog mysql]# mkdir -p /data/mysql ; chown -R mysql:mysql /data/mysql
[root@coderblog mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
#初始化数据库
--user 定义数据库的所属主,
--datadir 定义数据库安装到哪里,
建议放到大空间的分区上,
这个目录需要自行创建。
这一步骤很关键,如果你看到两个 “OK” 说明执行正确
[root@coderblog mysql]# cp support-files/my-large.cnf /etc/my.cnf
#拷贝配置文件
[root@coderblog mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@coderblog mysql]# chmod 755 /etc/init.d/mysqld
#拷贝启动文件并赋予权限
[root@coderblog mysql]# vim /etc/init.d/mysqld
#修改启动配置文件
需要修改的地方有 “datadir=/data/mysql” (前面初始化数据库时定义的目录)
basedir=/usr/local/mysql
[root@coderblog mysql]# chkconfig --add mysqld #把启动脚本加入系统服务项
[root@coderblog mysql]# chkconfig mysqld on #设定开机启动
[root@coderblog mysql]# service mysqld start #启动mysql

2.1 php安装

[root@coderblog ~]# cd /usr/local/src/php-5.3.27 #切到刚刚解压php之后的目录
[root@coderblog php-5.3.27]# useradd -s /sbin/nologin php-fpm #创建相关用户
[root@coderblog php-5.3.27]# yum install -y epel-release #安装epel扩展源
[root@coderblog php-5.3.27]# yum -y install pcre pcre-devel apr apr-devel zlib-devel libxml2-devel openssl openssl-devel bzip2 bzip2-devel libpng libpng-devel freetype freetype-devel libmcrypt-devel gcc libcurl-devel libtool-ltdl-devel libjpeg libjpeg-devel libpng libpng-devel 
#安装所需环境
[root@coderblog php-5.3.27]#./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 \
--with-pear \
--with-curl \
--with-openssl \
--enable-sockets
#配置编译参数
如有报错信息可以百度下error信息,一般都会有答案.
[root@coderblog php-5.3.27]# echo $?
0
#检测是否执行成功 非0则不成功
[root@coderblog php-5.3.27]# make && make install
[root@coderblog php-5.3.27]# cp php.ini-production /usr/local/php/etc/php.ini
[root@coderblog php-5.3.27]# vim /usr/local/php/etc/php-fpm.conf
#修改配置文件
#把如下内容写入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.user=php-fpm
listen.group=php-fpm
listen.mode=0666
listen = /tmp/php-fcgi.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
保存配置文件后,检验配置是否正确的方法为:

[root@coderblog php-5.3.27]# /usr/local/php/sbin/php-fpm -t

启动php-fpm
[root@coderblog php-5.3.27]# cp /usr/local/src/php-5.3.27/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm #拷贝启动文件
[root@coderblog php-5.3.27]# chmod 755 /etc/init.d/php-fpm #赋予权限
[root@coderblog php-5.3.27]# service php-fpm start #启动php服务

如果想让它开机启动,执行:

[root@coderblog php-5.3.27]# chkconfig php-fpm on

2.2 Nginx安装

[root@coderblog ~]# cd /usr/local/src/nginx-1.4.4/ #切到刚刚解压nginx之后的目录
[root@coderblog nginx-1.4.4]# useradd -s /sbin/nologin www #创建相关用户

[root@coderblog nginx-1.4.4]# ./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
#配置编译参数
[root@coderblog nginx-1.4.4]# make && make install #安装

[root@coderblog nginx-1.4.4]# vim /etc/init.d/nginx
#自定义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

[root@coderblog nginx-1.4.4]# chmod 755 /etc/init.d/nginx #赋予启动文件权限
[root@coderblog nginx-1.4.4]# chkconfig --add nginx #加入开机启动项
[root@coderblog nginx-1.4.4]# chkconfig nginx on #设置开机自动启动
[root@coderblog nginx-1.4.4]# > /usr/local/nginx/conf/nginx.conf #清空配置文件


[root@coderblog nginx-1.4.4]# vim /usr/local/nginx/conf/nginx.conf
#编辑nginx配置文件 并把以下内容拷贝到文件中
user www www;
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;
}

}

}


[root@coderblog ~]# /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
#如显示如上,则配置文件无误

[root@coderblog ~]# service nginx start #启动nginx
至此LNMP环境就安装完成了,nginx虚拟主机位置在:/usr/local/nginx/html/

2.3 测试php解析情况

将如下代码 写入网站根目录1.php
编译安装nginx默认根目录:/usr/local/nginx/html/

<?php
phpinfo();
?>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 199,340评论 5 467
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 83,762评论 2 376
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 146,329评论 0 329
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 53,678评论 1 270
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 62,583评论 5 359
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 47,995评论 1 275
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,493评论 3 390
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,145评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,293评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,250评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,267评论 1 328
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,973评论 3 316
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,556评论 3 303
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,648评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,873评论 1 255
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,257评论 2 345
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 41,809评论 2 339

推荐阅读更多精彩内容