php 之 源码包编译安装
要在Linux系统上从源代码编译安装PHP,请按照以下步骤操作:
- 安装必要的依赖项:
sudo apt-get update
sudo apt-get install build-essential autoconf libtool pkg-config re2c \
libxml2-dev libssl-dev libcurl4-openssl-dev libjpeg-dev libpng-dev \
libfreetype6-dev libbz2-dev libmcrypt-dev libreadline-dev libxslt-dev \
libmysqlclient-dev sqlite3 libpq-dev
- 下载PHP源代码:
wget https://www.php.net/distributions/php-7.x.y.tar.gz
tar -xzvf php-7.x.y.tar.gz
cd php-7.x.y
将7.x.y
替换为要安装的PHP版本。
- 配置PHP:
./configure --prefix=/usr/local/php --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pear --with-pdo-mysql --with-xmlrpc --with-xsl --with-zlib --enable-bcmath --enable-fpm --enable-libxml --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable-zip
- 编译和安装PHP:
make -j$(nproc)
sudo make install
- 配置PHP-FPM(如果已启用
--enable-fpm
):
sudo cp php.ini-development /usr/local/php/lib/php.ini
sudo cp sapi/fpm/php-fpm.service /etc/init.d/php-fpm
sudo chmod +x /etc/init.d/php-fpm
sudo update-rc.d php-fpm defaults
- 启动PHP-FPM服务:
sudo service php-fpm start
- 配置Web服务器以使用PHP-FPM(以Nginx为例):
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
确保替换为适合您系统和需求的配置选项。这只是一个基本的安装示例,根据您的具体需求,可能需要额外的配置步骤。
评论已关闭