8767564323 发表于 2016-12-20 08:38:06

LNMP环境编译安装

安装nginx
# tar -xf nginx-1.6.2.tar.gz
# ls
nginx-1.6.2nginx-1.6.2.tar.gz
#

# useradd -s /sbin/nologin -M nginx

# ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx1.6.2 --with-http_stub_status_module --with-http_ssl_module

Make&&make install       

# ln -s /usr/local/nginx1.6.2/ /usr/local/nginx

# ll nginx/
total 16
drwxr-xr-x 2 root root 4096 Dec8 15:56 conf
drwxr-xr-x 2 root root 4096 Dec8 15:56 html
drwxr-xr-x 2 root root 4096 Dec8 15:56 logs
drwxr-xr-x 2 root root 4096 Dec8 15:56 sbin


重启nginx
# ./nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx1.6.2/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx1.6.2/conf/nginx.conf test is successful

# ./nginx/sbin/nginx   启动nginx

# lsof -i :80
COMMANDPIDUSER   FD   TYPE DEVICE SIZE/OFF NODE NAME
nginx   4584root    6uIPv415901      0t0TCP *:http (LISTEN)
nginx   4585 nginx    6uIPv415901      0t0TCP *:http (LISTEN)


访问测试



配置nginx
# grep html nginx.conf
            root   html;默认站点


# ll
total 60
-rw-r--r-- 1 root root 1034 Dec8 15:56 fastcgi.conf动态位置文件
-rw-r--r-- 1 root root 1034 Dec8 15:56 fastcgi.conf.default
-rw-r--r-- 1 root root964 Dec8 15:56 fastcgi_params
-rw-r--r-- 1 root root964 Dec8 15:56 fastcgi_params.default
-rw-r--r-- 1 root root 2837 Dec8 15:56 koi-utf
-rw-r--r-- 1 root root 2223 Dec8 15:56 koi-win
-rw-r--r-- 1 root root 3957 Dec8 15:56 mime.types
-rw-r--r-- 1 root root 3957 Dec8 15:56 mime.types.default
-rw-r--r-- 1 root root 2656 Dec8 15:56 nginx.conf   静态配置文件
-rw-r--r-- 1 root root 2656 Dec8 15:56 nginx.conf.default


配置虚拟主机


# mkdir ../html/{www,blog,bbs}
# for i in www blog bbs;do echo "http://$i.bier.org" >../html/$i/index.html;done         
# for i in www blog bbs;do cat ../html/$i/index.html;done
http://www.bier.org
http://blog.bier.org
http://bbs.bier.org

打开配置文件
http {
    include       mime.types;
    default_typeapplication/octet-stream;
    sendfile      on;

    keepalive_timeout65;

    server {
      listen       80;
      server_namewww.bier.org;
            root   html/www;
            indexindex.html index.htm;
      }


    server {
      listen       80;
      server_nameblog.bier.org;
            root   html/blog;
            indexindex.html index.htm;
            indexindex.html index.htm;
      }

    server {
      listen       80;
      server_namebbs.bier.org;
            root   html/bbs;
            indexindex.html index.htm;
      }

}



# ./sbin/nginx -t
nginx: the configuration file /usr/local/nginx1.6.2/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx1.6.2/conf/nginx.conf test is successful

# ./sbin/nginx -s reload   加载配置文件


配置好hosts,浏览器测试访问




安装mysql

安装mysql(二进制包安装方式,直接解压,初始化数据库即可,无需编译)
# useradd mysql -s /sbin/nologin –M
#tar -xf mysql-5.5.32-linux2.6-x86_64.tar.gz
#mv mysql-5.5.32-linux2.6-x86_64 mysql
# chown -R mysql.mysql ./mysql/data


拷贝启动脚本
# cp support-files/mysql.server /etc/init.d/mysqld

# vi /etc/init.d/mysqld

basedir=/usr/local/mysql
datadir=/usr/local/mysql/data


# chkconfig --add mysqld
# chkconfig --list |grep mysqld
mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off
# chkconfig mysqld on


拷贝配置文件
# cp support-files/my-small.cnf /etc/my.cnf


初始化数据库
# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/


when specifying MySQL privileges !
Installing MySQL system tables...
OK
Filling help tables...
OK

You can start the MySQL daemon with:
cd /usr/local/mysql/ ; /usr/local/mysql//bin/mysqld_safe &



启动mysql

# /etc/init.d/mysqld start
Starting MySQL.... SUCCESS!



