一 官网: https://www.php.net/downloads.php
https://blog.izgq.net/archives/910/
https://www.jianshu.com/p/1ff101482b31
官网文档; https://www.php.net/manual/zh/install.unix.apache2.php
安装依赖
sudo apt-get install libxml2-dev sudo apt-get install libcurl4-gnutls-dev sudo apt-get install libbz2-dev sudo apt-get install libjpeg-dev sudo apt-get install libpng-dev sudo apt-get install libxpm-dev sudo apt-get install libfreetype6-dev sudo apt-get install libt1-dev sudo apt-get install libmcrypt-dev sudo apt-get install libmysql++-dev sudo apt-get install libxslt1-dev
sudo apt-get install libssl-dev
sudo apt-get install libgmp-dev
sudo apt install -y libedit-dev libreadline-dev
apt-get install libzip-dev
下载解压
https://www.php.net/distributions/php-7.2.20.tar.gz tar -xzvf php-7.2.20.tar.gz mv php-7.2.20 php
编译前准备
sudo apt install build-essential bison re2c pkg-config -y
sudo apt install build-essential bison re2c pkg-config libxml2-dev libbz2-dev libssl-dev libcurl4-openssl-dev libjpeg-dev libpng12-dev libfreetype6-dev libgmp-dev libreadline6-dev libxslt1-dev libzip-dev -y
二.配置和创建PHP
./configure --prefix=/usr/local/php
--with-apxs2=/usr/local/apache2/bin/apxs
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/php/etc --enable-fpm
执行该语句时可能会出现如下提示:
error: xml2-config not found. Please check your libxml2 installation
此时执行make命令会出现以下错误:
“make: *** No targets specified and no makefile found. Stop.”
这是因为缺少xml2-config文件造成的。解决方案:
sudo apt-get install libxml2 sudo apt-get install libxml2-dev
之后在此执行以下语句完成编译安装
./configure
-with-apxs2=/usr/local/apache2/bin/apxs --prefix=/usr/local/php --with-config-file-path=/etc --enable-fpm --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --with-libxml-dir --with-xmlrpc --with-mhash --with-pcre-regex --with-sqlite3 --with-zlib --with-libzip=../libzip-1.3.2 --enable-bcmath --with-iconv --with-bz2 --with-openssl --enable-calendar --with-curl --with-cdb --enable-dom --enable-exif --enable-fileinfo --enable-filter --with-pcre-dir --enable-ftp --with-gd --with-openssl-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash --enable-json --enable-mbstring --enable-mbregex --enable-mbregex-backtrack --with-libmbfl --with-onig --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pdo-sqlite --with-readline --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-libxml-dir --with-xsl --enable-zip --enable-mysqlnd-compression-support --with-pear --enable-opcache
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs #指定Apache2−−with−apxs2=/usr/local/apache2/bin/apxs——指定Apache2
make
make install
make test
、安装时报错内存 不足recipe for target 'ext/fileinfo/libmagic/apprentice.lo' failed,把服务器应用全关了 重新安装ok
4.将php.ini拷贝到/usr/local/lib/
cp php.ini-development /usr/local/lib/php.ini
查看编译时参数
php -i|grep config
查看php.ini 默认加载路径
php -i|grep php.ini
查看php配置文件有没有加载
php --ini
5.编辑httpd.conf,加载PHP模块
LoadModule php7_module modules/libphp7.so #好像程序自己加进去了
7.重启Apache2
/usr/local/apache2/bin/apachectl restart
1
8.测试PHP是否安装成功
在Apache2的指定文件目录下添加index.php文件,并输入以下内容
<?php
phpinfo();
?>
、
然后在浏览器输入url——localhost/index.php,如果查看到以下结果,则说明安装成功,若没有,可以考虑重新编译安装。