从 ubuntu 16.04 更新到 18.04 后,我注意到 php-curl 不起作用,但 php 工作正常。我以为问题是apache2仍在使用php7.0而不是php7.2,所以我跑了
sudo a2dismod php7.0
sudo a2enmod php7.2
sudo systemctl restart apache2
Run Code Online (Sandbox Code Playgroud)
现在 php 不起作用,但呈现 html 代码...
这将返回一个空白页:
<?php phpinfo(); ?>
Run Code Online (Sandbox Code Playgroud)
我使用在 php:phpinfo -manual 页面中找到的版本再次检查了我的 phpinfo() 实现,在下面重复,仍然不适用于 apache,但是当我在 bash 中运行以下时它确实有效
my-machine:~$ php public_html/info.php
Run Code Online (Sandbox Code Playgroud)
这是http://php.net/manual/en/function.phpinfo.php的编辑版本
<?php
phpinfo();
// Show just the module information.
// phpinfo(8) yields identical results.
phpinfo(INFO_MODULES);
?>
Run Code Online (Sandbox Code Playgroud)
我也试过
sudo update-alternatives --set php /usr/bin/php7.2
Run Code Online (Sandbox Code Playgroud)
我已经按照一页中的指示编辑了 /etc/php/7.2/apache2/php.ini 如下:
short_open_tag = On
Run Code Online (Sandbox Code Playgroud)
这是有关我的设置的一些信息。
php版本
php -v
PHP 7.2.7-0ubuntu0.18.04.2 (cli) (built: Jul 4 2018 16:55:24) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.7-0ubuntu0.18.04.2, Copyright (c) 1999-2018, by Zend Technologies
Run Code Online (Sandbox Code Playgroud)
查询
a2query -m php7.2
php7.2 (enabled by site administrator)
Run Code Online (Sandbox Code Playgroud)
apache2 模块列表,请注意:“AH01574:模块 php7_module 已加载,正在跳过”是因为我还运行了 =sudo a2enmod php7.0= 希望回到我以为的状态...我确实禁用了 php7.2并启用 php7.0 并使用 sudo systemctl restart apache2 重新启动 apache2,但未呈现 php。
apache2ctl -M
[Sun Sep 02 18:03:43.185183 2018] [so:warn] [pid 4166] AH01574: module php7_module is already loaded, skipping
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
Loaded Modules:
core_module (static)
so_module (static)
watchdog_module (static)
http_module (static)
log_config_module (static)
logio_module (static)
version_module (static)
unixd_module (static)
access_compat_module (shared)
alias_module (shared)
auth_basic_module (shared)
authn_core_module (shared)
authn_file_module (shared)
authz_core_module (shared)
authz_host_module (shared)
authz_user_module (shared)
autoindex_module (shared)
deflate_module (shared)
dir_module (shared)
dnssd_module (shared)
env_module (shared)
filter_module (shared)
mime_module (shared)
mpm_prefork_module (shared)
negotiation_module (shared)
php7_module (shared)
reqtimeout_module (shared)
setenvif_module (shared)
status_module (shared)
userdir_module (shared)
Run Code Online (Sandbox Code Playgroud)
已安装的 php 包列表
sudo apt list --installed | grep -i php
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
libapache2-mod-php/bionic,bionic,now 1:7.2+60ubuntu1 all [installed]
libapache2-mod-php7.0/now 7.0.30-0ubuntu0.16.04.1 amd64 [installed,local]
libapache2-mod-php7.2/bionic-updates,bionic-security,now 7.2.7-0ubuntu0.18.04.2 amd64 [installed]
libphp-phpmailer/bionic,bionic,now 5.2.14+dfsg-2.3 all [installed,automatic]
php/bionic,bionic,now 1:7.2+60ubuntu1 all [installed]
php-bz2/bionic,bionic,now 1:7.2+60ubuntu1 all [installed,automatic]
php-cli/bionic,bionic,now 1:7.2+60ubuntu1 all [installed,automatic]
php-common/bionic,bionic,now 1:60ubuntu1 all [installed]
php-curl/bionic,bionic,now 1:7.2+60ubuntu1 all [installed]
php-db/bionic,bionic,now 1.9.2-2ubuntu1 all [installed]
php-gd/bionic,bionic,now 1:7.2+60ubuntu1 all [installed,automatic]
php-getid3/bionic,bionic,now 1.9.15+dfsg-1 all [installed,automatic]
php-gettext/bionic,bionic,now 1.0.12-0.1 all [installed,automatic]
php-mbstring/bionic,bionic,now 1:7.2+60ubuntu1 all [installed,automatic]
php-mcrypt/now 1:7.0+35ubuntu6.1 all [installed,local]
php-mysql/bionic,bionic,now 1:7.2+60ubuntu1 all [installed]
php-pear/bionic,bionic,now 1:1.10.5+submodules+notgz-1ubuntu1 all [installed]
php-php-gettext/bionic,bionic,now 1.0.12-0.1 all [installed,automatic]
php-phpseclib/bionic,bionic,now 2.0.9-1 all [installed,automatic]
php-tcpdf/bionic,bionic,now 6.2.13+dfsg-1ubuntu1 all [installed,automatic]
php-tidy/bionic,bionic,now 1:7.2+60ubuntu1 all [installed]
php-xml/bionic,bionic,now 1:7.2+60ubuntu1 all [installed,automatic]
php-zip/bionic,bionic,now 1:7.2+60ubuntu1 all [installed,automatic]
php5-common/now 5.5.9+dfsg-1ubuntu4.19 amd64 [installed,local]
php5-json/now 1.3.2-2build1 amd64 [installed,local]
php5-mysql/now 5.5.9+dfsg-1ubuntu4.19 amd64 [installed,local]
php7.0/now 7.0.30-0ubuntu0.16.04.1 all [installed,local]
php7.0-cli/now 7.0.30-0ubuntu0.16.04.1 amd64 [installed,local]
php7.0-common/now 7.0.30-0ubuntu0.16.04.1 amd64 [installed,local]
php7.0-gd/now 7.0.30-0ubuntu0.16.04.1 amd64 [installed,local]
php7.0-json/now 7.0.30-0ubuntu0.16.04.1 amd64 [installed,local]
php7.0-mbstring/now 7.0.30-0ubuntu0.16.04.1 amd64 [installed,local]
php7.0-mcrypt/now 7.0.30-0ubuntu0.16.04.1 amd64 [installed,local]
php7.0-mysql/now 7.0.30-0ubuntu0.16.04.1 amd64 [installed,local]
php7.0-opcache/now 7.0.30-0ubuntu0.16.04.1 amd64 [installed,local]
php7.0-readline/now 7.0.30-0ubuntu0.16.04.1 amd64 [installed,local]
php7.0-xml/now 7.0.30-0ubuntu0.16.04.1 amd64 [installed,local]
php7.2/bionic-updates,bionic-updates,bionic-security,bionic-security,now 7.2.7-0ubuntu0.18.04.2 all [installed,automatic]
php7.2-bz2/bionic-updates,bionic-security,now 7.2.7-0ubuntu0.18.04.2 amd64 [installed,automatic]
php7.2-cli/bionic-updates,bionic-security,now 7.2.7-0ubuntu0.18.04.2 amd64 [installed,automatic]
php7.2-common/bionic-updates,bionic-security,now 7.2.7-0ubuntu0.18.04.2 amd64 [installed,automatic]
php7.2-curl/bionic-updates,bionic-security,now 7.2.7-0ubuntu0.18.04.2 amd64 [installed]
php7.2-gd/bionic-updates,bionic-security,now 7.2.7-0ubuntu0.18.04.2 amd64 [installed,automatic]
php7.2-json/bionic-updates,bionic-security,now 7.2.7-0ubuntu0.18.04.2 amd64 [installed,automatic]
php7.2-mbstring/bionic-updates,bionic-security,now 7.2.7-0ubuntu0.18.04.2 amd64 [installed,automatic]
php7.2-mysql/bionic-updates,bionic-security,now 7.2.7-0ubuntu0.18.04.2 amd64 [installed,automatic]
php7.2-opcache/bionic-updates,bionic-security,now 7.2.7-0ubuntu0.18.04.2 amd64 [installed,automatic]
php7.2-readline/bionic-updates,bionic-security,now 7.2.7-0ubuntu0.18.04.2 amd64 [installed,automatic]
php7.2-tidy/bionic-updates,bionic-security,now 7.2.7-0ubuntu0.18.04.2 amd64 [installed,automatic]
php7.2-xml/bionic-updates,bionic-security,now 7.2.7-0ubuntu0.18.04.2 amd64 [installed,automatic]
php7.2-zip/bionic-updates,bionic-security,now 7.2.7-0ubuntu0.18.04.2 amd64 [installed,automatic]
phpmyadmin/bionic,bionic,now 4:4.6.6-5 all [installed]
Run Code Online (Sandbox Code Playgroud)
apt 策略 libapache2-mod-php7.2
sudo apt policy libapache2-mod-php7.2
libapache2-mod-php7.2:
Installed: 7.2.7-0ubuntu0.18.04.2
Candidate: 7.2.7-0ubuntu0.18.04.2
Version table:
*** 7.2.7-0ubuntu0.18.04.2 500
500 http://us.archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages
500 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages
100 /var/lib/dpkg/status
7.2.3-1ubuntu1 500
500 http://us.archive.ubuntu.com/ubuntu bionic/main amd64 Packages
Run Code Online (Sandbox Code Playgroud)
ls -l /etc/apache2/mods-enabled/php*
ls -l /etc/apache2/mods-enabled/php*
lrwxrwxrwx 1 root root 29 Sep 2 18:48 /etc/apache2/mods-enabled/php7.2.conf -> ../mods-available/php7.2.conf
lrwxrwxrwx 1 root root 29 Sep 2 18:48 /etc/apache2/mods-enabled/php7.2.load -> ../mods-available/php7.2.load
Run Code Online (Sandbox Code Playgroud)
apache2 日志示例
[Mon Sep 03 00:06:52.805155 2018] [mpm_prefork:notice] [pid 5161] AH00163: Apache/2.4.29 (Ubuntu) configured -- resuming normal operations
[Mon Sep 03 00:06:52.805181 2018] [core:notice] [pid 5161] AH00094: Command line: '/usr/sbin/apache2'
[Sun Sep 02 13:39:30.728738 2018] [:error] [pid 4109] [client 127.0.0.1:36468] PHP Notice: Only variables should be assigned by reference in /home/go/public_html/index.php on line 115
[Sun Sep 02 13:39:30.739232 2018] [:error] [pid 4109] [client 127.0.0.1:36468] PHP Notice: Undefined variable: year in /home/go/public_html/calendar.php on line 38
[Sun Sep 02 13:39:30.739253 2018] [:error] [pid 4109] [client 127.0.0.1:36468] PHP Notice: Undefined variable: month in /home/go/public_html/calendar.php on line 40
[Sun Sep 02 13:39:30.739256 2018] [:error] [pid 4109] [client 127.0.0.1:36468] PHP Notice: Undefined variable: year in /home/go/public_html/calendar.php on line 42
[Sun Sep 02 13:39:30.739260 2018] [:error] [pid 4109] [client 127.0.0.1:36468] PHP Notice: Undefined variable: year in /home/go/public_html/calendar.php on line 46
[Sun Sep 02 13:39:30.739278 2018] [:error] [pid 4109] [client 127.0.0.1:36468] PHP Notice: Undefined variable: month in /home/go/public_html/calendar.php on line 52
[Sun Sep 02 13:39:30.739281 2018] [:error] [pid 4109] [client 127.0.0.1:36468] PHP Notice: Undefined variable: month in /home/go/public_html/calendar.php on line 56
[Sun Sep 02 13:39:35.889200 2018] [:error] [pid 4111] [client 127.0.0.1:36478] PHP Notice: Only variables should be assigned by reference in /home/go/public_html/show-reading-list.php on line 7, referer: http://localhost/~go/
Run Code Online (Sandbox Code Playgroud)
日志中提到的变量在这些 php 文件中......我在更新之前生成的先前日志中看到了相同的错误。
php 和 php-curl 现在可以工作了。
让我找到答案的是注意到 /etc/apache2/mods-available/ 中 php7.0.conf 和 php7.2.conf 之间的差异,这只会影响 php 在 userdir 中的执行方式。然后我检查了 php 是否在服务器上运行,发现它确实运行。
总而言之,我相信从 ubuntu 16.04 和 18.04 更新后我需要
<IfModule mod_userdir.c>部分;php 和 php-curl 现在在 userdir 中工作。
感谢所有留下评论的人。
[添加此作为答案只是为了便于格式化]
在 SSD 上安装新的 Ububtu18.04 后,我一直在努力解决这个问题。在我的用户帐户中用作 ~/public_html directory 文档根。apache 没有解析任何 PHP 代码。
最后,上面的详细问题帮助我确定在 php ~/public_html/test.php
工作时,它只是从不工作的浏览器访问 php 文件。
解决方案:允许apache2在用户目录中执行PHP。(就像上面的答案一样)。查找并编辑 php7.2.conf 文件。就我而言,它位于/etc/apache2/mods-enabled/php7.2.conf. 这些行需要被注释掉:
# Running PHP scripts in user directories is disabled by default
#
# To re-enable PHP in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
#<IfModule mod_userdir.c>
# <Directory /home/*/public_html>
# php_admin_flag engine Off
# </Directory>
#</IfModule>
Run Code Online (Sandbox Code Playgroud)
重新启动apache2,现在可以了。您可能需要从浏览器缓存中清除该页面。
感谢@tempestcat 希望这能帮助其他人将来。
| 归档时间: |
|
| 查看次数: |
19751 次 |
| 最近记录: |