树莓派编译安装PHP7.3

首先安装依赖

apt install -y libxml2 libxml2-dev libjpeg-dev libcurl4-openssl-dev libreadline-dev libzip-dev libfreetype6-dev

下载源码并安装

wget https://www.php.net/distributions/php-7.3.15.tar.gz
tar zxf php-7.3.15.tar.gz
cd php-7.3.15
./configure \
--prefix=/usr/local/php \
--with-apxs2=/usr/local/apache/bin/apxs \
--with-curl --with-gettext --with-iconv-dir --with-gd --with-jpeg-dir --with-openssl --with-openssl-dir=/usr/local/openssl --with-pear --with-readline --with-xmlrpc --with-zlib \
--with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd \
--enable-bcmath --enable-calendar --enable-exif --enable-fpm --enable-ftp --enable-intl --enable-mbstring --enable-mysqlnd \
--enable-soap --enable-sockets --enable-zip
make -j4 && make install

配置文件

cp php.ini-production /usr/local/php/lib/php.ini
sed -i 's/post_max_size = 8M/post_max_size = 50M/g' /usr/local/php/lib/php.ini
sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 50M/g' /usr/local/php/lib/php.ini
sed -i 's/;date.timezone =/date.timezone = PRC/g' /usr/local/php/lib/php.ini
sed -i 's/expose_php = On/expose_php = Off/g' /usr/local/php/lib/php.ini

配置 Apache 支持 PHP

echo "AddType application/x-httpd-php .php" >> /usr/local/apache/conf/httpd.conf

增加软连接

ln -s /usr/local/php/lib/php.ini /etc/php.ini
ln -s /usr/local/php/bin/php /usr/local/bin/
ln -s /usr/local/php/bin/phpize /usr/local/bin/
ln -s /usr/local/php/bin/pecl /usr/local/bin/
ln -s /usr/local/php/bin/php-config /usr/local/bin/