PHP 编译安装+apache开启php

PHP安装提示

直接 yum install php-cli 安装的是5.x版本,建议直接下载源码编译安装

安装:
https://www.cnblogs.com/houss/p/11296285.html

php7编译选项

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php --enable-mbstring --enable-ftp --with-gd --with-jpeg-dir=/usr --with-png-dir=/usr --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --without-pear  --disable-phar --enable-sockets --with-freetype-dir=/usr --with-zlib --with-libxml-dir=/usr --with-xmlrpc --enable-zip --enable-fpm --enable-xml --enable-sockets --with-gd --with-zlib --with-iconv --enable-zip --with-freetype-dir=/usr/lib/ --enable-soap --enable-pcntl --enable-cli --with-curl --with-apxs2

注意 --with-apxs2 选项,没有这个选项无法编译出 libphp7.so 文件,导致apache无法正常链接
使用 --with-apxs2 可能的错误:

Sorry, I cannot run apxs. Possible reasons follow:

Perl is not installed
apxs was not found. Try to pass the path using --with-apxs2=/path/to/apxs
Apache was not built using --enable-so (the apxs usage page is displayed)

解决办法:

when `httpd -l` does not list `mod_so.c`, `DSO` won't work, because it's an essential prerequisite; according to the [documentation](https://httpd.apache.org/docs/2.4/programs/apxs.html). otherwise `APXS` can be installed with the package manager:

*   `sudo yum install httpd-devel` (CentOS)
*   `sudo apt-get install apache2-dev` (Ubuntu)

this installs it as `/usr/bin/apxs` and `./configure --with-apxs` works (without passing a path). one does not even have to install `httpd` / `apache2`, in order to use it's development tools - which then can be used to configure `PHP` with `APXS`.

https://stackoverflow.com/questions/43640200/there-is-a-error-as-apxs-not-found-and-apache-is-not-built-when-i-buildconfigur

./configure ...
make install
完成后 .so 文件位置 libs/libphp7.so, 将其拷贝到对应对方备用

Apache 配置:

修改httpd.conf , 在适当问之添加 LoadModule php7_module modules/libphp7.so

php 配置文件:
/etc/httpd/conf.modules.d/10-php.conf


        AddType application/x-httpd-php .php
        AddType application/x-httpd-php-source .phps

        
                DirectoryIndex index.html index.php
        

apachectl restart 重启apache服务器,php生效

你可能感兴趣的:(PHP 编译安装+apache开启php)