L N M P   源码安装
 
简介:
      LNMP=Nginx+MySQL+PHP 网络服务器架构;
 
一、与之前的LAMP相比较而言,最大的不同就是 Nginx 的引用,Nginx一种小巧而效率很高的服务器软件,性能稳定,功能丰富,运行简单,处理静态文件速度比较快而且消耗的资源也比较少!
   二、与之前的LAMP相比较,支持更多的并发连接,效率更高!安装比较简单,配置文件比较简洁,还支持在不间断服务的情况下进行软件版本的升级!
 
搭建LNMP所用到的:
 
系统的平台: Linux Redhat 5.4 企业版
 
 使用到的源码包
nginx-1.1.18.tar.gz
MySQL-5.5.22-1.rhel5.i386.tar
php-5.4.0.tar.bz2
 
 
***安装之前的准备工作!检测一下group组中是否存在那些必需的工具***
[root@HanYu ~]# yum grouplist
Development Libraries
Development Tools
X Software Development
[root@HanYu ~]# yum -y install pcre-devel
 
一、    源码安装Nginx
 首先增加用户 nginx   用于实现和运行nginx服务进程!
[root@HanYu ~]# useradd -r -g nginx -s /bin/false -M 
[root@HanYu ~]# useradd -r -g nginx -s /bin/false -M nginx
 
编译及安装
[root@HanYu ~]# tar xf nginx-1.1.18.tar.gz -C /usr/src/
[root@HanYu ~]# cd /usr/src/nginx-1.1.18/
[root@HanYu nginx-1.1.18]# ./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/ \
 --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
 --http-scgi-temp-path=/var/tmp/nginx/scgi \
 --with-pcre
[root@HanYu nginx-1.1.18]# make
[root@HanYu nginx-1.1.18]# make install
[root@localhost nginx-1.1.18]# netstat -tupln |grep nginx
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      11369/nginx: master
 
验证nginx:

 

 
二、        配置mysql
源码安装之前进行的操作!   安装一些关联的软件包:
[root@localhost Server]# useradd -M -s /sbin/nologin mysql
[root@localhost Server]# rpm -ivh ncurses-devel-5.5-24.20060715.i386.rpm
               
[root@localhost ~]# tar -zxvf mysql-5.0.95.tar.gz -C /usr/src/
[root@localhost ~]# cd /usr/src/mysql-5.0.95/
[root@localhost mysql-5.0.95]# ./configure \
--prefix=/usr/local/mysql \
--without-debug \
--with-extra-charsets=utf8,gbk \
--enable-assembler \
--with-mysqld-ldflags=-all-static \
--with-client-ldflags=-all-static \
--with-unix-socket-path=/tmp/mysql.sock \
--with-ssl
编译及安装!
[root@localhost mysql-5.0.95]# make && make install
[root@localhost mysql-5.0.95]# cp support-files/my-medium.cnf /etc/my.cnf
[root@localhost mysql-5.0.95]# cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql-5.0.95]# chmod +x /etc/init.d/mysqld
[root@localhost mysql-5.0.95]# ln -s /usr/local/mysql/bin/* /usr/local/bin/
[root@localhost mysql-5.0.95]# ln -s /usr/local/mysql/lib/mysql/lib* /usr/lib/
 
初始化数据库;
[root@localhost mysql-5.0.95]# mysql_install_db --user=mysql
[root@localhost mysql-5.0.95]# chown -R root.mysql /usr/local/mysql/
[root@localhost mysql-5.0.95]# chown -R mysql.mysql /usr/local/mysql/var/
 
配置完成后启动mysql
[root@localhost mysql-5.0.95]# service mysqld start
Starting MySQL.                                            [确定]
 
查看mysql所属的端口是否被占用 3306端口1
[root@localhost mysql-5.0.95]# netstat -tupln |grep 3306
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      8315/mysqld
 
验证mysql是否配置成功!
[root@localhost mysql-5.0.95]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.95-log Source distribution
 
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
 
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
mysql>
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
3 rows in set (0.03 sec)
 
mysql>quit
 
 
 
三、           源码安装php
 
  安装之前  需要安装几个依赖包:
             【一】、libmcrypt-2.5.8.tar.bz2
             【二】、mhash-0.9.9.9.tar.bz2
             【三】、mcrypt-2.6.8.tar.gz
1libmcrypt-2.5.8.tar.bz2
 
[root@localhost ~]# tar -jxvf libmcrypt-2.5.8.tar.bz2 -C /usr/src/
[root@localhost ~]# cd /usr/src/libmcrypt-2.5.8/
[root@localhost libmcrypt-2.5.8]# make && make install
[root@localhost libmcrypt-2.5.8]#./configure
[root@localhost libmcrypt-2.5.8]#make && make install
 
