简体   繁体   English

在 Ubuntu 上使用 Apache2 和 PHP7 测试 PHP

[英]Testing PHP on Ubuntu with Apache2 and PHP7

I have installed Apache2 and PHP 7 with (sudo apt-get install php7.0 php7.0-mcrypt) on my machine.我已经在我的机器上安装了Apache2PHP 7 (sudo apt-get install php7.0 php7.0-mcrypt) When I hit php -v in terminal, it return:当我在终端中点击php -v时,它返回:

PHP 7.0.4-7ubuntu2.1 (cli) ( NTS ) Copyright (c) 1997-2016 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies PHP 7.0.4-7ubuntu2.1 (cli) ( NTS ) 版权所有 (c) 1997-2016 The PHP Group Zend Engine v3.0.0,版权所有 (c) 1998-2016 Zend Technologies with Zend OPcache v7.0.6-dev,版权所有 ( c) 1999-2016,由 Zend Technologies

So then I created one PHP file at var/www/html/e.php with the below content:然后我在var/www/html/e.php创建了一个PHP文件,内容如下:

  <!DOCTYPE html>
<html>
<body>

<h1>My first PHP page</h1>

<?php
echo "Hello World!";
?>

</body>
</html>

When I open the browser ( http://localhost/e.php ), it does not show the php variable, just works the html tag.当我打开浏览器( http://localhost/e.php )时,它不显示 php 变量,只显示 html 标签。 What am I missing?我错过了什么? The Ubuntu "It Works" page of Apache works. Apache 的 Ubuntu“It Works”页面有效。

Thanks in advance.提前致谢。

you have to install apache+php module.你必须安装 apache+php 模块。

find the below command to install all php module with apache找到以下命令以使用 apache 安装所有 php 模块

apt-get install -y php7.0 libapache2-mod-php7.0 php7.0-curl php7.0-gmp php7.0-mbstring php7.0-phpdbg php7.0-sqlite3 php7.0-zip php7.0-bcmath php7.0-dba php7.0-imap php7.0-mcrypt php7.0-pspell php7.0-sybase php7.0-bz2 php7.0-dev php7.0-interbase php7.0-mysql php7.0-readline php7.0-tidy php7.0-cgi php7.0-enchant php7.0-intl php7.0-odbc php7.0-recode php7.0-xml php7.0-cli php7.0-fpm php7.0-json php7.0-opcache php7.0-snmp php7.0-xmlrpc php7.0-common php7.0-gd php7.0-ldap php7.0-pgsql php7.0-soap php7.0-xsl php7.0-mongo

then run the next command然后运行下一个命令

sudo update-alternatives --set php /usr/bin/php7.0

then assigen the mode of php handler然后 assigen php 处理程序的模式

a2enmod php7.0

restart the apache webserver重新启动 apache 网络服务器

service apache2 restart

then try to open into browser .然后尝试打开浏览器。 http://localhost/e.php) http://localhost/e.php)

我之前在 ubuntu 中遇到过同样的问题,尝试将该文件从var/www/html/e.php/opt/lampp/htdocs并确保它具有正确的“-rw-r--r--”

You need to install PHP apache2 module to work with PHP.您需要安装 PHP apache2 模块才能使用 PHP。 You can install libapache2-mod-php from your terminal by typing the command您可以通过键入命令从终端安装 libapache2-mod-php

sudo apt-get install libapache2-mod-php

Apache will be restarted automatically and PHP then available. Apache 将自动重新启动,然后 PHP 可用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM