上传几个软件包:

LNMP 源码安装_lnmp源码安装

LNMP 源码安装_lnmp源码安装_02

 

先安装mysql:

把下面的压缩包解压到/usr/local/(额外安装包的目录)目录下:

[root@localhost ~]# tar -zxvf mysql-5.5.15-linux2.6-i686.tar.gz -C /usr/local

[root@localhost ~]# cd /usr/local/mysql-5.5.15-linux2.6-i686/

查看详细信息,下面的安装就按照这个步骤操作:

[root@localhost mysql-5.5.15-linux2.6-i686]# less INSTALL-BINARY

   To install and use a MySQL binary distribution, the basic command

   sequence looks like this:

shell> groupadd mysql

shell> useradd -r -g mysql mysql

shell> cd /usr/local

shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz

shell> ln -s full-path-to-mysql-VERSION-OS mysql

shell> cd mysql

shell> chown -R mysql .

shell> chgrp -R mysql .

shell> scripts/mysql_install_db --user=mysql

shell> chown -R root .

shell> chown -R mysql data

# Next command is optional

shell> cp support-files/my-medium.cnf /etc/my.cnf

shell> bin/mysqld_safe --user=mysql &

# Next command is optional

shell> cp support-files/mysql.server /etc/init.d/mysql.server

 

为了方便使用,可以给这个文件问做个名为mysql的符号链接:

[root@localhost local]# ln -s mysql-5.5.15-linux2.6-i686 mysql

进入mysql目录下:根据上面的步骤,先创建一个mysql组,一个账号,并加入组:

[root@localhost local]# cd mysql

[root@localhost mysql]# groupadd mysql

[root@localhost mysql]# useradd -r -g mysql mysql

然后根据步骤,改变权限(注意改权限时候,最后mysql后面别忘记"."):

[root@localhost mysql]# chown -R mysql .

[root@localhost mysql]# chgrp -R mysql .

然后以mysql的身份来进行初始化:

[root@localhost mysql]# scripts/mysql_install_db --user=mysql

初始化完成后,再把权限改成管理员:

[root@localhost mysql]# chown -R root .

但data目录的所属者依然是mysql:

[root@localhost mysql]# chown -R mysql data

把下面的文件拷贝到/etc/my.cnf(生成服务器配置脚本):

[root@localhost mysql]# cp support-files/my-medium.cnf /etc/my.cnf

生成服务器启动脚本:

