I had a lamp server installed and the server stopped working. I have fixed that problem and the server works now, however when running a php file it just displays the code instead of runnning it. I think this problem may have to do with the fact that i have reinstalled apache2 to try to get my server to work. Im guessing it had messed up some the configuration between apache and php however i have no idea how to fix it.
I also have mysql installed which i cannot test on the server until php is working again.
you probably have not configured apache to use php, this is from my conf file
#PHP Include
Include conf/extra/php5_module.conf
and
LoadModule php5_module modules/libphp5.so
apache service would require a restart after any edits
Content-Type might be set to text/plain. Change it to text/html instead.
Related
I've got this jQuery function:
function phpmail(){
$.post('mail.php',{name:$("#name").val()},
function(out){
alert(out);
});
}
and this PHP script in mail.php:
<?php
$name=$_POST['name'];
echo $name;
?>
However, each time when I click a button, I get PHP code and not the variable, so can someone explain me what I'm doing wrong?
I'm testing this on my local computer using WAMP.
maybe you test it using wrong url (on the browser)..
it should start with http://localhost/
not file:///c:\wamp\bla
This is a serious issue. You should make sure that php is correctly installed on your instance, otherwise anyone could see your code. Also make sure that your web server is not treating your cgi files as plain-text/html
This has nothing to do with either your PHP or JavaScript code. The problem is that your web server is misconfigured. It isn't recognizing ".php" as PHP code and therefore not parsing it.
You need to tell your web server that files with a ".php" ending are to be handled by PHP. You don't mention which web server you're working with so it's difficult to give you precise instructions for that but for what it's worth, here's the relevant portion of my Apache configuration.
<IfModule mod_php5.c>
<FilesMatch "\.ph(p3?|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>
# ...bunch of irrelevant stuff here
</IfModule>
Of course, in order for PHP to work at all, the module must be loaded like so:
LoadModule php5_module /usr/lib/apache2/modules/libphp5.so
However, if you're running Linux, it is strange if you have to configure this yourself. But then again I don't know what you're running.
Web servers differ quite a bit from each other, so it's difficult to give you good instruction without more information on your runtime environment. Are you running Apache or IIS or Lighttp etc.? - Are you running on Windows or Linux or Mac? If Linux, which distribution, Debian or Fedora Core or Ubuntu?
Do you config you Web Server(Such as Apache or nginx) correctly? Do you handle the php file as the plain text??
I just set up a local web server on a new Mac running 10.6 (Apache2 / PHP / Mysql). Everything seems to be working fine except when I navigate to SOME (not most) pages Apache downloads php files instead of executing them.
I thought this might have something to do with the time it takes php to execute the script so I increased my "max_execution_time" but it didn't help.
I wish I could give more details but the error logs don't output anything so I really have no idea why this is happening. One thing that might be of significance is that only pages that don't query the database seem to work every time.
UPDATE:
Just discovered something strange that might give more insite into the problem. If I type the following URLs:
localhost/index.php // the home page is served up correctly
localhost/index.php?page=1 // the home page is served up correctly
localhost/index.php?page=home // ERROR: index.php is downloaded !!!!!!!!!!
localhost/index.php?page=contact // the contact page is served up correctly
localhost/index.php?page=blog // ERROR: index.php is downloaded
localhost/index.php?page=10 // the blog page is served up correctly
Uncommenting the following line in /etc/apache2/httpd.conf fixed the problem for me:
LoadModule php5_module libexec/apache2/libphp5.so
You could try adding this to your conf or htaccess:
AddType application/x-httpd-php .php
I know that this was asked a long time ago, but I just encountered this problem so I thought I'd post what the cause was for me.
Make sure that you don't have...
AddHandler application/x-httpd-php5 .php
...in BOTH your .htaccess file and your httpd.conf file. Check your .htaccess file, comment it out, restart Apache, and try again. That is most likely your problem since Apache renders php for some sites but not others. It has to be at the directory level, which would point to a .htaccess file setting.
I stumbled upon this problem after upgrading php to 5.5 and reinstalling apache.
Finally,this fixed it, in case someone else needs it.
apt-get install libapache2-mod-php5
(here's the answer)
I want to start learning php, I install apache 2.2 and I want to run my first.php file, I look for www folder in the installation folder of ApacheSoftwareFoundation but I couldn't find it.
here's the files in the apache
I tried to put my php file in htdocs but it doesn't work , can some one help ?
Edit
Doesn't work means when I make http:localhost/first.php , returns Unable to connect
Now the apache is running, when I open htt'://localhost/
returns "it works"
but when I open any php file, it opens as-is ?!
You'll need to check a couple of things...
Make sure the Web Server is running ,either the service
or the program, is running and that you have the correctly configured the Virtual Directories.
If the web server just outputs the
content of the .php file, it could
mean that you don't have mod_php
installed. Meaning the server does
not have the Mime type registered so
it will just try to treat it as a
text file ...
And as your on windows you might consider using something like XAMPP. It gives you a Full Working AMP (Apache Mysql Php) Stack with one install and a easy control manager to start/stop the servers. Other wise do a couple of Google searches on how to install the php module for your Web Server on Windows
Update
To start the server try executing the executable bin/httpd.exe .
Now the apache is running, when I open
http://localhost/ returns "it works"
but when I open any php file, it opens
as-is ?!
A default installation of Apache on windows does not include the necessary modules to run PHP. After installing Apache, you must either:
Install PHP separately and follow the instructions described here to configure Apache to use the installed version of PHP to serve .php files. I've been through this and took me hours to get every thing to work.
Recommended for you: uninstall Apache; install WAMP instead.
if you look in your httpd.conf file you will find the default root directory, it doesnt have to be called www. It is the htdocs by default.
error 500 covers a whole host of things. from compile error, to permissions.
Have you put a simple file of
<?php
echo "test";
?>
As your test php page to rule out other issues?
You need to:
Construct your URI correctly: http://localhost/first.php (with the //)
Ensure that Apache is running
all files in htdocs can be referenced from outside
Just put a basic file named index.php
and visit site http://localhost/
In general type in http://localhost/filename
You say that you get a connection error when you try to go to your webpage. Since it looks like you're using Windows Vista or 7, make sure you're running Apache as an administrator; it can't bind to port 80 otherwise. Also check that other programs like Skype aren't binding to port 80. If you still can't find the problem, check the error log. (logs/error.log by default I think)
The problem is that Apache was installed but not started
If you are using xampp start it and then start apache through control panel
for others look for similar instruction
I am learning how to code in PHP and MySQL and I am running into trouble with my HTML calling up PHP. The code looks like:
<form method="post" action="report.php">
When I ran the PHP and HTML on web server (hosted by GoDaddy), the code worked fine.
However, now I am running on a local server (using Apache and MySQL on my Mac Snow Leopard) and I am getting errors. When PHP gets called, a dialogue window pops up saying that "I have chosen to open report.php" and asking if I want to open it with a text editor or save it. I am using FireFox 3 and it's the same dialogue window that appears when opening up a file.
Do I need to do something in particular when I am using my local server? Do I need to save my files in a particular location?
I've spent a long time trying to fix this so any help would be greatly appreciated!
Have you opened /etc/apache2/httpd.conf and enabled the php5 module?
Should be able to uncomment this line:
LoadModule php5_module libexec/apache2/libphp5.so
This sounds like a server configuration issue. Apache doesn't know what to do with PHP files and is giving them back to the browser instead of executing them. This generally means PHP is not installed properly. Check in your httpd.conf file that the correct AddType directives have been added so that Apache knows about the PHP interpreter.
you need to open the file via the server not a directory so in your browser something like http://localhost/file.php
I'm trying to setup an Apache/PHP/Postgresql server locally on my machine. I'm using Windows vista business 32bit. I tried to install everything manually (one thing at a time, apache, postgresql and php (all the latest stable releases)) and after I get everything up and running.
Whenever I try to run a script on my machine, I get a "What do you want to do with the *.php file?" dialog. The dialog is the browser's open/save dialog
I'm just trying to get the output of phpinfo() to make sure everything is up and running...
I already tried to mess around a bit with the Apache conf file, but since I don't know much about what I'm doing, I reinstalled everything again and the problem is still there. I kinda get the feeling it must have something to do with the PHP thingy isn't correctly installed.
When i try to get the output of phpinfo as in:
<pre><?php
phpinfo();
?></pre>
I get the browser's "Open/Save" dialog for the *.php file.
You should have something like this in your httpd.conf file:
LoadModule php5_module "c:/php/php5apache2_2.dll"
AddType application/x-httpd-php .php
PHPIniDir "c:/php"
Make sure that's in place, and don't forget to restart apache!
In Windows, the default location for your conf file is C:\Program Files\Apache Group\Apache2\conf\httpd.conf
You can also have a look at the official page of PHP in the install section.
There is a closer link if you are on Windows.
And you can also use some precompiled installer for this like XAMMP and install Postgres after all is set up and running with the web server and php.
are you on Windows?
I use Wamp server, which is an excellent way of getting Apache, MySQL and PHP installed and configured without any hassle on Windows.
If you want to use Postgres instead, provided that you've got it installed separately it will work fine. (one great thing you can do with Wamp is add and remove PHP extensions via a GUI pretty much on-the-fly, and pgsql is one of them).
Maybe somebody can help, but you'd be much better off if you'd provide some relevant details.
What sort of system are you using? Be specific.
What do you mean by "everything up and running"?
What are you doing when you "try to run a script"?
What installation procedures did you use? (If you were following them off a script or how-to, we at least need to know where to find the script or how-to.)
We don't automatically know these things. What seems obvious to you may not be clear to us, and what seems irrelevant to you may turn out to be crucial.
In httpd.conf, make sure the PHP module is being loaded and that that line isn't commented out. (Comments in httpd.conf starts with #.)
Also what OS are you running?
I had the same problem, You need to configure apache and add the php module...
e.g I compiled the php from source as well as the apache. After doing so I then copied the libphp5.so from php/lib dir in to the apache/modules dir. Than you have to add php in the http.conf
LoadModule php5_module modules/libphp5.so
AddHandler php5-script php
you can then restart apache....it's not the most elegant of solutions but it works.