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

源码编译安装LNMP

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-7-14 10:54:34 | 显示全部楼层 |阅读模式
Nginx是一种最重要的技能,在公司里可以不会其他的,nginx精通了你也可以所向披靡。

这篇文章也许是有史以来最长的文章了,没有之一。


LNMP=Linux Nginx MysqlPHP

nginx在工作中是非常重要的web服务器,它是一个高性能的 HTTP 和 反向代理 服务器,也是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,百度BWS、新浪、网易、腾讯等都是使用的是nginx

Nginx的工作原理

Nginx 本身只支持静态页面的处理,当客户端访问php页面的时候,nginx会将php转到php-fpm也处理,
php-fpm服务会把php页面解析成html文件给nginx处理,nginx返回给客户端处理
本次编译所需要的软件版本:
libmcrypt-2.5.8

mysql-1.60

nginx-1.8.0

pcre-8.37

php-5.6.13

jpegsrc.v7
编译前安装环境:
1
2
[iyunv@Xinsz08 ~]# yum install gcc gcc-c++autoconf automake zlib zlib-devel openssl openssl-devel pcre* -y
root@Xinsz08 ~]# tar xf pcre-8.37.tar.bz2 -C /usr/local/src/          //解压此安装包即可,不需要安装



解压编译安装nginx:
1
2
[iyunv@Xinsz08 ~]# tar xvf nginx-1.9.4.tar.gz-C /usr/local/src/ ;
cd /usr/local/src/nginx-1.9.4




1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@Xinsz08nginx-1.8.0]# ./configure --prefix=/usr/local/nginx
--with-http_dav_module  //
   #启用支持(增加PUT,DELETE,MKCOL:创建集合,COPY和MOVE方法)
--with-http_stub_status_module //
#启用支持(获取Nginx上次启动以来的工作状态)
--with-http_addition_module
#启用支持(作为一个输出过滤器,支持不完全缓冲,分部分相应请求)
--with-http_sub_module
#启用支持(允许一些其他文本替换Nginx相应中的一些文本)
--with-http_flv_module
#启用支持(提供支持flv视频文件支持)
--with-http_mp4_module
#启用支持(提供支持mp4视频文件支持,提供伪流媒体服务端支持)
--with-pcre=/usr/local/src/pcre-8.37




1
root@Xinsz08 nginx-1.9.4]# make - j 3 ;make install ; cd





1
2
[iyunv@Xinsz08 ~]# useradd -M -u 8001-s /sbin/nologinnginx           //
用于运行Nginx的用户




配置Nginx支持php文件
1
2
[iyunv@Xinsz08 ~]# vim/usr/local/nginx/conf/nginx.conf                 
//Nginx主配置文件




#user  nobody;                 

user nginx nginx;                   #添加此行

……

并在所支持的主页面格式中添加php格式的主页,类似如下:

location / {

            root   html;

            index  index.php index.html index.htm;

        }


        #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;

        #}                      #找到上面这段内容,将这段内容复制,去掉#且修改为如下

location ~ \.php$ {

    root           html;

    fastcgi_pass   127.0.0.1:9000;

    fastcgi_index  index.php;

    fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;      #将scripts修改为nginx的html,即Nginx页面目录,因为要处理的php文件也在这个目录下

    include        fastcgi_params;

}


启动Nginx
1
[iyunv@Xinsz08 ~]#/usr/local/nginx/sbin/nginx



1
2
[iyunv@localhost conf]# cd /etc/init.d/
[iyunv@localhost init.d]# vi nginxd (书写启动的shell)



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
#Author ethnicity(Just a check of others)
#Time 2011-9-24
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/usr/local/nginx/logs/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
   echo "nginx already running...."
   exit 1
fi
echo -n $"Starting $prog: "
   daemon $nginxd -c ${nginx_config}
   RETVAL=$?
   echo
   [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
   return $RETVAL
}
# Stop nginx daemons functions.
stop() {
        echo -n $"Stopping $prog: "
        killproc $nginxd
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
}
# reload nginx service functions.
reload() {
    echo -n $"Reloading $prog: "
    #kill -HUP `cat ${nginx_pid}`
    killproc $nginxd -HUP
    RETVAL=$?
    echo
}
# See how we were called.
case "$1" in
start)
        start
        ;;
stop)
        stop
        ;;
reload)
        reload
        ;;
restart)
        stop
        start
        ;;
status)
        status $prog
        RETVAL=$?
        ;;
*)
        echo $"Usage: $prog {start|stop|restart|reload|status|help}"
        exit 1
esac
exit $RETVAL





1
[iyunv@localhost init.d]# chmod a+x nginxd



1
[iyunv@localhost ~]# service nginxd  restart




使用浏览器测试   http://IP





编译安装MySql

1
2
3
4
5
6
tar zvxf mysql-5.1.60.tar.gz -C /usr/src
    cd /usr/src/mysql-5.1.60/

    ./configure --prefix=/usr/local/mysql

    make && make install




