LNMP环境构建
LNMP(Linux+Nginx+Mysql+Php)就是在Linux系统中,通过编译安装Nginx,Mysql,Php来提供一个支持Php动态网页的Web服务器,构建过程如下:
libevent-2.0.16-stable.tar.gz
nginx-1.0.11   
php-5.3.7   
mysql-5.0.81.tar.gz编译安装过程

一.安装nginx

#yum install gcc openssl-devel pcre-devel zlib-devel #安装编译安装的开发工具

1.tar -zxvf libevent-2.0.16 -C /usr/src

2.cd /usr/src/libevent-2.0.16
3. ./configure
4 make&&make install
5 vim /etc/ld.so.conf.d/libevent.conf
加上 /usr/local/lib
6 ldconfig -v |grep libevent
7 . tar -zxvf nginx-1.0.11.tar.gz -C /usr/src
8 . cd /usr/src/nginx-1.0.11
9 . groupadd -r nginx 添加nginx组
10. useradd -r -g nginx -s /bin/false -M nginx 添加nginx用户
11
./configure \
--prefix=/usr \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/tmp/nginx/client/ \
--http-proxy-temp-path=/var/tmp/nginx/proxy/ \
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
--with-pcre
 
12.make&&make install
 
13.mkdir -pv /var/tmp/nginx/client
14 .nginx
15 vim /etc/nginx/nginx.conf
启用如下选项
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
添加php格式的主页,类似如下:
location / {
root html;
index index.php index.html index.htm;
}
16.编辑/etc/nginx/fastcgi_params,将其内容更改为如下内容:
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
17. pkill -1 nginx

二.安装mysql源码包:
新建用户以安全方式运行mysql进程
[root@server html]# groupadd -r mysql
[root@server html]# useradd -g mysql -s /sbin/nologin -M mysql
解压mysql包
[root@server ~]# tar -zxvf mysql-5.0.81.tar.gz -C /usr/local/
编译安装:
[root@server ~]# cd /usr/local/ mysql-5.0.81
[root@server mysql-5.0.81]# ./configure --prefix=/usr/local/mysql
[root@server mysql-5.0.81]# make && make install
改变文件所有者:
[root@server mysql]# chown -R mysql:mysql .
[root@server mysql-5.0.81]# chown -R mysql /usr/local/mysql/var/
为mysql提供主配置文件:
[root@server mysql]# cp support-files/my-large.cnf /etc/my.cnf
初始化:
[root@server mysql-5.0.81]# /usr/local/mysql/bin/mysql_install_db --user=mysql
后台安全运行:
[root@server mysql-5.0.81]# /usr/local/mysql/bin/mysqld_safe --user=mysql
[root@server mysql-5.0.81]# vim /etc/ld.so.conf.d/mysql.conf

/usr/local/mysql/lib/mysql
为mysql提供mysql的服务脚本文件
[root@server mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
赋予脚本执行权限
[root@server mysql-5.0.81]# chmod +x /etc/init.d/mysqld
设置系统全局的环境变量PATH值,方便使用mysql数据库命令
[root@server mysql-5.0.81]# echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
将mysql添加至服务列表:
[root@server mysql]# chkconfig --add mysqld
[root@server mysql]# chkconfig mysqld on
[root@server mysql-5.0.81]# service mysqld start启动mysqld服务
 

三.编译安装php-5.3.10

解决依赖关系:

请配置好yum源(可以是本地系统光盘)后执行如下命令:

# yum -y groupinstall "X Software Development"

# yum -y groupinstall "Development Tools" #安装好开发组包工具

# yum -y groupinstall "Development Libraries"# 安装编译时依赖的库文件

1.tar -jvxf php-5.3.10.tar.bz2 -C /usr/src
2.cd /usr/src/php-5.3.10
3../configure \
--prefix=/usr/local/php \
--with-mysql=/usr/local/mysql \
--with-openssl \
--enable-fpm \
--enable-sockets \
--enable-sysvshm \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--enable-mbstring \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-libxml-dir=/usr \
--enable-xml \
--with-config-file-path=/etc/php \
--with-config-file-scan-dir=/etc/php \
--with-bz2 \
--with-curl
4.make&&make install
5.为php提供配置文件
mkdir /etc/php/
cp php.ini-production /etc/php/php.ini

..............