qinling072 发表于 2018-12-12 10:44:57

LAMP(3)安装PHP5、安装PHP7

                                安装PHP5

  http://s1.运维网.com/images/20180313/1520950096648732.png

  (目前很多的企业仍然是使用PHP5,因为考虑到兼容的问题)

  1.先进入到 /usr/local/src目录(因为我把下载的包都统一放在这里)
  cd /usr/local/src
  2.下载包: wget http://cn2.php.net/distributions/php-5.6.30.tar.gz
  http://s1.运维网.com/images/20180313/1520950562579717.png
  3.解压文件压缩包:
  tar -zxvf php-5.6.30.tar.gz
  http://s1.运维网.com/images/20180313/1520950851929741.png
  

  4.安装:
  (1)cd php-5.6.30
  (2)
  ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php/etc--with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif
  

  (apxs2:apache的工具,自动的把扩展模块放到apache目录,且自动修改配置文件
  )
  首次安装PHP,会出现很多次的错误,其实是缺乏一些包:

  yum list |grep -i 模糊包名 (一般都是安装:包名+devel)
  http://s1.运维网.com/images/20180313/1520952499911401.png
  这里缺乏 openssl (yum install -y openssl-devel)
  

  http://s1.运维网.com/images/20180313/1520952870626896.png
  这里缺乏 bzip2 (yum install -y bzip2-devel)
  

  http://s1.运维网.com/images/20180313/1520953241731274.png
  这里缺乏 libjpeg (yum install -y libjpeg-devel)
  

  http://s1.运维网.com/images/20180313/1520953489315145.png
  这里缺乏 png (yum install -y libpng-devel)
  

  http://s1.运维网.com/images/20180313/1520953618894921.png
  这里缺乏 freetype (yum install -y freetype-devel)
  

  http://s1.运维网.com/images/20180313/1520953812766503.png
  这里缺乏 libmcrypt
  libmcrypt 是依赖epel-release这个扩展源的,如果机器没安装先安装 yum install -y epel-release
   再:yum install -y libmcrypt-devel)
  

  安装成功:
  http://s1.运维网.com/images/20180313/1520954192147294.png
  

  5.make 和make install (make && make install)
  http://s1.运维网.com/images/20180313/1520955006885855.png
  

  php安装完后不需启动
  

  安装后:把php的参考配置文件复制到我们定义的php配置文件路径
  
  cp php.ini-production/usr/local/php/etc/php.ini
  

  (/usr/local/php/etc,这个是在执行.configure时就定义了配置文件路径)
  使用命令:/usr/local/php/bin/php -i |less 加-i可以查看到PHP文件的信息
  http://s1.运维网.com/images/20180313/1520956451483372.png
  (php.ini-production :适应在生产环境中使用(我选用这个)
   php.ini-development:适应在开发环境中使用
   )

  查看:/usr/local/php/bin/php 加载的模块:(模块都是静态的)
  /usr/local/php/bin/php-m
   (而查看httpd的模块用-M/usr/local/apache2.4/bin/httpd-M)?
  http://s1.运维网.com/images/20180313/1520955464143526.png
  

  http://s1.运维网.com/images/20180313/1520955302935310.png
  PHP和Apache结合的核心文件:/usr/local/apache2.4/modules/libphp5.so
  modules/libphp5.so 是和加载模块相关的,而PHP就是Apache的一个模块
  

                             
                           安装php7
  http://s1.运维网.com/images/20180314/1520957121728977.png
   1.先进入到 /usr/local/src目录(因为我把下载的包都统一放在这里)

  

  2.下载PHP7包:
  
  wget http://cn2.php.net/distributions/php-7.1.6.tar.bz2
  http://s1.运维网.com/images/20180314/1520957220143059.png
  3.解压:
  tar -jxvf php-7.1.6.tar.bz2
  4.安装:
  cd php-7.1.6
  执行 .configure
  
  ./configure --prefix=/usr/local/php7 --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php7/etc--with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif
  

  5.遍历 make 和 make install

  

  

  

  

  

  安装完成后:复制配置文件到定义的路径
  
  cp php.ini-production/usr/local/php7/etc/php.ini
  

  

  查看apache2.4加载了多少个PHP
   /usr/local/apache2.4/bin/apachectl-M
  http://s1.运维网.com/images/20180314/1520958691405170.png
  

  根据自己的需求使用哪个版本的PHP(5或7,前提是两个都安装有)?
  答:修改配置文件
  vim /usr/local/apache2.4/conf/httpd.conf
  http://s1.运维网.com/images/20180314/1520958788961586.png
  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  




页: [1]
查看完整版本: LAMP(3)安装PHP5、安装PHP7