配置mysql

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
PATH=$PATH:/usr/local/mysql/bin
  echo $PATH
   mkdir -p /var/run/mysqld   
   useradd -M -s /sbin/nologin mysql
   chown -R  mysql /usr/local/mysql/
   /usr/local/mysql/bin/mysql_install_db --user=mysql
   /usr/local/mysql/bin/mysqld_safe --user=mysql
cd /usr/src/mysql-5.1.60
  cp -p support-files/mysql.server /etc/rc.d/init.d/mysqld
    chmod a+x /etc/rc.d/init.d/mysqld
  chkconfig --add mysqld
   chkconfig --list mysqld
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
   netstat -nultp | grep ":3306"
ln -s /usr/local/mysql/bin/mysql /usr/bin/
service mysqld start
    mysqladmin -u root password '123456'





编译安装PHP

解决依赖
1
2
[iyunv@Xinsz08~]# yum install -y php-pear* xmlrpc*  mhash*  gd* libxml* zlib* freetype* libpng-devel* libcurl-devel*               
   //pear按照一定的分类来管理pear应用代码库




1
2
[iyunv@Xinsz08 ~]# tar xf libmcrypt-2.5.8.tar.bz2 -C /usr/local/src/ ;
cd /usr/local/src/libmcrypt-2.5.8/





1
2
[root@Xinsz08libmcrypt-2.5.8]# ./configure --prefix=/usr/local/libmcrypt ;
make ; makeinstall ; cd




由于系统默认规定只在/lib、/lib64、/lib/lib64下面找库文件,所以我们需要手动添加进去。

1
  [iyunv@Xinsz08 ~]# vim /etc/ld.so.conf





include ld.so.conf.d/*.conf                          #此行原有

/usr/local/libmcrypt/lib                       #此行添加

/usr/local/mysql/lib                           #此行添加

1
2
[iyunv@Xinsz08 ~]# ldconfig
[iyunv@Xinsz08 ~]# echo 'ldconfig' >>/etc/rc.local




编译安装php
1
  [iyunv@Xinsz08~]# tar xf php-5.6.13.tar.bz2 -C /usr/local/src/ ; cd/usr/local/src/php-5.6.13





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
[iyunv@Xinsz08 php-5.6.13]# ./configure --prefix=/usr/local/php
  #设置 php.ini 的搜索路径。默认为 PREFIX/lib
--with-config-file-path=/usr/local/php
--with-mysql=/usr/local/mysql
#mysql安装目录,对mysql的支持
--with-mysqli=/usr/local/mysql/bin/mysql_config
#mysqli扩展技术不仅可以调用MySQL的存储过程、处理MySQL事务,而且还可以使访问数据库工作变得更加稳定。是一个数据库驱动
--with-iconv-dir
#种字符集间的转换
--with-freetype-dir
#打开对freetype字体库的支持
--with-jpeg-dir
#打开对jpeg图片的支持
--with-png-dir
#打开对png图片的支持
--with-zlib
#打开zlib库的支持,实现GZIP压缩输出     
--with-libxml-dir=/usr
#打开libxml2库的支持,libxml是一个用来解析XML文档的函数库
--enable-xml
#支持xml文档
--disable-rpath
--enable-bcmath
--enable-shmop
--enable-sysvsem
--enable-inline-optimization
--with-curl
--enable-mbregex
--enable-fpm
--enable-mbstring
--with-gd
--enable-gd-native-ttf
--with-openssl
--with-mhash
--enable-pcntl
--enable-sockets
--with-xmlrpc
--enable-zip
--enable-soap
--with-mcrypt=/usr/local/libmcrypt
[iyunv@Xinsz08 php-5.6.13]#make -j 3 && make install ; cd




配置php和php-fpm

PHP配置文件:

1
[iyunv@Xinsz08~]# cp /usr/local/src/php-5.6.13/php.ini-production /usr/local/php/php.ini





PHP-FPM配置文件:


1
     [iyunv@Xinsz08~]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf




修改 /usr/local/php/etc/php-fpm.conf 运行用户和组改为nginx


PHP-FPM启动脚本


1
2
3
4
[iyunv@Xinsz08~]# cp /usr/local/src/php-5.6.13/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[iyunv@Xinsz08~]# chmod +x /etc/init.d/php-fpm
[iyunv@Xinsz08 ~]# chkconfig php-fpm on
[iyunv@Xinsz08 ~]# /etc/init.d/php-fpmstart






测试LNMP的PHP支持

1
2
[iyunv@Xinsz08~]#
echo "<?php phpinfo(); ?>" > /usr/local/nginx/html/index.php




浏览器访问:http://IP




运维网声明 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-243960-1-1.html 上篇帖子: LNMP环境No input file specified.的解决方法 下篇帖子: CentOS7下安装部署LAMP环境
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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