1、apache配置
- VirtualHost中添加php模块配置
<FilesMatch "\.php$"> SetHandler application/x-httpd-php </FilesMatch>
- apxs2找不到
sudo apt-get install apache2-dev
2、php安装
PS:
php7.0- *软件包已从ppa:ondrej / php repo的Ubuntu 15.04版本中删除,但在15.10版本中可用.
2.1 php源码安装
- 安装配置
./configure --prefix=/usr/local/php-7.2 --with-apxs2=/usr/bin/apxs2 --with-config-file-path=/usr/local/php-7.2/etc --enable-maintainer-zts --enable-sockets --enable-fpm
- 编译命令
make && makeinstall
2.2 扩展安装
- 常见问题
-
进入etx目录下可以看到扩展的源码目录,选择对应的源码目录进入;
-
使用phpize命令生成configure执行文件,如果找不到phpize文件可以去php的安装目录的bin目录下找到,将其软连接到/usr/bin目录下就可以直接使用了
-
添加扩展模块时有时会遇到
error: unknown type name ‘zend_string’ zend_string *hash_key
, 是因为在编译php7的扩展时,用到的是php5的环境,但是php5 里面没有zend_string类型,所以应该升级php5的环境到php7,或者在配置时指定php编译环境的配置。
./configure --with-php-config=/usr/local/php-7.2/bin/php-config
-
编译插件时常见的NotFound错误解决方案:
configure: error: libxml2 not found. Please check your libxml2 installation. apt install libxml2-dev configure: error: jpeglib.h not found. apt install libjpeg-dev configure: error: png.h not found. apt install libpng-dev configure: error: freetype-config not found apt install libfreetype6-dev configure: error: mcrypt.h not found. Please reinstall libmcrypt apt install libmcrypt-dev configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution apt install libxslt1-dev
-
- pdo_mysql安装
查找mysql安装路径:find / -name mysql.h 生成makefile文件:./configure --with-php-config=/usr/local/php-7.2/bin/php-config --with-pdo-mysql=/usr
- mysqli安装
查找mysql_config路径:find / -name mysql_config 生成makefile文件:./configure --with-php-config=/usr/local/php-7.2/bin/php-config --with-mysqli=/usr/bin/mysql_config
- bz2安装
生成makefile文件时报错:configure: error: Please reinstall the BZip2 distribution 安装bzip2和libbz2-dev apt install -y bzip2* apt-get install libbz2-dev 生成makefile文件:./configure --with-php-config=/usr/local/php-7.2/bin/php-config --with-bz2
- curl安装
生成makefile文件时报错:configure: error: Please reinstall the libcurl distribution 安装curl和libcurl4-gnutls-dev apt-get install curl apt-get install libcurl4-gnutls-dev 生成makefile文件:./configure --with-php-config=/usr/local/php-7.2/bin/php-config --with-curl=/usr/local/lib/curl
- gd2安装
预安装:- 安装libjpeg jpeg-9b
wget http://www.ijg.org/files/jpegsrc.v9d.tar.gz ./configure --prefix=/usr/local/libjpeg --enable-shared
- 安装freetype2
wget http://download.savannah.gnu.org/releases/freetype/freetype-2.7.tar.gz ./configure --prefix=/usr/local/freetype2
- 安装libpng
wget https://nchc.dl.sourceforge.net/project/libpng/libpng16/1.6.37/libpng-1.6.37.tar.xz ./configure --prefix=/usr/local/libpng
- 安装zlib
wget http://www.zlib.net/zlib-1.2.11.tar.gz ./configure --prefix=/usr/local/zlib
生成makefile文件:./configure --with-php-config=/usr/local/php-7.2/bin/php-config --with-jpeg-dir=/user/local/libjpeg --with-png-dir=/user/local/libpng --with-freetype-dir=/user/local/freetype2 --with-zlib-dir=/user/local/zlib
- 安装libjpeg jpeg-9b
- intl安装
生成makefile文件:./configure --with-php-config=/usr/local/php-7.2/bin/php-config --enable-intl
- exif安装
生成makefile文件: ./configure --with-php-config=/usr/local/php-7.2/bin/php-config
- mbstring安装
生成makefile文件: ./configure --with-php-config=/usr/local/php-7.2/bin/php-config
- soap安装
生成makefile文件:./configure --with-php-config=/usr/local/php-7.2/bin/php-config --enable-soap
- xsl安装
生成makefile文件: ./configure --with-php-config=/usr/local/php-7.2/bin/php-config