Yocto 支持 PHP 的 Apache2

Apache2 with PHP support in Yocto

我正在使用 Yocto 创建一个包含 apache2 的构建,但我很难添加 php 支持。我以前有过它 运行(阅读:去年),但从那时起,meta-openembedded 中的 meta-webserver 层发生了变化。来自 meta-webserver 中的 README 文件:

"This layer used to provide a modphp recipe that built mod_php, but this is now built as part of the php recipe in meta-oe. However, since apache2 is required to build mod_php, and apache2 recipe is in this layer and recipes in meta-oe can't depend on it, mod_php is not built by default. If you do wish to use mod_php, you need to add "apache2" to the PACKAGECONFIG value for the php recipe in order to enable it."

我在我自己的图层 php 中添加了以下行:

PACKAGECONFIG_append = " apache2"

但是我在编译 mod_php 时找不到似乎是 apache 的包含文件时出现编译错误(我在下面只包含一个错误,我在 ap_config.h 中得到类似的错误嗯):

In file included from /home/martin/Yocto/poky/rpi/tmp/work/x86_64-linux/php-native/5.6.12-r0/php-5.6.12/sapi/apache2handler/mod_php5.c:26:0: | /home/martin/Yocto/poky/rpi/tmp/work/x86_64-linux/php-native/5.6.12-r0/php-5.6.12/sapi/apache2handler/php_apache.h:24:19: fatal error: httpd.h: No such file or directory | compilation terminated.

最近有没有人成功地编译了带有 php 支持的 apache2,并且可以就如何做提供一些帮助?谢谢!

在 Armin Kuster 的宝贵帮助下,我设法解决了我的问题。 Armin 注意到 PACKAGECONFIG_append = " apache2" 覆盖了现有的 PACKAGECONFIG 并仅设置了 "apache2"。根据他的建议,我更改了我的 bbappend 文件以包含以下内容:

DEPENDS = "apache2"
RDEPENDS_${PN} = "apache2"
PACKAGECONFIG = "sqlite3 apache2 ${@bb.utils.contains('DISTRO_FEATURES', 'pam', 'pam', '', d)}”

我不知道 DEPENDS 和 RDEPENDS 是否还需要,但它们似乎没有什么坏处。

然后我意识到只是将 'php' 添加到我的 layer.conf 并不能像过去那样构建二进制文件。我必须明确指定 php-cli 和 php-modphp。我的 layer.conf 现在包括这个:

IMAGE_INSTALL_append = " apache2 php php-cli php-modphp"

由此 PHP 配方构建并包括 php 二进制文件和 php apache module。但是,文件 /etc/apache/modules.d/70_mod_php5.conf 不会加载 PHP module,因为 PHP5 环境变量未定义(请参阅下面的默认文件).我不知道在哪里指定环境变量,所以我最终在我自己的层中覆盖了这个文件,在我的版本中我只是删除了 IfDefine。

# vim: ft=apache sw=4 ts=4
<IfDefine PHP5>
        # Load the module first
        <IfModule !sapi_apache2.c>
                LoadModule php5_module    /usr/lib/apache2/modules/libphp5.so
        </IfModule>

        # Set it to handle the files
        AddHandler php5-script .php .phtml .php3 .php4 .php5
        AddType application/x-httpd-php-source .phps
        DirectoryIndex index.html index.html.var index.php index.phtml
</IfDefine>

希望对遇到同样问题的其他人有所帮助。

要在 yocto 中添加 PHP 对 apache 的支持,请在 bitbake 配方文件中进行以下更改。

下面是 php.inc 文件的差异输出

10c10
<            openssl libmcrypt"
---
>            openssl libmcrypt apache2-native apache2"
52c54,55
< EXTRA_OECONF = "--enable-mbstring \
---
> EXTRA_OECONF = "--with-apxs2=${STAGING_BINDIR_CROSS}/apxs \
>               --enable-mbstring \
129c132
<     if ${@bb.utils.contains('PACKAGECONFIG', 'apache2', 'true', 'false', d)}; then
---
>     if ${@bb.utils.contains('PACKAGECONFIG', 'apache2', 'true', 'true', d)}; then
200c203
< PACKAGES = "${PN}-dbg ${PN}-cli ${PN}-cgi ${PN}-fpm ${PN}-fpm-apache2 ${PN}-pear ${PN}-phar ${MODPHP_PACKAGE} ${PN}-dev ${PN}-staticdev ${PN}-doc ${PN}"
---
> PACKAGES = "${PN}-dbg ${PN}-cli ${PN}-cgi ${PN}-fpm ${PN}-fpm-apache2 ${PN}-pear ${PN}-phar ${MODPHP_PACKAGE} ${PN}-dev ${PN}-staticdev ${PN}-doc ${PN} ${PN}-modphp"
236a240
> #FILES_${PN} += "${sysconfdir}"

希望,这有助于解决问题:)