设为首页 收藏本站
查看: 1637|回复: 0

LNMP环境编译安装

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-12-20 08:38:06 | 显示全部楼层 |阅读模式
安装nginx
[iyunv@lnmp src]# tar -xf nginx-1.6.2.tar.gz
[iyunv@lnmp src]# ls
nginx-1.6.2  nginx-1.6.2.tar.gz
[iyunv@lnmp nginx-1.6.2]#

[iyunv@lnmp nginx-1.6.2]# useradd -s /sbin/nologin -M nginx

[iyunv@lnmp nginx-1.6.2]# ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx1.6.2 --with-http_stub_status_module --with-http_ssl_module

Make&&make install       

[iyunv@lnmp local]# ln -s /usr/local/nginx1.6.2/ /usr/local/nginx

[iyunv@lnmp local]# ll nginx/
total 16
drwxr-xr-x 2 root root 4096 Dec  8 15:56 conf
drwxr-xr-x 2 root root 4096 Dec  8 15:56 html
drwxr-xr-x 2 root root 4096 Dec  8 15:56 logs
drwxr-xr-x 2 root root 4096 Dec  8 15:56 sbin


重启nginx
[iyunv@lnmp local]# ./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

[iyunv@lnmp local]# ./nginx/sbin/nginx   启动nginx

[iyunv@lnmp local]# lsof -i :80
COMMAND  PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
nginx   4584  root    6u  IPv4  15901      0t0  TCP *:http (LISTEN)
nginx   4585 nginx    6u  IPv4  15901      0t0  TCP *:http (LISTEN)


访问测试
wKioL1hX-fLwCBcnAAB4BKApzic748.jpg


配置nginx
[iyunv@lnmp conf]# grep html nginx.conf
            root   html;  默认站点


[iyunv@lnmp conf]# ll
total 60
-rw-r--r-- 1 root root 1034 Dec  8 15:56 fastcgi.conf  动态位置文件
-rw-r--r-- 1 root root 1034 Dec  8 15:56 fastcgi.conf.default
-rw-r--r-- 1 root root  964 Dec  8 15:56 fastcgi_params
-rw-r--r-- 1 root root  964 Dec  8 15:56 fastcgi_params.default
-rw-r--r-- 1 root root 2837 Dec  8 15:56 koi-utf
-rw-r--r-- 1 root root 2223 Dec  8 15:56 koi-win
-rw-r--r-- 1 root root 3957 Dec  8 15:56 mime.types
-rw-r--r-- 1 root root 3957 Dec  8 15:56 mime.types.default
-rw-r--r-- 1 root root 2656 Dec  8 15:56 nginx.conf   静态配置文件
-rw-r--r-- 1 root root 2656 Dec  8 15:56 nginx.conf.default


配置虚拟主机


[iyunv@lnmp conf]# mkdir ../html/{www,blog,bbs}
[iyunv@lnmp conf]# for i in www blog bbs;do echo "http://$i.bier.org" >../html/$i/index.html;done         
[iyunv@lnmp conf]# 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_type  application/octet-stream;
    sendfile        on;

    keepalive_timeout  65;

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


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

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

}



[iyunv@lnmp 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

[iyunv@lnmp nginx]# ./sbin/nginx -s reload   加载配置文件


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




安装mysql

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


拷贝启动脚本
[iyunv@lnmp mysql]# cp support-files/mysql.server /etc/init.d/mysqld

[iyunv@lnmp mysql]# vi /etc/init.d/mysqld

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


[iyunv@lnmp mysql]# chkconfig --add mysqld
[iyunv@lnmp mysql]# chkconfig --list |grep mysqld
mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off
[iyunv@lnmp mysql]# chkconfig mysqld on


拷贝配置文件
[iyunv@lnmp mysql]# cp support-files/my-small.cnf /etc/my.cnf


初始化数据库
[iyunv@lnmp mysql]# ./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

[iyunv@lnmp mysql]# /etc/init.d/mysqld start
Starting MySQL.... SUCCESS!



[iyunv@lnmp mysql]# lsof -i :3306      
COMMAND   PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
mysqld  35035 mysql   10u  IPv4  48207      0t0  TCP *:mysql (LISTEN)




连接数据库
[iyunv@lnmp mysql]# which mysql
/usr/bin/which: no mysql in (/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)

[iyunv@lnmp mysql]# find /usr/local/ -type f -name "mysql"
/usr/local/mysql/bin/mysql

[iyunv@lnmp mysql]# cp /usr/local/mysql/bin/mysql /usr/local/sbin/


[iyunv@lnmp mysql]# 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 ===> fcgi  php-fpm   port 9000

安装准备
yum install zlib libxml libjpeg freetype libpng gd  curl libiconv  zlib-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的配置文件
[iyunv@lnmp php-5.3.27]# pwd
/usr/local/src/php-5.3.27
[iyunv@lnmp php-5.3.27]# ls -l php.ini-*
-rw-r--r-- 1 101 101 69606 Jul 10  2013 php.ini-development
-rw-r--r-- 1 101 101 69627 Jul 10  2013 php.ini-production

[iyunv@lnmp php-5.3.27]# cp /usr/local/src/php-5.3.27/php.ini-production /usr/local/php/lib/php.ini

php的配置文件php.ini




启动模式是fcgi的模式
[iyunv@lnmp etc]# pwd
/usr/local/php/etc
[iyunv@lnmp etc]# ll
total 28
-rw-r--r-- 1 root root  1212 Dec  8 21:34 pear.conf
-rw-r--r-- 1 root root 21669 Dec  8 21:34 php-fpm.conf.default
[iyunv@lnmp etc]# mv php-fpm.conf.default php-fpm.conf

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


[iyunv@lnmp etc]# mkdir /app/logs –p


检测重启
[iyunv@lnmp php]# ./sbin/php-fpm -t
[08-Dec-2015 21:57:55] NOTICE: configuration file /usr/local/php5.3.27/etc/php-fpm.conf test is successful



[iyunv@lnmp php]# 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复制配置粘贴到下面更改
[iyunv@lnmp extra]# vim bbs.conf
server {
        listen       80;
        server_name  bbs.bier.org;
            root   html/bbs;
            index  index.html index.htm;

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


       }

检测
[iyunv@lnmp nginx]# ../php/sbin/php-fpm -t
[08-Dec-2015 22:14:15] NOTICE: configuration file /usr/local/php5.3.27/etc/php-fpm.conf test is successful


加载nginx配置文件
[iyunv@lnmp nginx]# ./sbin/nginx -s reload

[iyunv@lnmp bbs]# pwd
/usr/local/nginx/html/bbs
[iyunv@lnmp bbs]# cat info.php
<?php
phpinfo();
?>


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




PHP测试连接mysql
[iyunv@lnmp bbs]# 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();
        }
?>

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

或者这样子测试
[iyunv@lnmp bbs]# /usr/local/php/bin/php mysql.php
mysql successful by bier !


到此lnmp安装完成。


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-316685-1-1.html 上篇帖子: LAMP中的php编译安装 下篇帖子: 搭建LNMP网站服务平台
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表