[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld

启动服务:

[root@localhost mysql]# service mysqld start

Starting MySQL...                                          [确定]

Mysql已经正常的运作了,下面进行库的操作:

而库一般就 /lib  /usr/lib   /usr/local/lib  在这几个目录下;

而mysql的库文件在

[root@localhost mysql]# pwd

/usr/local/mysql

进入这个目录,创建新的库文件指向:

[root@localhost mysql]# cd /etc/ld.so.conf.d/

[root@localhost ld.so.conf.d]# vim mysql.conf

添加的内容,mysql库文件路径:

LNMP 源码安装_lnmp源码安装_03

重新加载:

[root@localhost ld.so.conf.d]# ldconfig -v |grep mysql

库文件完成;

头文件一般在 /usr/include  /usr/local/include 这两个目录下;

而mysql的头文件也没有在这个目录下;所以做个链接来指向:

[root@localhost mysql]# cd /usr/include/

[root@localhost include]# ln -s /usr/local/mysql/include mysql

设置环境变量,export的效力仅及于该此登录操作:

[root@localhost ~]# export PATH=$PATH:/usr/local/mysql/bin

[root@localhost ~]#export

这样mysql就做好了;

查看一下:

LNMP 源码安装_lnmp源码安装_04

 

 

 

 

安装nginx:

[root@localhost ~]# mkdir /mnt/cdrom/

[root@localhost ~]# mount /dev/cdrom /mnt/cdrom/

[root@localhost ~]# cd /mnt/cdrom/Server/

[root@localhost Server]# vim /etc/yum.repos.d/rhel-debuginfo.repo

[rhel-server]

name=Red Hat Enterprise Linux serverbaseurl=file:///mnt/cdrom/Server

enabled=1

gpgcheck=1

gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release

 

先安装pcre,里面是库文件:

[root@localhost Server]# yum install pcre-devel

解压libevent文件到/usr/local/src/目录下:里面有一些库文件可以提高nginx性能:

[root@localhost ~]# tar -zxvf libevent-2.0.16-stable.tar.gz -C /usr/local/src/

[root@localhost ~]# cd /usr/local/src/

因为默认路径为/usr/lccal/lib是非标准路径:

所以要用编辑一个文件,来指明路径:

[root@localhost src]# vim /etc/ld.so.conf.d/libevent.conf

LNMP 源码安装_lnmp源码安装_05

保存退出;

然后进行编译工作:

[root@localhost src]# cd libevent-2.0.16-stable/

[root@localhost libevent-2.0.16-stable]# ./configure

[root@localhost libevent-2.0.16-stable]# make

[root@localhost libevent-2.0.16-stable]# make install

因为编译后会形成四个文件:头文件、库文件、可执行文件和说明文件;

把这四个文件放到合适的位置,这就是make install的作用;

 

然后调用一次:

[root@localhost libevent-2.0.16-stable]# ldconfig –v

解压缩nginx到/usr/local/src/目录下:

[root@localhost src]# tar -zxvf nginx-1.0.11.tar.gz -C /usr/local/src/

[root@localhost ~]# cd /usr/local/src/libevent-2.0.16-stable/

添加一个系统组和系统帐号:

[root@localhost libevent-2.0.16-stable]# groupadd -r nginx

[root@localhost libevent-2.0.16-stable]# useradd -r -g nginx -s /bin/false -M nginx

然后进入nginx目录下进行编译:

[root@localhost libevent-2.0.16-stable]# cd ../nginx-1.0.11/

[root@localhost nginx-1.0.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 \      //开启基于线程的nginx

--lock-path=/var/lock/nginx.lock \           //存放锁机文件的路径

--user=nginx \                           //运行者身份

--group=nginx \                         //运行者的组

--with-http_ssl_module \              //开启加密模块

--with-http_flv_module \             //开启流媒体模块

--with-http_stub_status_module \          //安装可以查看nginx状态的程序

--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      //启用地址重写

[root@localhost nginx-1.0.11]# make

[root@localhost nginx-1.0.11]# make install

 

[root@localhost ~]# mkdir -pv /var/tmp/nginx

[root@localhost ~]# nginx

测试一下nginx安装是否成功:

LNMP 源码安装_lnmp源码安装_06

 

 

 

 

安装php:

[root@localhost ~]# tar -jxvf php-5.3.7.tar.bz2 -C /usr/local/src/

[root@localhost ~]# cd /usr/local/src/php-5.3.7/

[root@localhost php-5.3.7]# ./configure  --help

我们用一下帮助:

LNMP 源码安装_lnmp源码安装_07

LNMP 源码安装_lnmp源码安装_08

LNMP 源码安装_lnmp源码安装_09

LNMP 源码安装_lnmp源码安装_10

LNMP 源码安装_lnmp源码安装_11

 

然后安装,编译:

[root@localhost php-5.3.7]# ./configure \

> --prefix=/usr/local/php \

> --with-mysql=/usr/local/mysql \

> --with-openssl \

> --enable-fpm \

> --with-libevent-dir=/usr/local \

> --with-mysqli=/usr/local/mysql/bin/mysql_config \

> --enable-mbstring \

> --with-freetype-dir \

> --with-jpeg-dir \

> --with-png-dir \

> --with-zlib \

> --with-libxml-dir=/usr \

> --enable-xml \

> --with-iconv-dir=/usr/local

[root@localhost php-5.3.7]# make

[root@localhost php-5.3.7]# make install

 

将配置文件拷到主配置目录:

[root@localhost php-5.3.7]# cp php.ini-production /usr/local/php/etc/php.ini

创建php-fpm.conf文件:

[root@localhost php-5.3.7]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

编辑该文件:

[root@localhost php-5.3.7]# vim /usr/local/php/etc/php-fpm.conf

LNMP 源码安装_lnmp源码安装_12

LNMP 源码安装_lnmp源码安装_13

编辑fastcgi.conf:

[root@localhost ~]# cd /etc/nginx/

[root@localhost nginx]# vim /etc/nginx/fastcgi.conf

LNMP 源码安装_lnmp源码安装_14

将fastcgi.conf的配置重定向到fastcgi_params:

[root@localhost nginx]# cat fastcgi.conf>fastcgi_params

启动php-fpm服务:

[root@localhost nginx]# /usr/local/php/sbin/php-fpm

配置nginx的主配置文档:

[root@localhost nginx]# vim /etc/nginx/nginx.conf

LNMP 源码安装_lnmp源码安装_15

LNMP 源码安装_lnmp源码安装_16

重新加载nginx的主配置文档:
    [root@localhost ~]# pkill -1 nginx

也可以用("pkill –9 nginx “强力关闭nginx ,然后重启 "nginx”)

 

 

最后验证

测试nginx连接php的正确性:

创建并编辑php主页index.php:

[root@localhost ~]# cd /usr/html/

[root@localhost html]# vim index.php

LNMP 源码安装_lnmp源码安装_17

LNMP 源码安装_lnmp源码安装_18

测试php连接mysql的正确性:

##编辑php主页index.php:
    [root@localhost html]# vim index.php

LNMP 源码安装_lnmp源码安装_19

LNMP 源码安装_lnmp源码安装_20