One website showing as text on LAMP - php

I have a local install of Apache / MySQL and PHP on Fedora Linux.
I know PHP is running ok as some of my websites are running fine and if I create a simple file I can see I am running PHP 5.4.1.
Searching Google brings up tons of hits where the issue is PHP is not running at all but that isn't the case here - it's only one site that displays as plain text instead of processing as php.
I'm sure it's some kind of seeting in httpd.conf but have had a look and there is nothing obvious (to me anyway).

If some pages work and some don't check if it's a short_open_tag in php.ini issue. (it allows for <? instead of only <?php)

Related

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..?

Use PHP Include offline

In testing our site it would be so much easier to use PHP include offline. Essentially rather than put a page together for the purposes of testing, we would rather just include the various html files from their respective areas.
Our macs do not render PHP pages when offline and just show the source code. Is there a way to make them?
You need a local webserver in order to run php in your browser.
check out mamp or zend server
Once installed you can type localhost and whatever is the default directory will show in your browser. What I usually do is instad of just accessing everything through localhost I create an alias in the /private.etc/hosts/ file and the http.conf file in mamp
You would need a local web server to render any PHP code. MAMP might help you : www.mamp.info
To include HTML code into php with include() or require() you'll have to change the extension of the files from .html to .php even if no PHP code is inside them.
Also you could use a localhost server. There are mainly 2 of them for Mac:
Mamp
Xampp
I use the latter and I think it's the best. I had some trouble with Mamp years ago while Xampp worked just fine.
You have to make a php server. Free MAC php/ mysql server http://www.mamp.info/en/index.html

XAMPP (LAMPP) server not serving php files properly, browser tries to download the script & weird behavior

I'm starting a new project using Linux and PHP, but for the early dev state i'm now, I'm trying to use XAMPP for now.
I'm Running Ubuntu 10.04 x64 on a laptop, And got everything I need. The site I should build is based upon CodeIgniter and some implementation of smarty, but I think this is not that important because the same site runs pretty well on windows (with XAMPP )
The Problem I have is, if I put some php file on the root (like foo.php) with phpinfo() on it, the server parsed it as it should be, but when I try to get the url for one CodeIgniter app (as http://localhost/site/site.php ), Firefox tries to download the file & Chrome alerts some server error.
Again, the site as it works perfectly on windows (I share code using mercurial, if that's important)
I have around 3 codeigniter apps sharing the same System folder, and those get pickup by the loader (as site.php, admin.php...), but anyone I pick I still getting the same msg.
Also, the server list all the files perfectly, and tried to rename the file and then asked for the same (to see if the problem is cache or something) but I get a 404.
I'm also a newbie on apache and linux in general, I don't know what to do...
Check your apache.conf and httpd.conf. There are configuration entries called AddHandler which assign a module to each file extension which should handle this. If no module is provided the apache will send the file as plain text to the client.

How to get started with sql and php?

I was wondering how to link a SQL database on my PHP code.
I am using a database on my local server that I set up and I have already created a database, I tried writing a PHP script with ++notepad, but when I clicked on the script, it opened the browser and displayed a blank page. What am I doing wrong? I created my databases using phpMyAdmin.
You need to be running a web server locally which supports PHP (like Apache). It it the web server which does the PHP processing. At the same time you will have to run a MySQL (or any other) database engine too, so your PHP code can connect and query it. (I'm assuming you've already installed PHP.)
I would recommend you install XAMPP which includes Apache, PHP, MySQL and a bunch of other stuff. It one of "Apache friends". Once you install XAMPP you would have a folder htdocs in the xampp folder. Create a folder for you project myproject and place your PHP script script.php in there. Now if MySQL and Apache are running following should behave as you expect.
http://127.0.0.1/myproject/script.php
For the tutorial, to begin with you can use W3Schools. Brief and to the point. They have both a PHP tutorial and a SQL tutorial.
This is a very good book to start with:
PHP and MySQL
Web Development
Luke Welling and Laura Thomson
You have to play with php/sql code practically. Only reading cant help!
go for w3shools as mentioned above :)
start with simple code and then go to the complexity. all the best.. :)
There are multiple ways on how to do that.
One of the most modern ways to do that, is to use PDO to connect to the DB with PHP.
To run PHP on your PC(which i assume is your workstation), you need the supporting software for it, for php to run you need the PHP software installed, and likewise if you want to run the server software you need apache, however you can go for a single install package which will install almost everything for you to run your php script, download and install the wamp.
to install wamp which stands for (windows, apache, mysql, PHP) if you are running windows, and lamp for linux or mamp for mac, all of which are free softwares, you can download wamp from the following link. http://www.wampserver.com/en/download.php that is the first step which you need to do.
step 2: once wamp is installed the default directory of installation is C:/wamp (i reccomend do not change the location of the installation), you need to start the wamp server by just opening or double clicking the software which you just installed.
step3: navigate to the default directory where you should be storing your PHP files and that is C:/wamp/www note that you should be keeping all your PHP files here apart from this location if you store it anywhere else it wont simply run at all, and that it should and must have the .php extension.
step4: create or save the php files in this location(c:/wamp/www) i for example will assume you have created a file test.php in the www folder. now to access this file open your web browser and type http://localhost/test.php there you go, you will have the access to your PHP file (Note: PHP files cannot be run by simply double clicking the file, you have to follow this procedure in order to run the PHP files)
step5: open the test.php in any of your text editor like notepad, or i recommend use an IDE (Netbeans is free and worth a try), and write your code in the following format.
<?php
your PHP code should go here.
?>
when i started writing the code i started by following a nice tutorial which i found in zend.com, it has one of the best examples, and moreover the tutorial is meant for the beginners. hope this helps you..
http://devzone.zend.com/tag/PHP101

