can't use php in html (mixing) - php

I would like to set up a small nginx server on my pi.
So far, html and php5 are working, but if I make a mixing, lets say:
<p>It is <?php echo time();?> UTC </p>
It would show me:
It is UTC
But if I put a index.php in root with echo phpinfo(); (index.php comes before index.html)
I got no error at all.
I followed this tutorial:
Is there anything else to install in order to use mixings?
I installed Rasbian as OS.
I am definitely not a pro, any help will be very appreciated.

Some versions of PHP are not compatible with certain versions of web servers, at least in Apache. I have next to zero experience in nginx, but if I'm not mistaken it's more commonly used for CGI, being event-based and not process-based. CGI still has it's place for some things, but I've found using MySQL more secure, and MSSQL more secure still.
On that note, you might prefer installing Apache over nginx, unless you have specific reason otherwise: I'm not sure how well developed nginx is on the RasPi, but I know many people use Apache to run web servers on it. If you're sure about using nginx, make sure there's no errors when you run the line from that page [sudo apt-get install php5-fpm].
Your issue itself seems that the PHP is not parsing. HTML will process and HTML between carrots (< and >), and not show that output to the user. However, unless PHP is working, it still is visible if you view source. To make sure PHP is installed, view the page source and see if you can see that php code. If you can, PHP isn't installed or working. If it doesn't show up, there's likely a problem with the compatibility of the server. Also, some PHP code ends up deprecated on newer versions, while some instructions are new. Make sure your issue is you're using correct code/syntax for your installed PHP version.
Lastly, but possibly most importantly: Make sure you're following the "TEST THE WEB SERVER" of your tutorial properly, and visit it from ANOTHER computer. If you try from the same IP address, it can result in loopback, where PHP won't parse for the same IP address as the source.
I also found this resource that might lead you in the right direction.
https://serverfault.com/questions/593677/php-file-are-not-parsed-by-fastcgi-in-nginx
I know this is a long answer, but it's a good way to troubleshoot with logic and understanding of how it works.

What is the extension of the file .php or .html ? It should be of type .php when you are using Php script in a file with html ie your file should be saved with extension .php.

Related

course index.php file it's not loading after upgraded from moodle 2.2.11

I need some help with my course material created for moodle. The problem is that after I upgraded the 2.2.11 moodle version to version 2.8.3 , the course main index.php file it's not interpreted anymore and it shows the source of that index.php file. Also with the upgrading process I switched to a new php 5.6.3 version(The new moodle it works only with 5.4 or higher versions, and I think this is the problem, because with the 5.3 php version it worked everything fine) upgrade.The error is :that when I try to acces the course, instead of the course material place it appears the index.php source code.
If your PHP code is not executing and instead is loading as plaintext, then I'm 80% sure this is a problem with PHP rather than Moodle itself.
First thing you need to do is check that PHP is installed and running.
You can do this by running this code:
<? phpinfo(); ?>
If you get a return, then it's working, if not, then revisit your cPanel and have a gander at your settings.
Check that your Apache server is running PHP by checking your httpd.conf file.
And I know it sounds daft, but also check your index.php file's syntax. (Especially if PHP turns out to be running fine) because that would generally mean that you have a syntax error. If it boils down to this, check that all your statements, otherwise the server will just assume it's plaintext. Easiest way to do this is using NotePad++. Click on any
Tldr: This is probably PHP not running correctly. Nothing to do with Moodle I imagine. But I could be wrong.

phpinfo() returns blank page in Firefox and asks whether to open or save in IE

