LAMP

1 LAMP 介绍

LAMMP的介绍
L: linux, A: apache (httpd) M: MySQL MariaDB M:memcached P: php,perl,python
WEB资源的类型:
  静态资源: 原始形式与响应内容一致
  动态资源: 原始形式通常为程序文件,需要在服务器端执行后,将执行结果返回给客户端
CGI: Common Gateway Interface
  可以让客户端,从网页浏览器通过http服务器向执行在网络服务器上的程序传输数据;CGI描述了客户端和服务器程序之间传输的一种标准
  程序=指令+数据
    指令: 代码文件
    数据: 数据存储系统,文件
  请求流程:
    Client --> httpd --> httpd--(cgi) --> application server(program file) --(mysql)-->mysql
  php: 脚本编程语言,嵌入到html中的嵌入式web程序语言,基于zend编译成opcode(二进制格式的字节码,重复运行,可省略编译环境)
  opcode是一种PHP脚本编译后的中间语言,类似于Java的ByteCode,或者.NET的MSL.PHP执行脚本代码一般会经过如下4个步骤(确切的来说,应该为PHP的语言引擎Zend)
    1 Scanning 语法分析,将PHP代码转化为语言片段(Tokens)
    2 Parsing 语义分析,将Tokens转换成简单而有意义的表达式
    3 Compilation 将表达式编译成Opcodes
    4 Executing 顺次执行Opcodes,每次一条,从而实现PHP脚本的功能
      扫描 --> 分析 --> 编译 --> 执行

2 PHP配置

php: 脚本语言解释器
  配置文件: /etc/php.ini, /etc/php.d/*.ini
  配置文件在php解释器启动时被读取
  对配置文件的修改生效方法
    Modules: 重启httpd的服务
    FastCGI: 重启php-fpm服务
  /etc/php.ini配置文件格式:
    [foo]: Section Header
    directive = value
  PHP的配置
    max_execution_time=30 最长执行时间30s
    memory_lmit 128M 生产不大,可调大
    display_errors off 调试使用,不要打开,否则可能会会暴露重要信息
    display_startup_errors off 建议关闭,开启启动时的错误提示
    post_amx_size 8M 最大上传数据大小,生产可能临时要调大,比下面选项要大
    upload_max_filesize 2M 最大上传文件,生产可能要调大
    max_file_uploads =20 同时上传最多文件数
    date.timezone=Asia/Shanghai 指定时区
    收人头_Open_tag= on 开启短标签
php与mysql连接的方式:
mysql的扩展,mysqli的扩展,pdo
  使用mysql扩展连接数据库
     
  使用mysqli扩展连接数据库
     close();
    ?>
httpd和php的结合方式
  1 module: php
  2 cgi  #不常用
  3 fastcgi: php-fpm
CentOS 6:
  PHP-5.3.2之前:默认不支持fpm机制;需要自行打补丁编译安装
  httpd-2.2:默认不支持fcgi协议,需要自行编译此模块
  解决方案:编译安装httpd-2.4, php-5.3.3+
CentOS 7:
  httpd-2.4:rpm包默认编译支持了fcgi模块
  php-fpm包:专用于将php运行于fpm模式
配置php和httpd基于模块形式来运行
配置FastCGI
在服务器上必须开启proxy_fcgi_module模块,充当PHP客户端
  
    ServerName www.johniu.com
    DocumentRoot /var/www/html
    ProxyRequests Off  #关闭正向代理
    ProxyPassMatch ^/(.*\.php)$   fcgi://127.0.0.1:9000/var/www/html/$1
    
      Options None
      AllowOverride None
      Require all granted
    
  

6 源码编译LAMP

在CentOS 6 源码编译httpd
编译安装httpd-2.4和php-5.6
  httpd2.4
  1 yum install @"Development tools" pcre-devel  openssl-devel expat-devel
  2 下载安装apr和apr-util 版本必须大于2.3
    ./configure --prefix=/usr/local/apr 
     make && make install
    ./configure --prefix=/usr/local/apr-util
     make && make install 
  4 下载httpd的源码包 
    ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork
  5 make && make install
  6 在http的配置文件中添加 AddType application/x-httpd-php  .php\n    AddType application/x-httpd-php-source  .phps 使其支持php文件
  编译安装 php-5.6(模块)
  1 yum install libxml2-devel bzip2-devel libmcrypt-devel(epel源)
  2 ./configure --prefix=/usr/local/php --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --with-mysqli=mysqlnd --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml  --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs --with-mcrypt  --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2  --enable-maintainer-zts
  3 make && make install
  4 cp php.ini-production /etc/php.ini
  编译安装 php-5.6 FastCGI
  1 yum install  libxml2-devel bzip2-devel libmcrypt-devel libmcrypt mhash mhash-devel
  ./configure --prefix=/usr/local/php5 --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --with-mysqli=mysqlnd --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml  --enable-sockets --enable-fpm --with-mcrypt  --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php5.d --with-bz2
  2 make && make install 
  3 设定一些php-fpm的运行配置和参数
     cp php.ini-production /etc/php5.ini
     cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm && chmod u+x /etc/rc.d/init.d/php-fpm
     chkconfig --add /etc/rc.d/init.d/php-fpm
     cp /usr/local/php5/etc/php-fpm.conf.default /usr/local/php5/etc/php-fpm.conf

7 以二进制格式安装mysql

1 到官方网站下载mysql的二进制的包
  mariadb-5.5.43-linux-x86_64.tar.gz
2 解压到 /usr/local/并创建软连接
   tar xf mariadb-5.5.43-linux-x86_64.tar.gz -C /usr/local/
   cd /usr/local
   ln -sv mariadb-5.5.43-linux-x86_64  mysql
3 创建用户
   groupadd -r -g 306 mysql&>/dev/null;useradd -s /sbin/nologin -r -u 306 -g 306 mysql  
4 修改mysql的所属组
   chown -R root.mysql mysql
5 给mysql复制启动脚本
  cp support-files/mysql.server  /etc/init.d/mysqld
6 给数据库准备数据存放位置 
   mkdir /mydata/data -p
   chown -R mysql.mysql /mydata/
7 必须在 /usr/local/mysql的目录下面初始化数据库
  scripts/mysql_install_db --datadir=/mydata/data --user=mysql
8 然后就可以启动mysql的数据库
9 添加mysql的PATH路径
  echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
  source /etc/profile.d/mysql.sh
10 授权用户可以远程访问本数据库
   mysql > grant all on *.* to test@"%" identified by "test"

8 安装wordpress或phpMyadmin 进行测试

你可能感兴趣的:(LAMP)