Apache is downloading php files instead of displaying them

后端 未结 26 1705
陌清茗
陌清茗 2020-11-22 01:03

OS and server information:

  • CentOS 6.4 (Final)
  • Apache 2.2.15
  • PHP 5.5.1

I previously had php 5.3.x installed but decided to upgr

26条回答
  •  傲寒
    傲寒 (楼主)
    2020-11-22 01:30

    I got this kind of problem. This is how I solve it. After installed Apache then I installed PHP using this command.

    sudo apt-get install php libapache2-mod-php
    

    it executes correctly but I request .php file from Apache, it gives without executing the PHP script.

    Then I check PHP is enabled.

    $ cd /etc/apache2
    $ ls -l mods-*/*php*
    

    but it didn't show any results. I check installed PHP packages.

    $ dpkg -l | grep php| awk '{print $2}' |tr "\n" " "
    

    Different type of PHP versions installed to my computer. Then I remove some PHP packages from my previous list, using apt-get purge.

    sudo apt-get purge libapache2-mod-php7.0 php7.0 php7.0-cli php7.0-common php7.0-json
    

    I reinstall PHP

    sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql
    

    Verify that the PHP module is loaded

    $ a2query -m php7.0
    

    if not enabled with:

    $ sudo a2enmod php7.0
    

    Restart Apache server

    $ sudo systemctl restart apache2
    

    Finally, I check PHP process on Apache

    create an empty file

    sudo vim /var/www/html/info.php
    

    Add this content to info.php & save.

    
    

    Check on browser:

    http://localhost/info.php

    it shows correctly.I think this will help anyone.

提交回复
热议问题