×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

php code

php code

php code

(OP)
Windows 8.1 Apache 2.4.20
PHP 5.5.15
When I run a php file only the code shows in the browser (chrome). I searched all over the internet but find no solutions. I tried altering the apache config with no success. Please help

RE: php code

For PHP questions please post in forum434: PHP.

How did you install PHP?

How are you attempting to run the php file?

Are you going through a fully qualified domain url? Or simply attempting to open a php file by double clicking or using the Open File option from the browsers file menu?



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech

RE: php code

(OP)
Thanks for answering so quickly. I downloaded xammp from apache and friends. Using local host. I just sent a simple PHP file:
<?php
echo "PHP works";
?>
The output on the browser shows the code and not (PHP works)
I've been all over the internet and can't find a solution please help.

RE: php code


Does your file name end in .php or .html?




----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech

RE: php code

(OP)
php

RE: php code

Is the PHP module loaded in the Apache configuration?

CODE

LoadModule php5_module /lib/apache2/modules/libphp5.so 


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech

RE: php code

(OP)
I have this loaded:
LoadModule php5_module C:/xampp/php/php5apache2_4.dll
LoadModule php5_module /lib/apache2/modules/libphp5.so
The problem remains

RE: php code

I did not realize this was on Windows. You can remove the line I posted above, as that is the Path for Unix installations.

In any case, make sure your php file is executable, right clicking on the file, and setting the permissions for the Apache user to read, write, and execute.

Also, make sure you are opening your files similar to http://localhost/filename.php in your browser, rather than file:///c:/xamp/htdocs/filename.php

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech

RE: php code

(OP)
When I typed it in the way you said I got access forbidden error (no permission) Error 403. But the application I'm using is Laravel. Do I need to adjust the Apache config and localhost to point to the htdocs directory?

RE: php code

When you install XAMPP, you will have a administration panel when just browsing http://localhost

Applications (or Frameworks) are either installed in subdirectories of htdocs or you add Aliases to apaches httpd.conf pointing to other directories. This seems to be done already, otherwise you would only get 404 not found errors, not permission errors. If you started Apache as service, the account used by apache will need permissions to the Laravel directory. It may be easier to install Laravel into htdocs, as that inherits permissions.

If you start learning, you may start off with pure PHP first, and maybe a few basics about Windows file system permissions, services and system accounts?
It may be easier fpr you to find hosting including a preinstalled apache,php and Laravel.

Bye, Olaf.

RE: php code

(OP)
I have full permissions set for both htdocs and laravel directories. At this point all I would like to do is make a simple PHP file and get apache to recognize it. I'm not familiar on how to start Apache as a service I a merely use a gui control pane. I do have artisan running as a service but the problem appears where it's running or not.

RE: php code

Apache should already be pointing to the htdocs director.

What happens if you open http://localhost only?

Do You get the "Apache is up" page?



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech

RE: php code

>I have full permissions set for both htdocs and laravel directories

There often is a simple misunderstanding about Windows file system permissions. If you add the "account" All/everyone, this doesn't include some Windows system accounts. Anyway, this mostly only plays a role, if you run Apache as a service, if you start a normal process from the Xampp panel it'll run with your account and privileges.

As Vacunita said Apache itself will be configured for htdocs by default, so what did you actually do in apache config?

Xampp installs both apache and php and you just have to start Apache and php is executed, the whole xampp administrative panel you see when browsing http://localhost is running on php.

Bye, Olaf.

RE: php code

(OP)
When I typed localhost I got page cannot be displayed.

RE: php code

Then apache doesn't run. If you install xampp you get a xampp control panel installed, from where you can start apache http server, mysql database, filezilla ftp server (if installed) and mercury mail server (if installed). Look out for that and start apache from there.

Bye, Olaf.

RE: php code

(OP)
It wasn't running my bad but now I get.
Access forbidden!

You don't have permission to access the requested directory. There is either no index document or the directory is read-protected.

If you think this is a server error, please contact the webmaster.

Error 403

localhost
Apache/2.4.10 (Win32) PHP/5.5.15 OpenSSL/1.0.1i

RE: php code

After a normal install of XAMPP the htdoc will be configured and permissions granted and there is nothing to do but start apache. So uninstall and reinstall.

Bye, Olaf.

RE: php code

(OP)
My last thought before re-installing I have a 64 bit machine would it have made a difference if I installed the 32 bit version of apache?

RE: php code

If 64bit systems could only run 64bit software you'd not have much more than the OS.

As far as I see there is no 64bit version of XAMPP downloads and you don't need one.

When you install change install location to C:\XAMPP for example or any other directory outside of program files, as system folders are only writable for setup via elevated priviliges during installs.

Also don't change any of the defaults. If asked whether to install Apache as service, don't, that also adds to the problem of htdocs access, as already said. By default two normal apache processes running with your own user account will be started by the xampp control panel, one for http, one for https.

If it still doesn't work, maybe something else on your system is already making use of port 80, eg IIS.

Bye, Olaf.

RE: php code

(OP)
Apache is running on port 80 for sure and xampp is at the C:/xampp. I guess all that's left is re-install. I will inform you of the results after.

RE: php code

>Apache is running on port 80 for sure
That is out of question. But another webserver already is installed and listens to port 80 that will not help to get a consistent response for localhost requests, if you knwo what I'm indicating.

Bye, Olaf.

RE: php code

(OP)
I used to have IIS on this computer but removed before setting up apache. How can I check that nothing else is conflicting with port 80.

RE: php code

You can start cmd.exe as Administrator and then do >netstat -aonb >connections.txt
Look out for :80 in the output text file.

On PC IIS works and there still are several entries listening to port 80, so that is not necessarily an issue. I assume two webservers listening for http protocoll messages might disturb each other.

