Jump to content

Linux Web Server Not Displaying PHP

FaiL___

Hi, I am just starting to learn PHP (after having done HTML, CSS, and JavaScript. I am currently hosting my own website which I am using to practice my coding. I cannot however, seem to get my website to display the PHP code e.g. echo commands do not output anything. Is there anything I can do to try and do to fix this? Here is my code:

<!DOCTYPE html>
<meta charset="utf-8"/>

<html>
    <head>
        <link rel="stylesheet" href="css.css">
        <script src="javascript.js"></script>
    </head>
    <body>
    <?php
     echo "Hello";
    ?>
    </body>
</html>

 

There are 10 types of people in the world. Those that understand binary and those that don't.

Link to comment
Share on other sites

Link to post
Share on other sites

Which distro of Linux are you using, and what web server? Apache or nginx?

Link to comment
Share on other sites

Link to post
Share on other sites

Ubuntu 16 and apache2

 

There are 10 types of people in the world. Those that understand binary and those that don't.

Link to comment
Share on other sites

Link to post
Share on other sites

3 minutes ago, FaiL___ said:

Ubuntu 16 and apache2

 

Double check you have installed these packages from aptitude:

sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt

Edit: when you've done that, restart apache2:

sudo service apache2 restart

 

Link to comment
Share on other sites

Link to post
Share on other sites

8 minutes ago, Octobyte said:

Double check you have installed these packages from aptitude:


sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt

Edit: when you've done that, restart apache2:


sudo service apache2 restart

 

That hasn't helped

There are 10 types of people in the world. Those that understand binary and those that don't.

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, FaiL___ said:

That hasn't helped

Apologies, I think I got the wrong version of php there. Try these. If those don't work, take a look at DigitalOcean's guides for a resource

 

https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-16-04#step-3-install-php

 

sudo apt-get remove php5 libapache2-mod-php5 php5-mcrypt

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

sudo service apache2 restart

 

Link to comment
Share on other sites

Link to post
Share on other sites

34 minutes ago, Octobyte said:

Apologies, I think I got the wrong version of php there. Try these. If those don't work, take a look at DigitalOcean's guides for a resource

 

https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-16-04#step-3-install-php

 


sudo apt-get remove php5 libapache2-mod-php5 php5-mcrypt

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

sudo service apache2 restart

 

That still isn't working :(

There are 10 types of people in the world. Those that understand binary and those that don't.

Link to comment
Share on other sites

Link to post
Share on other sites

did you save the file as .php?

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

3 hours ago, FaiL___ said:

That hasn't helped

Make sure php is actually running with

sudo service --status-all | grep php

 

Link to comment
Share on other sites

Link to post
Share on other sites

@FaiL___ How are you testing the PHP code?

Make sure you are

a) saving the .php file in Apaches htdocs folder, default location on debian/ubuntu is I belive /var/www/htdocs, and

b) opening your web browser and going to http://localhost/filename.php to run your PHP code

 

You cannot be opening .php files directly into the browser (ie, the address begins with file://) as this will not work!

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×