2mhash-0.9.9.9.tar.bz2
[root@localhost ~]# tar -jxvf mhash-0.9.9.9.tar.bz2 -C /usr/src/
[root@localhost ~]# cd /usr/src/mhash-0.9.9.9/
[root@localhost mhash-0.9.9.9]# ./configure
[root@localhost mhash-0.9.9.9]# make && make install
 
[root@localhost mhash-0.9.9.9]# ln -s /usr/local/lib/libmcrypt* /usr/lib
[root@localhost mhash-0.9.9.9]# ln -s /usr/local/lib/libmhash.* /usr/lib
 
3mcrypt-2.6.8.tar.gz
[root@localhost ~]# tar -zxvf mcrypt-2.6.8.tar.gz -C /usr/src/
[root@localhost ~]# cd /usr/src/mcrypt-2.6.8/
[root@localhost mcrypt-2.6.8]# ./configure
[root@localhost mcrypt-2.6.8]# make && make install
 
 
 
进行php的源码安装 
安装之前还要进行一些跟php依赖的安装!
[root@localhost ~]# yum -y install libxml2-devel curl-devel libpng-devel openldap-devel
 
[root@localhost ~]# tar -jxvf php-5.4.0.tar.bz2 -C /usr/src/
[root@localhost ~]# ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql/ --with-zlib --enable-xml --disable-rpath --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --with-curl --with-curlwrappers --enable-fpm --enable-fastcgi --with-mcrypt --with-gd --with-openssl --with-mhash --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc -enable-zip --enable-soap
 
 
 
 
Installing PHP CLI binary:        /usr/local/php/bin/
Installing PHP CLI man page:      /usr/local/php/php/man/man1/
Installing PHP FPM binary:        /usr/local/php/sbin/
Installing PHP FPM config:        /usr/local/php/etc/
Installing PHP FPM man page:      /usr/local/php/php/man/man8/
Installing PHP FPM status page:      /usr/local/php/php/fpm/
Installing PHP CGI binary:        /usr/local/php/bin/
Installing build environment:     /usr/local/php/lib/php/build/
Installing header files:          /usr/local/php/include/php/
Installing helper programs:       /usr/local/php/bin/
 program: phpize
 program: php-config
Installing man pages:             /usr/local/php/php/man/man1/
 page: phpize.1
 page: php-config.1
Installing PEAR environment:      /usr/local/php/lib/php/
[PEAR] Archive_Tar    - installed: 1.3.7
[PEAR] Console_Getopt - installed: 1.3.0
[PEAR] Structures_Graph- installed: 1.0.4
[PEAR] XML_Util       - installed: 1.2.1
[PEAR] PEAR           - installed: 1.9.4
Wrote PEAR system config file at: /usr/local/php/etc/pear.conf
You may want to add: /usr/local/php/lib/php to your php.ini include_path
/usr/src/php-5.4.0/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin
ln -s -f /usr/local/php/bin/phar.phar /usr/local/php/bin/phar
Installing PDO headers:          /usr/local/php/include/php/ext/pdo/
 
 
 
php创建配置文件
[root@localhost php-5.4.0]# cp php.ini-production /usr/local/php/php.ini
[root@localhost php-5.4.0]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[root@localhost php-5.4.0]# ln -s /usr/local/bin/php /usr/bin/
 
配置php-fpm   编辑 php-fpm.conf
[root@localhost php-5.4.0]# vim /usr/local/php/etc/php-fpm.conf
 
143 listen = /var/run/php-fpm/php-fpm.sock
 
[root@localhost php-5.4.0]# vim /usr/local/nginx/conf/nginx.conf
 
43         location / {
 44             root   html;
 45             index index.html index.htm index.php;
 46         }
57        location ~ \.php$ {
 58           # root           html;
 59            fastcgi_pass   unix:/var/run/php-fpm/php-fpm.sock;
 60            fastcgi_index index.php;
 61         fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_na    me;
 62            include        fastcgi_params;
 63            include        fastcgi.conf;
 64        }
 
 
 
 
[root@localhost php-5.4.0]# make && make install
 
重启nginx
[root@localhost php-5.4.0]# pkill -9 niginx
 
pkill -9   强制杀死  
pkill -1   杀死重新读取!
 
[root@localhost php-5.4.0]# cd /usr/local/nginx/html/
[root@localhost html]# vim index.php
<?php
phpinfo();
?>
验证php是否配置成功: