Centos7源码安装PHP

PHP安装

      安装依赖  libxml2-devel (后期安装时,如果不报错也可以不用安装)

    源码安装步骤:

        1. 利用wget下载      wget -c http://php.net/distributions/php-7.2.4.tar.gz

        2. 解压     tar -zxvf php-7.2.4.tar.gz

        3. 安装编译(./configure  --prefix=/安装目录 -参数)

            ./configure  --prefix=/usr/local/php  --with-config-file-path=/usr/local/php/etc --with-apxs2=/usr/local/apache2/bin/apxs

        4. make&&make install

    apache php 整合

         编辑 /usr/local/apache2/conf/httpd.conf文件

         搜索有没有下面这一行:
                LoadModule php7_module    modules/libphp7.so
         如果没有 请手动添加 否则 会出现出现无法加载php文件。

         找到
                AddType application/x-compress .Z
                AddType application/x-gzip .gz .tgz
         在后面添加
                AddType application/x-httpd-php .php
                AddType application/x-httpd-php-source .php7

        找到在里边添加index.php
                
                         DirectoryIndex index.html index.php
                

       之后在/usr/local/apache2/htdocs目录下建立  index.php测试即可。

    

       测试即可,在本机输入 ip/index.php

  脚本化实现

        
#!/bin/bash
#describe: install php

 cat << EOF  
 +============+
 | 1 php-5.4  |
 | 2 php-5.5  |
 | 3 php-5.6  |
 | 4 php-7.0  |
 +============+ 
EOF  

 echo "please input your choose: "

 read -p "version[1-4]:" version 


 function install_php(){
 	if [ ! -d "/tmp/soft" ]; then
	mkdir -p /tmp/soft
	fi

	cd /tmp/soft/

	#install software dependency packages for php 
	yum install libxml2-devel

	#install different kinds of php software
	case $version in
  	1)
		wget -c http://php.net/distributions/php-5.6.31.tar.gz
		tar -zxvf php-5.6.31.tar.gz
		cd php-5.6.31
		echo "install php-5.6"
		;;
	2)	
		wget -c http://php.net/distributions/php-7.2.4.tar.gz
		tar -zxvf php-7.0.29.tar.gz
		cd php-7.0.29
		echo "install php-7.0"
		;;
	3)
		wget -c http://php.net/distributions/php-7.2.4.tar.gz
		tar -zxvf php-7.1.16.tar.gz
		cd php-7.1.16
		echo "install php-7.1"		
		;;
	4)
		wget -c http://php.net/distributions/php-7.2.4.tar.gz
		tar -zxvf php-7.2.4.tar.gz
		cd php-7.2.4
		echo "install php-7.2"
		;;
	*)	
		echo "error please input [1-4]!"
		;;
	esac
	#compile configuration file
	./configure  --prefix=/usr/local/php  --with-config-file-path=/usr/local/php/etc --with-apxs2=/usr/local/apache2/bin/apxs --with-pdo-mysql=/usr/local/mysql
	if [ $? -ne 0 ]; then
		echo "configure failed,please check it out!"
		exit -1
	fi
	make -j4
	if [ $? -ne 0 ]; then
		echo "make failed,please check it out!"
		exit -1
	fi
	#install software  -j4:open 4 processes
	make -j4 install
	sleep 1 
	echo "Install PHP Successful!"

}

install_php

 

你可能感兴趣的:(centos7)