Bye, Olaf.

RE: php code

And if you have Skype installed make sure it is set to use it's alternate ports as it defaults to 80 & 443

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

RE: php code

(OP)
[Sat Jan 17 13:51:46.436302 2015] [:error] [pid 4420:tid 1724] [client ::1:60037] script 'C:/xampp/htdocs/xampp/imdex.php' not found or unable to stat
I did a fresh install and still can't view a php file above is the error I get when I do localhost. I wrote apache and friends and waiting for a response. Please Please help

RE: php code

m ---> n?

imdex.php should be index.php, shouldn't it?

Would it really be so simple, that you misspelled the name of your script?

Bye, Olaf.

RE: php code

(OP)
I seen that as well but couldn't find where to change that link. because all I typed was localhost.

RE: php code

Aha, when you request a domain name only (or localhost) the web server looks for default files configured in webserver config.
So look out for imdex in apache.conf, maybe you altered something there.

It seems either the xampp installer has this wrong already or does not touch existing config.

You should perhaps deinstall xampp, delete C:\XAMPP and only after that is removed install back.

Bye, Olaf.

RE: php code

Just a word of caution. It doesn't seem you invested much work in htdocs already, aside of your php test script, but if there is work in it, eg by colleagues, instead of deleting c:\xampp after deinstallation you can of course also rename it. Just so the new install really is fresh and not mixing with already/still existing files.

If the bug to let the default file point to imdex.php instead of index.php is part of the xampp download I suggest you download another version.

Bye, Olaf.

RE: php code

OK, I made an attempt to install XAMPP myself, though I already have IIS, PHP and MySQL installed.

The installation itself is xampp-win32-5.6.3-0-VC11-installer.exe, so Version 5.6.3.0

The installer detected UAC on and suggested C:\XAMPP. That's OK
Starting XAMPP control panel it reports a problem starting apache:

20:59:39  [Apache] 	Problem detected!
20:59:39  [Apache] 	Port 80 in use by "Unable to open process" with PID 4!
20:59:39  [Apache] 	Apache WILL NOT start without the configured ports free!
20:59:39  [Apache] 	You need to uninstall/disable/reconfigure the blocking application
20:59:39  [Apache] 	or reconfigure Apache and the Control Panel to listen on a different port
20:59:39  [Apache] 	Attempting to start Apache app...
20:59:39  [Apache] 	Status change detected: running
20:59:40  [Apache] 	Status change detected: stopped
20:59:40  [Apache] 	Error: Apache shutdown unexpectedly.
20:59:40  [Apache] 	This may be due to a blocked port, missing dependencies, 
20:59:40  [Apache] 	improper privileges, a crash, or a shutdown by another method.
20:59:40  [Apache] 	Press the Logs button to view error logs and check
20:59:40  [Apache] 	the Windows Event Viewer for more clues
20:59:40  [Apache] 	If you need more help, copy and post this
20:59:40  [Apache] 	entire log window on the forums 

So there you also have info about what already uses a certain port.

I did as is suggested and clicked on the Config button of the XAMPP control panel to open httpd.conf. In that config file you find this section:
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to 
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 12.34.56.78:80
Listen 80 
And here I changed the 80 to 8080. That's a well usable alternative. If you create a webapp in IIS it suggests using port 81,82,83 and so on. Those are also fine.

Anyway as said I changed port to 8080 here.

Now start succeeds. Next message is coming from Windows Firewall and says Windows Firewall is blocking some functions. I clicked on Allow access and Yes in the follow up dialog.

And voila, XAMPP control panel shows Apache green and says it's running as some PID and using ports 443 and 8080.
And now http://localhost:8080 displays the XAMPP start page.

Even though its unclear what happens at your PC, the XAMPP installation is not faulty and the config not false for systems not running anything previously installed/configured. You just have to read and react to the messages given, see the signals and all is well.

If you installed once again I suggest you keep an eye on what happens, if you click on Apache Start Button. You also may find a blockade in your Firewall, if you ever reacted to the first firewall warning with not allowing Apache. You have to allow it to work.

Bye, Olaf.

Bye, Olaf.

RE: php code

(OP)
Thank you for all your help. I got past the php problem. When I display my page using sublime view in browser all is well. But when I try to view using localhost:8000 I get 404 errors unable to find my css or js. Here is my code:
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>IMG ON-LINE</title>

<!-- JS -->
<script type="text/javascript" src="/imgweb2/public/js/jquery.js"></script>

<script type="text/javascript" src="/imgweb2/public/js/jquery-ui.js"></script>
<link rel="stylesheet" href="/imgweb2/public/css/menu.css" type="text/css media="print, projection, screen"/>

</head>
I've tried putting the css in the same folder I tried assets and can't get it to view properly using any browser. Any ideas when I physically put the css code directly in the html file it worked but I must be able to point to an external file. Again thank you very much you are very helpful.

RE: php code

Relative paths have to begin with ./, or no thing at all, If you begin a path with / you refer to root. HTML never uesed windows path conventions, as you can simply see by it using slashes and not backslashes.

For example <a href="mysecond.php">click here</a> refers to a script mysecond.php in the same folder as the current. The same applies if writing <a href="./mysecond.php">click here</a>, but not in general with <a href="/mysecond.php">click here</a>, only if the current html is in the root folder, too.

So / means root, ./ or nothing means current folder, ../ means one folder up.

Bye, Olaf.

RE: php code

By the way, practicing relative links via <A> tag is easy, as the browser status bar will show the full qualified URI if hovering over a link.

Bye, Olaf.

RE: php code

(OP)
Got it thank you. You're the best. I'm learning with laravel and at times it becomes confusing.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close