PHP is not interpreted, showing in sight

I hope this will be a useful page to get started with php code, as well as to solve the current problem. I have a very simple code:

<html> <head> <title> Practice</title></head> <body> This is HTML <?php echo "This is PHP"; ?> </body> <html> 

This uploads to the ec2 website with apache running. The code is not interpreted, and when you look at the source of the page, it shows the PHP code.

You can see the page .

Any ideas? The PHP code is so basic that I think it could be related to the apache configuration. Please let me know any additional information that you need and I will provide it, hope to tell me how to get it.

+10
source share
5 answers

Are you sure you have php installed? If you need to make sure apache associates .php files with a php handler. Find an entry similar to the following in /etc/apache/apache.conf

  LoadModule php5_module modules/libphp5.so 

and

  application/x-httpd-php php php5 

when changing the file you will need to restart apache via sudo service httpd restart

+8
source

You can install libapache2-mod-php5 using

 apt-get install libapache2-mod-php5 

Worked for me.

+9
source

You probably need addHandler or addType either in the .htaccess file or in the Apache configuration itself: for example, AddType / x-httpd-php.php Application

+3
source

If you are using php7, make sure you install this module.

sudo apt-get install libapache2-mod-php7.0

0
source

If you have the contents of a web page in a user directory, for example:

 /home/*/public_html 

Then you need to enable them, disable by default:

 # Running PHP scripts in user directories is disabled by default # # To re-enable PHP in user directories comment the following lines # (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it # prevents .htaccess files from disabling it. <IfModule mod_userdir.c> <Directory /home/*/public_html> php_admin_flag engine Off </Directory> </IfModule> 

Just comment out this piece of code located in the file:

 /etc/apache2/mods-enabled/php7.3.conf 

Correct the path and file name on your system, version of PHP, etc.

0
source

Source: https://habr.com/ru/post/921039/


All Articles