![PHP 代码显示在浏览器中](https://linux22.com/image/1144847/PHP%20%E4%BB%A3%E7%A0%81%E6%98%BE%E7%A4%BA%E5%9C%A8%E6%B5%8F%E8%A7%88%E5%99%A8%E4%B8%AD.png)
我在 Ubuntu 上全新安装了 LAMP 组件。以下安装已完成
apt-get install php
apt-get install php-mysql
apt-get install mysql-server
apt-get install apache2
apt-get install libapache2-mod-php7.0
apt-get install dolibarr
apt-get install php7.0 php5.6 php5.6-mysql php-gettext php5.6-mbstring php-xdebug libapache2-mod-php5.6 libapache2-mod-php7.0
apt-get install python-software-properties pkg-config software-properties-common
当我访问时<MyIP>/dolibarr/htdocs
,显示的是 PHP 代码,但并未执行。
当我访问时<MyIP>/test.php
,我得到了下面的 PHP 代码执行和 PHP 信息显示:
<?php
phpinfo();
?>
这个 test.php 和多利巴尔放置在/var/www
Apache 根目录设置/etc/apache2/sites-enabled/000-default.conf
如下:
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www
因为我想确保没有暗示 PHP 版本,所以我尝试了本教程并在 PHP 7.0 和 PHP 5.6 之间切换。
我被困在这里了。大家有什么想法吗?
答案1
在 Ubuntu 中,默认apache
目录/var/www
不是/var/www/html
这样htdocs
的Windows
,要解决您的问题请执行以下操作:
dolibarr
通过放置来生根所有文件和文件夹在htdocs
/var/www/dolibarr
- 然后从浏览器执行
<MyIP>/dolibarr/index.php