开发者

PHP script display as text in browser

开发者 https://www.devze.com 2023-02-03 11:48 出处:网络
I have installed PHP, Apache in my开发者_如何学C Linux server. http://localhost/index.htm displaying correctly. To test the PHP I have created test PHP file phpinfo.php. Here is the code in that file

I have installed PHP, Apache in my开发者_如何学C Linux server. http://localhost/index.htm displaying correctly. To test the PHP I have created test PHP file phpinfo.php. Here is the code in that file

<?php phpinfo(); ?>

But when try to http://localhost/phpinfo.php, browser displays script in the file. Apache did not execute the script in the file. What would be reason for this?


You have not configured Apache to run .php files through PHP.

In the installation manual those would be the lines about

LoadModule php5_module modules/libphp5.so

and

<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>

You probably want to add index.php to the default files as well.


Well this means that php is not enabled for your webserver. Have you restarted apache after installing php as well as have you tried a2enmod php or a2enmod php5


On Ubuntu 16.04 with PHP 7.0, the following should work:

apt update
apt install libapache2-mod-php7.0

If it does not work, run a2enmod php7.0 and service apache2 restart.

0

精彩评论

暂无评论...
验证码 换一张
取 消