Posted March 3, 2017 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 https://linustechtips.com/topic/746992-linux-web-server-not-displaying-php/ Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted March 3, 2017 Which distro of Linux are you using, and what web server? Apache or nginx? Link to comment https://linustechtips.com/topic/746992-linux-web-server-not-displaying-php/#findComment-9461203 Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted March 3, 2017 Author 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 https://linustechtips.com/topic/746992-linux-web-server-not-displaying-php/#findComment-9461211 Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted March 3, 2017 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 https://linustechtips.com/topic/746992-linux-web-server-not-displaying-php/#findComment-9461224 Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted March 3, 2017 Author 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 https://linustechtips.com/topic/746992-linux-web-server-not-displaying-php/#findComment-9461255 Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted March 3, 2017 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 https://linustechtips.com/topic/746992-linux-web-server-not-displaying-php/#findComment-9461266 Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted March 3, 2017 Author 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 https://linustechtips.com/topic/746992-linux-web-server-not-displaying-php/#findComment-9461394 Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted March 4, 2017 did you save the file as .php? ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est ¸„»°'´`'°«„¸`'°«„¸¸„»°'´ Link to comment https://linustechtips.com/topic/746992-linux-web-server-not-displaying-php/#findComment-9461465 Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted March 4, 2017 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 https://linustechtips.com/topic/746992-linux-web-server-not-displaying-php/#findComment-9462079 Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted March 4, 2017 @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 https://linustechtips.com/topic/746992-linux-web-server-not-displaying-php/#findComment-9463487 Share on other sites More sharing options... Link to post Share on other sites More sharing options...
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 accountSign in
Already have an account? Sign in here.
Sign In Now