I'm trying to update a site that's using php. I built the site and tested it on this machine. But today, the Php won't run on my local machine.
To test, I went back to the most basic php page I have:
<?php
phpinfo();
?>
When I navigate to this file, in Firefox (28), the result is a blank page. (The page source shows just my code.) In IE 11, I'm asking whether I want to open or save the file.
Searching for my original problem (which was that my php code was showing up rather than running), it was suggested that php wasn't installed. I don't know how it would have gotten uninstalled, but I went ahead and installed it again (from http://www.microsoft.com/web/platform/phponwindows.aspx) and still no joy.
Windows 7 SP1
Updates in response to suggestions:
Pardon the beginning stuff, but I'm not primarily a web developer. (I do databases.) This is stuff I'm doing for an organization I'm involved in. I don't actually remember having installed/configured a web server in the first place, nor do I remember having installed php before yesterday (though maybe my son did that for me).
After seeing the replies here, I followed the instructions on this page: http://webmasterjuice.com/how-to-activate-built-in-web-server-windows, but I'm still seeing the same thing.
Update:
I've confirmed that IIS is running and the php was installed. I've followed instructions I found online for getting php working in Windows 7 with IIS. However, it still doesn't make sense to me to have to do this. I'm sure I didn't do any of this when I started working with php. I'm not trying to use my computer as a web server. No interest in working through localhost.
I'm creating the file in a simple web-oriented editor (Crimson Editor). Until recently, I could use the editor's preview function on a file, whether HTML or PHP, and it would run correctly. I'm baffled as to why this stopped working.
A few things to look for:
It's php running besides been installed? (obvious, but maybe it got killed by some reason)
Have you included the phpinfo() call inside a html document?
Obviously you named the file with a .php extension and saved it within the document root of the server..?

PHP on IIS 5.1 is not working

I know this has been asked a few times here. But none of the suggestions or answers related to PHP on IIS have helped.
I have tried installing PHP ON IIS 5.1 (XP SP 3) on two computers and it still doesn't work.
I've even began to think that all of the articles and installers for PHP on IIS are a huge prank...and that PHP on IIS doesn't actually work.
I've spent the last 6 hours trying to get it to work. Nothing does. As of right now when I navigate to http://localhost/phpinfo.php all that shows up is: "The specified module could not be found." My IIS applications still work perfectly.
phpinfo.php contains:
<?php echo phpinfo(); ?>
Even loading test.php with "Hello World." in it gives me the same error message.
The current installation of PHP was installed from http://php.iis.net/ (the big blue button in the middle of the page). This installed PHP in my programs directory (F:\PHP).
That didn't configure PHP to work so I manually added the Application Mapping in "Web Sites" > Properties > Home Directory > Configuration > Mappings > Add.
I added C:\WINDOWS\system32\inetsrv\fcgiext.dll, ext .php, "GET,HEAD,POST"
Anyone have any idea what my problem is?
Sounds like you've not installed the FastCGI components (which to be honest you don't really need on your local development machine). Can I suggest mapping the .php extension to:
F:\php\php-cgi.exe (or wherever the PHP binaries are installed)
Also make sure you give your site's anonymous user account at least read access to the F:\PHP folder and children.
I think the DLL you are using for getting PHP to work have a missing dependency. Why don't you get a WAMP.
Do you really need to use IIS, using Apache would be far more easy IMHO. If you really want to use IIS, I advise to install the official PHP release they have a good README which describe all the steps to configure IIS or even an installer.

PHP on windows environment Vista

