下载编译PHP
安装依赖
1 | apt-get install gcc g++ libxml2-dev libssl-dev libbz2-dev libjpeg-dev libpng-dev libxpm-dev libfreetype6-dev libgmp-dev libgmp3-dev libmcrypt-dev libpspell-dev librecode-dev libcurl4-gnutls-dev libgmp-dev libgmp3-dev librecode-dev libpspell-dev libmcrypt-dev libreadline-dev libtidy-dev libxslt1-dev libmagickcore-dev bison re2c libzip-dev apache2 apache2-dev libzstd-dev |
Apache支持
source /etc/apache2/envvars 在apache.conf添加一行支持php AddType application/x-httpd-php .php
下载源码
http://php.net/downloads.php, 解压
1
2
3 wget http://php.net/distributions/php-7.3.13.tar.gz
tar zxf php-7.3.13.tar.gz
cd php-7.3.13/
配置
1 | ./configure --prefix=/usr/local/php --with-config-file-path=/etc --enable-fpm --with-fpm-user=www-data --with-fpm-group=www-data --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-soap --with-libxml-dir --with-xmlrpc --with-openssl --with-mhash --with-pcre-regex --with-sqlite3 --with-zlib --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --with-cdb --enable-dom --enable-pcntl --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-onig --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-zlib-dir --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 --with-apxs2=/usr/bin/apxs --enable-maintainer-zts --enable-intl --with-libzip |
编译常见问题
virtual memory exhausted: Cannot allocate memory Makefile:993: recipe for target ‘ext/fileinfo/libmagic/apprentice.lo’ failed make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 增加swap
缺少icu-config wget http://download.icu-project.org/files/icu4c/64.2/icu4c-64_2-src.tgz tar zxf icu4c-64_2-src.tgz cd icu/source ./configure make && make install
configure: error: Cannot find OpenSSL’s libraries 安装libssl-dev find / -name libssl.so ln -s /usr/lib/x86_64-linux-gnu/libssl.so /usr/lib
编译警告:
Config variable ${APACHE_RUN_DIR} is not defined source /etc/apache2/envvars
编译警告:
apache2:DefaultRuntimeDir must be a valid directory, absolute or relative to ServerR
1 | source /etc/apache2/envvars |
编译警告:
configure: error: Please reinstall the libcurl distribution - easy.h should be in /include/curl/
1 | apt install libcurl4-gnutls-dev |
配置没问题后编译安装
1 | make |
根据提示运行
1 | /root/php-7.3.13/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin |
添加到环境变量
1 | vi /etc/profile |
1 | #ln -s /usr/local/php/bin/php /usr/local/bin/php |
配置文件和服务
1 | cp php.ini-production /etc/php.ini |
php相关模块安装
7.2后的版本自带phar,不需要再另外安装
安装phar
wget http://pear.php.net/go-pear.phar php -d detect_unicode=0 go-pear.phar ln -s /usr/local/php/bin/pear /usr/local/bin/pear ln -s /usr/local/php/bin/pecl /usr/local/bin/pecl 更新协议
1 | pecl channel-update pecl.php.net |
使用:
1 | pecl install XXX |
php 安装 imagick模块(nextcloud程序需要)
1 | wget ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick.tar.gz |
其他模块
pecl install igbinary pecl install lzf pecl install redis
redis-server
apt install redis-server redis警告
WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128. echo “net.core.somaxconn= 4096” >> /etc/sysctl.conf sysctl -p
mysql数据库相关支持
在php.ini修改 mysqli.default_socket = /var/run/mysqld/mysqld.sock pdo_mysql.default_socket=/var/run/mysqld/mysqld.sock
php配置
php.ini
一般需要扩展
1
2
3
4
5 extension=imagick.so
zend_extension=opcache.so
extension=redis.so
extension=igbinary.so
extension=lzf.so
OPcache 支持
1 | opcache.enable=1 |
设置getenv(“PATH”)函数
/usr/local/php/etc/php-fpm.d/www.conf
1 | env[HOSTNAME] = $HOSTNAME |
其他
nextcloud 文件操作显示错位 设置语言为中文