20180606

6月6日任务
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

1. LNMP架构介绍

LNMP: Linux, Nginx, MySQL, PHP
Nginx优点: 轻量级web服务器, 支持反向代理, 并发能力强, 负载性能好, 处理动态请求的能力比Apache弱

2. 安装MySQL

2.1 把之前的MySQL删掉

查看进程, 如有先结束
ps aux |grep mysql
删除目录和启动脚本
rm -rf /usr/local/mysql
rm -rf /etc/init.d/mysqld
rm -rf /data/mysql/*

2.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/ ## 创建data目录
./scripts/mysql_install_db --user=mysql --datadir=/data/mysql

拷贝配置文件并编辑
cp support-files/my-default.cnf /etc/my.cnf
vim /etc/my.cnf
修改如下内容:

datadir=/data/mysql
socket=/tmp/mysql.sock

拷贝启动脚本
cp support-files/mysql.server /etc/init.d/mysqld
编辑启动脚本
vim /etc/init.d/mysqld
修改以下内容

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

加入开机启动
chkconfig --add mysqld
启动服务
/etc/init.d/mysqld start

3. 安装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
make && make install

错误解决
yum install -y libcurl-devel

拷贝配置文件
cp php.ini-production /usr/local/php-fpm/etc/php.ini

vim /usr/local/php-fpm/etc/php-fpm.conf //写入如下内容
(参考https://coding.net/u/aminglinux/p/aminglinux-book/git/blob/master/D15Z/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 = 127.0.0.1:9000
listen.mode = 666 #定义sock文件的权限为666. 不定义的话会是660
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

拷贝启动脚本
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
ps aux |grep php-fpm

未经允许不得转载:外贸SOHO笔记 » 20180606

赞 (0) 打赏

评论 0

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下作者~

支付宝扫一扫打赏

微信扫一扫打赏