PHP -> CLI has stopped working

I recently installed Windows 7 on my desktop and the following problem has begun occuring:
I regularly run some PHP scripts from the commandline that are now giving this error in a popup window:
CLI has stopped working.
I cancel this and my script terminates. Not good...
I've googled around and tried most of the few ideas suggested but still i am plagued by this annoyance. Right now it appears to regularly occur when I do a file_get_contents() of a url pointing to an image file. Only happens when the url is http protocol, works fine for ftp files. It also happens spuriously doing other things as well.
This is PHP 5.3.0 as distributed in a xampp 1.7.2 .zip. All exe's and dll's have been unblocked by copying thru FAT32 and back.
hints from anyone who's cracked this would be most helpful.
Try updating your PHP version bundled with xampp. You might have to update some php_XXX.dll extension files.
More info: http://web2.0entrepreneur.com/31/cli-has-stopped-working-on-windows-vista.html
PHP-CLI stops under these circumstances: Windows 7 64bit, PHP 5.6.8 64bit, only when Zend OpCache extension is ENABLED!!!
Just edit php.ini and comment zend_extension=php_opcache.dll (with ; in front of it)
I found that this happened to me when I had the APC extension enabled. I switched to using the Wincache for PHP extension instead.
If you receive this error after installing WAMP, most likely you have another installation of PHP on your machine. This may have been installed using the Microsoft Web Platform Installer or by other means. The first thing you should do is un-install PHP.
If this doesn't work, check to make sure that IIS and Apache are not trying to use the same port. WAMP starts out with Port 80 as standard and IIS usually will be the same. The easiest way to fix this is to turn off IIS while running WAMP, but you can set either of them servers to port 81 or another port.
If this doesn't work, my last suggest is to look for multiple copies of php.ini on your machine. You may find them in places like the Windows directory. Make a backup of the file just in case, and then remove them from all of the folders except the WAMP folder.
it happened to me in laravel 5.I searched every where but no solution that fix my problem then i debug my web application at different points and found that if you comment your php code in laravel comments in blade template like
{{--print_r($date_a);--}}
Now comment like this
//print_r($date_a);
works
The solution for me was to stop using PHP 5.3.0 and go back to 5.2.11. Once I did this the "CLI has stopped working" issue disappeared.
I have the same issue with Windows 7 Professional.
My Apache Server has no problem finding and executing PHP within my web application but the command line execution gives the infamous message "CLI has stopped working."
The User Account Settings seem to allow executions.
Perl has no problem.
I always have to take my code to an XP machine and run it there to debug it.
You didn't specify that you were using xdebug, but just in case you were, I may be able to help. I had this error for a long time. It turned out I was on a slightly older version of Xdebug (php_xdebug-2.2.0-5.4-vc9.dll).
I replaced that file with "php_xdebug-2.2.2-5.4-vc9.dll" and it magically started working immediately.
I'm on wamp, and I updated both php.ini files (one is for cli, one for normal use) with the latest filename.
"zend_extension = c:\wamp\bin\php\php5.4.3\ext\php_xdebug-2.2.2-5.4-vc9.dll"
Then dropped the new file into the php ext folder and instant success.
I had the same issue on Windows 7 (Home premium). I had a hunch that it is caused by one of the extensions I installed so I started commenting them out one-by-one.
Turned out it was caused by a non-compatible mongodb extension I was using
Edit php.ini and comment zend_extension=opcache.enable_cli=1 (with ; in front of it)
Try to use another php version instead.
It works perfectly for me.
Try to run scripts with php-cgi.exe instead of php.exe. For me it works.

Categories