Do I need a special library to run PHP on Windows environment Vista?
I can write simple message like echo "hello" but whenever I try to run any these scripts no error nothing display on the page http://php.net/manual/en/function.crypt.php.
I'm new to PHP please help
When in doubt...
<?php echo phpinfo(); ?>
If that code outputs information regarding your PHP version and settings, PHP is installed correctly.
There would be errors in your code if nothing is displaying. Post the code you are having trouble with and we can help you out.
Have you actually set up a local server? You'll need this to run PHP scripts. For a newbie I'd recommend WampServer since it's really easy and handles all the complexity of installing a server. Once installed and running, try http://localhost/ in your web browser.
Based on your comment though, I think the problem is that the sample code on the page you posted won't work on their own, you'd need to combine them with other things. For example the first one references a variable $user_input which you'd replace with a variable taken from user input (eg a form) on your site.
I suggest finding some tutorials online (or buy a book) and walk through various proper examples to familiarise yourself with PHP.
Do you have PHP / Apache installed at the moment? If you don't, try XAMPP. It comes with an easy and convenient installer.
Like most languages your computer must have the language/compiler installed in order develop and run scripts/applications. PHP was originally designed for web development so you won't usually find it installed on PCs by default.
The easiest way to develop PHP is to upload the scripts to a web server that has PHP installed and then test in your browser in the same fashion that you'd test an HTML page.
Otherwise to do it locally on your computer you can install a web development environment which acts like a web server. Essentially eliminating the upload step.
I believe the most popular for Windows is Wamp Server

How do I get PHP and MySQL working on IIS 7.0?

Okay, I've looked all over the internet for a good solution to get PHP and MySQL working on IIS7.0. It's nearly impossible, I've tried it so many times and given up in vain. Please please help by linking some great step-by-step tutorial to adding PHP and MySQL on IIS7.0 from scratch. PHP and MySQL are essential for installing any CMS.
Have you taken a look at this:
http://learn.iis.net/page.aspx/246/using-fastcgi-to-host-php-applications-on-iis7/
MySQL should be pretty straight forward.
Let us know what problems you're encountering...
I've been given a PHP / MySQL web site that I'm to host with IIS 7.0 on 64-bit Windows Server 2008.
I'm a .NET / MSSQL developer, and am unfamiliar with either PHP or MySQL.
Kev wrote:
Have you taken a look at this…
I don't know if any one implementation of Win64 PHP is more authoratative or popular than another.
I'm going to try following the steps in Kev's Enable FastCGI support in IIS7.0 article with file php-5.2.5-x64-2007-11-12.zip from fusion-x lan.
It's "PHP Version 5.2.5 (x64)", but according to php.net, the latest version is PHP 5.2.6. Oh, well.
Make sure "ISAPI Extensions" are installed in IIS (mine were).
Download and then unzip php-5.2.5-x64-2007-11-12.zip
Copy contents of folder php-5.2.5 (x64) into *C:\php*
Copy file C:\php\php.ini-dist into folder *C:\Windows*
Rename file C:\Windows\php.ini-dist as php.ini
Edit php.ini in Notepad. Remove leading semi-colon (;) from line:
;extension=php_mysql.dll
Save and close
Copy file C:\php\ext\php_mysql.dll into folder *C:\Windows\System32*
Within IIS Manager's "Handler Mappings", choose "Add Script Map…"
Request path: *.php
Executable: C:\php\php5isapi.dll
Name: PHP
Install MySQL (someone had already installed MySQL 5.0 for me).
Create file C:\inetpub\wwwroot\test.php as
<html>
<head>
<title>PHP Information</title>
</head>
<body>
<?php phpInfo(); ?>
</body>
</html>
Navigate to http://localhost/test.php in your web browser. You will see a page of information about PHP.
Roadblock: How do I get PHP to work with ADOdb and MySQL?
It's supposed to work via FastCGI. But I haven't had great success (using Vista). I can get PHP to run, but it crashes after a page loads (FastCGI does). So I'm modding you up. I'd like to see a reliable answer myself.
From my experience with windows/apache it's just a matter of install MySQL, I can't Imagine that IIS/Apache has anything to do with this.
Apache is a major pain to get running in Vista. And II7 (and 6) are suppose to run PHP fine. So why bother with Apache?
I would suggest if you are going for a PHP and MySQL install to instead use WAMP. It works great and is easy to add extensions and modify everything. I use it for work and love it.
One of the IIS developers has an excellent walkthrough here:
http://blogs.iis.net/bills/archive/2006/10/31/PHP-on-IIS.aspx
However, for the love of god why?

Categories