# lsof -i :3306      
COMMAND   PIDUSER   FD   TYPE DEVICE SIZE/OFF NODE NAME
mysqld35035 mysql   10uIPv448207      0t0TCP *:mysql (LISTEN)




连接数据库
# which mysql
/usr/bin/which: no mysql in (/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)

# find /usr/local/ -type f -name "mysql"
/usr/local/mysql/bin/mysql

# cp /usr/local/mysql/bin/mysql /usr/local/sbin/


# mysql   输入mysql登录数据库
Welcome to the MySQL monitor.Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.32 MySQL Community Server (GPL)

Copyright (c) 2000, 2013, 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>       



安装php
Lnmp下的php
Apache==>libphp5.so
Nginx php ===> fcgiphp-fpm   port 9000

安装准备
yum install zlib libxml libjpeg freetype libpng gdcurl libiconvzlib-devel libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel -y

字符集
tar zxf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local/libiconv
make
make install


加密的库
tar -xf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make
make install
sleep 2
/sbin/ldconfig
cd libltdl/
./configure --enable-ltdl-install
make
make install

tar -xf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure
make
make install




加密扩展库
tar -xf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
/sbin/ldconfig
./configure LD_LIBRARY_PATH=/usr/local/lib
make
make install


再安装一个包,不然编译的时候会出错
yum install libxslt* -y




开始安装php
tar -xf php-5.3.27.tar.gz
cd php-5.3.27
./configure \
--prefix=/usr/local/php5.3.27 \
--with-mysql=/usr/local/mysql \
--with-libxml-dir=/usr \
--with-zlib \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-iconv-dir=/usr/local/libiconv \
--enable-xml \
--with-curl \
--with-curlwrappers \
--disable-rpath \
--enable-safe-mode \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--enable-mbregex \
--enable-fpm \
--enable-mbstring \
--with-mcrypt \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--enable-short-tags \
--enable-zend-multibyte \
--enable-static \
--with-xsl \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--enable-ftp

要这样子处理,不然会报错
ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/

make
make install


ln -s /usr/local/php5.3.27/ /usr/local/php


拷贝php的配置文件
# pwd
/usr/local/src/php-5.3.27
# ls -l php.ini-*
-rw-r--r-- 1 101 101 69606 Jul 102013 php.ini-development
-rw-r--r-- 1 101 101 69627 Jul 102013 php.ini-production

# cp /usr/local/src/php-5.3.27/php.ini-production /usr/local/php/lib/php.ini

php的配置文件php.ini




启动模式是fcgi的模式
# pwd
/usr/local/php/etc
# ll
total 28
-rw-r--r-- 1 root root1212 Dec8 21:34 pear.conf
-rw-r--r-- 1 root root 21669 Dec8 21:34 php-fpm.conf.default
# mv php-fpm.conf.default php-fpm.conf

改一下他默认的配置文件,然后启动,
把php-fpm.conf.default 变成php-fpm.conf


# mkdir /app/logs –p


检测重启
# ./sbin/php-fpm -t
NOTICE: configuration file /usr/local/php5.3.27/etc/php-fpm.conf test is successful



# netstat -lnptu |grep php-fpm
tcp      0      0 127.0.0.1:9000            0.0.0.0:*                   LISTEN      30227/php-fpm   





配置php整合nginx

从nginx.conf.default复制配置粘贴到下面更改
# vim bbs.conf
server {
      listen       80;
      server_namebbs.bier.org;
            root   html/bbs;
            indexindex.html index.htm;

      location ~ .*\.(php|php5)?$
      {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_indexindex.php;
            include fastcgi.conf;
      }


       }

检测
# ../php/sbin/php-fpm -t
NOTICE: configuration file /usr/local/php5.3.27/etc/php-fpm.conf test is successful


加载nginx配置文件
# ./sbin/nginx -s reload

# pwd
/usr/local/nginx/html/bbs
# cat info.php
<?php
phpinfo();
?>


访问测试
http://bbs.bier.org/info.php




PHP测试连接mysql
# vi mysql.php

<?php
       
        $link_id=mysql_connect('localhost','root','bier123') or mysql_error();

        if($link_id){
                echo "mysql successful by bier !";
        }else{
                echo mysql_error();
        }
?>

浏览器访问测试 (不需要重启服务)

或者这样子测试
# /usr/local/php/bin/php mysql.php
mysql successful by bier !


到此lnmp安装完成。

页: [1]
查看完整版本: LNMP环境编译安装