day 47 LNMP介绍
12.1 LNMP架构介绍
- LNMP: Linux+Nginx+MySQL+PHP
- Nginx提供web服务
- PHP作为一个独立服务存在的,该服务叫php-fpm
- Nginx直接处理静态请求,动态请求会转发给php-fpm
12.2 MySQL安装
- cd /usr/local/src
- wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
- tar zxvf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
- mv mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql
- cd /usr/local/mysql
- useradd mysql
- mkdir /data/
- ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
- cp support-files/my-default.cnf /etc/my.cnf
- cp support-files/mysql.server /etc/init.d/mysqld
- vim /etc/init.d/mysqld #编辑启动脚本,定义basedir和datadir
- /etc/init.d/mysqld start #启动mysql服务
LNMP的PHP安装方法和LAMP安装PHP方法有差别,需要开启php-fpm服务
- cd /usr/local/src/
- wget http://cn2.php.net/distributions/php-5.6.30.tar.gz
- tar zxvf php-5.6.30.tar.gz
- useradd -s /sbin/nologin php-fpm #创建php-fpm用户
- cd php-5.6.30
- ./configure --prefix=/usr/local/php-fpm --with-config-file-path=/usr/local/php-fpm/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --with-pear --with-curl --with-openssl
- make
- make install
- cp php.ini-production /usr/local/php-fpm/etc/php.ini
- vim /usr/local/php/etc/php-fpm.conf #编辑php-fpm配置文件(参考https://coding.net/u/aminglinux/p/aminglinux-book/git/blob/master/D15Z/php-fpm.conf)
- cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
- chmod 755 /etc/init.d/php-fpm
- chkconfig --add php-fpm
- chkconfig php-fpm on #开机启动php-fpm服务
- service php-fpm start #启动php-fpm服务
- ps aux |grep php-fpm #查看服务是否启动成功
- Nginx官网 nginx.org,最新版1.13,最新稳定版为1.12
- Nginx应用场景:web服务、反向代理、负载均衡
- Nginx著名分支,淘宝基于Nginx开发的Tengine,使用上和Nginx一致,服务名,配置文件名都一样,和Nginx的最大区别在于Tenging增加了一些定制化模块,在安全限速方面表现突出,另外它支持对js,css合并
- Nginx核心+lua相关的组件和模块组成了一个支持lua的高性能web容器openresty,参考http://jinnianshilongnian.iteye.com/blog/2280928