12.1 LNMP架构介绍 12.2 MySQL安装 12.3/12.4 PHP安装 12.5 Nginx介绍
** 扩展** Nginx为什么比Apache Httpd高效:原理篇 http://www.toxingwang.com/linux-unix/linux-basic/1712.html apache和nginx工作原理比较 http://www.server110.com/nginx/201402/6543.html mod_php 和 mod_fastcgi以及php-fpm的比较 http://dwz.cn/1lwMSd 概念了解:CGI,FastCGI,PHP-CGI与PHP-FPM http://www.nowamagic.net/librarys/veda/detail/1319/ https://www.awaimai.com/371.html~~
LNMP架构介绍
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 ** 此处报错按一下提示操作:**
一.
FATAL ERROR: please install the following Perl modules before executing ./scripts/mysqlinstalldb:
Data::Dumper
[root@izbp1iei7rfo61naj23hlez mysql]# ^C
[root@izbp1iei7rfo61naj23hlez mysql]# yum install -y perl-Module-Install.noarch
二.
Installing MySQL system tables..../bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
[root@izbp1iei7rfo61naj23hlez mysql]# yum install libaio -y
vim /etc/my.cnf [mysqld] datadir=/data/mysql socket=/tmp/mysql.sock [mysqld_safe] #log-error=/var/log/mysql/mysql.log #pid-file=/var/run/mysqld/mysqld.pid
cp support-files/mysql.server /etc/init.d/mysqld vi /etc/init.d/mysqld 定义basedir和datadir
basedir=/usr/local/mysql datadir=/data/mysql
/etc/init.d/mysqld start #添加服务进去 chkconfig --add mysql 设置开机启动 chkconfig mysql on service mysql start
[root@izbp1iei7rfo61naj23hlez mysql]# service mysqld start Starting MySQL [ OK ]
PHP安装
和LAMP安装PHP方法有差别,需要开启php-fpm服务 cd /usr/local/src/ wget http://cn2.php.net/distributions/php-5.6.30.tar.gz tar zxf php-5.6.30.tar.gz useradd -s /sbin/nologin 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 ** 可能会报错** 一.
configure: error: xml2-config not found. Please check your libxml2 installation
[root@izbp1iei7rfo61naj23hlez php-5.6.30]#yum install libxml2 [root@izbp1iei7rfo61naj23hlez php-5.6.30]#yum install libxml2-devel -y 二. configure: error: Cannot find OpenSSL's <evp.h> [root@izbp1iei7rfo61naj23hlez php-5.6.30]# yum install openssl openssl-devel -y 三. configure: error: Please reinstall the libcurl distribution - easy.h should be in <curl-dir>/include/curl/ [root@izbp1iei7rfo61naj23hlez php-5.6.30]# yum install curl curl-devel -y 四. configure: error: jpeglib.h not found. [root@izbp1iei7rfo61naj23hlez php-5.6.30]# yum -y install libjpeg-devel 五. configure: error: png.h not found. yum install -y libpng yum install -y libpng-devel 六. configure: error: freetype-config not found. yum install -y freetype-devel.x86_64 七. configure: error: mcrypt.h not found. Please reinstall libmcrypt yum install -y epel-release yum install -y libmcrypt-devel
安装成功 make && make install cp php.ini-production /usr/local/php-fpm/etc/php.ini cd /usr/local/php-fpm/etc/ mv php-fpm.conf.default php-fpm.conf 或者
[global] pid = /usr/local/php-fpm/var/run/php-fpm.pid error_log = /usr/local/php-fpm/var/log/php-fpm.log [www] listen = /tmp/php-fcgi.sock listen.mode = 666 user = php-fpm group = php-fpm pm = dynamic pm.max_children = 50 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35 pm.max_requests = 500 rlimit_files = 1024
vi /usr/local/php/etc/php-fpm.conf //写入如下内容(参考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 service php-fpm start
[root@izbp1iei7rfo61naj23hlez php-5.6.30]# service php-fpm start Starting php-fpm [23-Apr-2018 22:51:37] ERROR: failed to open configuration file '/usr/local/php-fpm/etc/php-fpm.conf': No such file or directory (2) [23-Apr-2018 22:51:37] ERROR: failed to load configuration file '/usr/local/php-fpm/etc/php-fpm.conf' [23-Apr-2018 22:51:37] ERROR: FPM initialization failed failed
此时可以用/usr/local/php-fpm/sbin/php-fpm -t 如果报错以下信息 [root@izbp1iei7rfo61naj23hlez php-5.6.30]# /usr/local/php-fpm/sbin/php-fpm -t [23-Apr-2018 22:57:25] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful
useradd -s /sbin/nologin php-fpm ** 启动成功** **[root@izbp1iei7rfo61naj23hlez php-5.6.30]# service php-fpm start Starting php-fpm done ** ps aux |grep php-fpm
Nginx介绍
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