432ewd 发表于 2015-4-3 08:37:29

Cent OS 中LNMP 环境源码搭建

LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构。    Nginx是一个小巧而高效的Linux下的Web服务器软件,是由 Igor Sysoev 为俄罗斯访问量第二的Rambler 站点开发的,已经在一些俄罗斯的大型网站上运行多年,相当的稳定。Nginx性能稳定、功能丰富、运维简单、处理静态文件速度快且消耗系统资源极少。

本案环境与说明:环境
1
2
3
# cat /etc/centos-release && uname -r
CentOS release 6.6 (Final)
2.6.32-504.el6.x86_64




软件版本:
1
2
3
4
mysql-5.7.6-m16-linux-glibc2.5-x86_64.tar.gz
nginx-1.7.8.tar.gz
libmcrypt-2.5.6.tar.gz
php-5.6.6.tar.gz




文中所用软件下载地址:http://mirrors.sohu.com/http://mirrors.cnnic.cn/apache/ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt
Nginx 安装前的准备
wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.6-m16-linux-glibc2.5-x86_64.tar.gz
wget http://mirrors.sohu.com/php/php-5.6.6.tar.gz
wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.6.tar.gz
wget http://mirrors.sohu.com/nginx/nginx-1.7.8.tar.gz

安装MySQL

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# useradd -s /sbin/nologin mysql
# tar zxvf mysql-5.7.6-m16-linux-glibc2.5-x86_64.tar.gz
# cd /usr/local/
# mv /root/mysql-5.7.6-m16-linux-glibc2.5-x86_64 .
# ln -s mysql-5.7.6-m16-linux-glibc2.5-x86_64 mysql
# cd mysql
# mkdir /data/mysql
# chown -R root .
# chown -R mysql /data/mysql
# chgrp -R mysql .
# bin/mysql_install_db --user=mysql --datadir=/data/mysql
# cp support-files/my-default.cnf /etc/my.cnf
cp:是否覆盖"/etc/my.cnf"? y
# cp support-files/mysql.server /etc/init.d/mysqld
# chmod 755 /etc/init.d/mysqld
# vim /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/data/mysql
# chkconfig --add mysqld
# chkconfig mysqld on
# service mysqld start
Starting MySQL. SUCCESS!




安装PHP
1.环境配置

1
2
3
4
5
6
7
8
9
rpm -q libxml2-devel libjpeg-turbo libpng-devel freetype-devel gd-devel libmcrypt-devel openssl-devel
libxml2-devel-2.7.6-14.el6_5.2.x86_64
libjpeg-turbo-1.2.1-3.el6_5.x86_64
libpng-devel-1.2.49-1.el6_2.x86_64
freetype-devel-2.3.11-14.el6_3.1.x86_64
package gd-devel is not installed
package libmcrypt-devel is not installed
openssl-devel-1.0.1e-30.el6.x86_64
# yum install gd-devel




本案为配置扩展源,libmcrypt-devel使用tar包安装


1
2
3
4
# tar zxvf libmcrypt-2.5.6.tar.gz
# cd libmcrypt-2.5.6
# ./configure --prefix=/usr/local/libmcrypt
# make && make install




2.安装php


1
2
3
4
5
6
7
8
9
10
11
12
# tar zxvf php-5.6.6.tar.gz
# useradd -s /sbin/nologin php-fpm
# cd php-5.6.6
# ./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=/usr/local/libmcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --disable-ipv6 --with-curl
# make && make install
# cp php.ini-production /usr/local/php/etc/php.ini
# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
# mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
# chmod 755 /etc/init.d/php-fpm
# chkconfig --add php-fpm
# chkconfig php-fpm on
# service php-fpm start




安装nginx
1.环境检查

1
2
# rpm -q pcre-devel
pcre-devel-7.8-6.el6.x86_64




2.安装

1
2
3
4
# tar nginx-1.7.8.tar.gz
# cd nginx-1.7.8
# ./configure --prefix=/usr/local/nginx --with-pcre
# make && make install




3.启动

1
2
3
4
5
6
# /usr/local/nginx/sbin/nginx   #启动服务
# ps -aux | grep nginx
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
root      115410.00.024304   668 ?      Ss   00:45   0:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody    115420.00.1247281248 ?      S    00:45   0:00 nginx: worker process      
root      115440.00.0 103256   840 pts/0    S+   00:45   0:00 grep nginx




4.配置解析php

1
2
3
4
5
6
7
8
9
10
11
12
# vi /usr/local/nginx/conf/nginx.conf#找如下内容并修改fastcgi_param行
      # 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_indexindex.php;
      #    fastcgi_paramSCRIPT_FILENAME/scripts$fastcgi_script_name;
            fastcgi_paramSCRIPT_FILENAME/usr/local/nginx/html$fastcgi_script_name;
            include      fastcgi_params;
      }
# /usr/local/nginx/sbin/nginx -s reload




5.测试

1
2
3
4
5
# cat /usr/local/nginx/html/1.php
<?php
    phpinfo();
?>
# curl localhost/1.php



页: [1]
查看完整版本: Cent OS 中LNMP 环境源码搭建