0
votes

I have installed Apache2 and PHP 7 with(sudo apt-get install php7.0 php7.0-mcrypt) on my machine. When I hit php -v in terminal, it return:

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

So then I created one PHP file at var/www/html/e.php with the below content:

  <!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. What am I missing? The Ubuntu "It Works" page of Apache works.

Thanks in advance.

3
Do you mean that you see the PHP code on the page or something else?Julie Pelletier
It doesnt show anything regarding php, looks like there is no php on my machine. @JuliePelletierJulinho da Adelaide
@JulinhodaAdelaide any update for us !!PacMan

3 Answers

1
votes

you have to install apache+php module.

find the below command to install all php module with apache

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

a2enmod php7.0

restart the apache webserver

service apache2 restart

then try to open into browser . http://localhost/e.php)

0
votes

i was getting the same issue before in ubuntu ,try to move that file from var/www/html/e.php to /opt/lampp/htdocs and make sure it had the right "-rw-r--r--"

0
votes

You need to install PHP apache2 module to work with PHP. You can install libapache2-mod-php from your terminal by typing the command

sudo apt-get install libapache2-mod-php

Apache will be restarted automatically and PHP then available.