EulerOS手动安装编译php7.2, 并关联Apache
在 openEuler 上手动安装编译 PHP 7.2 并附加 bcmath、curl、gd、mysql(通常使用 pdo_mysql 或 mysqli)、mbstring、xml、zip 和 imagick 扩展,你需要按照以下步骤操作:
1. 安装依赖
首先,安装编译 PHP 和这些扩展所需的依赖库
1 |
yum groupinstall "Development Tools" |
1 2 3 4 5 6 |
yum install gcc gcc-c++ make autoconf bison re2c \ libxml2-devel openssl-devel bzip2-devel libcurl-devel \ libzip-devel freetype-devel libpng-devel libjpeg-devel \ libXpm-devel gmp-devel mariadb-devel aspell-devel \ recode-devel autoconf213 libicu-devel libicu-devel \ readline-devel libxslt-devel |
对于 imagick 扩展,你还需要安装 ImageMagick 开发库:
1 |
yum install ImageMagick-devel |
2. 下载 PHP 7.2 源代码
1 2 3 4 |
cd /usr/local/src wget https://www.php.net/distributions/php-7.2.34.tar.gz tar -zxvf php-7.2.34.tar.gz cd php-7.2.34 |
3. 编译安装 PHP 7.2 时启用 apache2handler
如果你在编译 PHP 时没有启用 apache2handler(这是 PHP 与 Apache 的模块接口),你需要重新编译 PHP。启用该模块的配置选项如下(如果这个目录下已经编译过了, 需要执行 make clean ):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
./configure --prefix=/usr/local/php \ --with-apxs2=/usr/bin/apxs \ --with-freetype-dir=/usr/include/freetype2 \ --with-mysqli --with-curl --with-openssl \ --with-zlib --enable-bcmath --enable-calendar \ --enable-sockets --enable-sysvsem --enable-sysvshm \ --enable-shmop --enable-intl --enable-mbstring \ --enable-fpm --enable-soap --enable-pdo \ --with-bz2 --with-gd --enable-pdo_mysql \ --with-iconv --with-gettext --with-imagick \ --with-mcrypt --with-pdo_mysql --with-openssl \ --with-sockets --with-xmlrpc --with-mysqli \ --with-pdo --with-xsl --enable-sysvsem \ --enable-pdo --with-mysqli --enable-pdo \ --with-readline --enable-sysvsem --with-pdo-mysql \ --with-mysqli --with-openssl --enable-soap \ --enable-bcmath --with-gettext --with-bz2 \ --with-zlib --enable-shmop --enable-sockets \ --enable-mbstring --with-curl --with-gd \ --enable-intl --enable-sysvsem --enable-pdo \ --enable-mbstring --with-iconv --with-imagick \ --with-pdo-mysql --with-bz2 --with-mysqli \ --with-xsl --with-openssl --enable-fpm \ --enable-zip --with-zip |
apxs 工具是 Apache 服务器的扩展工具, 可以 通过 which apxs 查看安装路径,用于编译和安装 Apache 模块。
重新编译并安装 PHP:
1 2 |
make -j"$(nproc)" make install |
4. 配置 PHP
复制 PHP 配置文件模板,并根据需要进行修改:
1 |
cp php.ini-development /usr/local/php/etc/php.ini |
5. 配置 Apache 加载 PHP 模块
编译和安装 PHP 后,你需要配置 Apache 来加载 PHP 模块。打开或创建 Apache 的配置文件(通常位于 /etc/httpd/conf/httpd.conf),并添加或修改以下内容:
1 2 3 4 5 6 7 |
# Load PHP module LoadModule php7_module modules/libphp7.so # Add handler for PHP files <IfModule php7_module> DirectoryIndex index.php index.html AddType application/x-httpd-php .php </IfModule> |
确保 libphp7.so 文件的路径正确。这通常是在 PHP 安装目录下的 lib 目录中。
配置完成之后重启Apache
1 |
systemctl restart httpd |