I recently installed apache2 and Mysql on my RaspberryPi, I also setup FTP so I can edit my Files on my PC and upload them directly to the webserver.
If I now connect to my server vis it's IP-Address I can see the index.html, but as soon as I try to open a *.php file it shows the content of said file instead of interpreting it.
Are there any common mistakes that could make this happen?
Thanks for your help
This kind of errors mainly happen 3 reason
You may not be installed php
if you have installed php, you have not configured with apache
Check your php file having opening php tag <?php and closing php tag ?>
The same thing can happen if you have short php tags disabled. If it is disabled - all code that starts with <?..., <?=... will be printed on the screen just as simple text. Everything can be checked very easy: just create some php file and add <?php echo phpinfo() ?>. If browser will show php info - than problem is really in disabled short pho tags.
In that case you can simple enable that in php.ini with the directive short_open_tag=On (not recommended, however).
This is from php.ini file:
; This directive determines whether or not PHP will recognize code between
; <? and ?> tags as PHP source which should be processed as such. It's been
; recommended for several years that you not use the short tag "short cut" and
; instead to use the full <?php and ?> tag combination. With the wide spread use
; of XML and use of these tags by other languages, the server can become easily
; confused and end up parsing the wrong code in the wrong context. But because
; this short cut has been a feature for such a long time, it's currently still
; supported for backwards compatibility, but we recommend you don't use them.
; Default Value: On
; Development Value: Off
; Production Value: Off
; http://php.net/short-open-tag
short_open_tag = On
Your HTTP's response header should have "Content-Type:text/html". Have you checked that?
You don't have PHP configured to interpret php files within Apache or the PHP module is not known to Apache.
apt-get install libapache2-mod-php5
or
apt-get install php5
in apache.conf (or similiar) add line like:
LoadModule php5_module modules/libphp5.so
<FilesMatch "\.ph(p[2-6]?|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>
see http://www.php.net/manual/en/install.unix.apache2.php
Install php and any web server
http://www.apachefriends.org/en/xampp.html
download and install and goto C:/xampp/htdocs
make directory of your project and in browser type localhost/your_directory_name
Related
I use OS win10, xampp ( xampp manager already run and apache too) localhost and phpadmin run well. but when I write coding phpinfo.php like this coding
<?php
phpinfo();
?php
in chrome will show same like that coding.
But if I add HTML format then in chrome will blank or not show any
it happens with coding
<HTML><BODY> <?php echo "Hello World!" ?> </BODY></HTML>
I already put there C:\xampp\htdocs but still don't show any.
if I write code without html
<?php Echo " Hello World ! " ?>
then chrome show all script php code in browser.
is anyone can help me ? thanks a lot
Sounds like there is something wrong with your configuration, here's a few things you can check:
Make sure that PHP is installed and running correctly. This may sound silly, but you never know. An easy way to check is to run php -v from a command line and see if returns version information or any errors.
Make sure that the PHP module is listed and uncommented inside of your Apache's httpd.conf This should be something like LoadModule php5_module "c:/php/php5apache2_2.dll" in the file. Search for LoadModule php, and make sure that there is no comment (;) in front of it.
Make sure that the http.conf file has the PHP MIME type in it. This should be something like AddType application/x-httpd-php .php. This tells Apache to run .php files as PHP. Search for AddType, and then make sure there is an entry for PHP, and that it is uncommented.
Make sure your file has the .php extension on it, or whichever extension specified in the MIME definition in point #3, otherwise it will not be executed as PHP.
Make sure you are not using short tags in the PHP file (<?), these are deprecated not enabled on all servers by default. Use <?php instead (or enable short tags in your php.ini whith short_open_tag=On if you have code that relies on them).
Make sure you are accessing your file over your webserver using an URL like http://localhost/file.php not via local file access file://localhost/www/file.php
And lastly check the PHP manual for further setup tips.
Source: Here
I am having trouble getting my PHP to work for my Apache server. I am running Oracle Linux, and used yum install php + yum install httpd to get my PHP and Apache. I have scoured the internet and done a couple of things:
Firstly, I have gone into my httpd.conf file and added LoadModule php5_module modules/libphp5.so. I have chosen to use the one in my php.conf file, which is the exact same one. Furthermore, I have done AddType application/x-http-php .php, so now my .php files are loading fine.
Secondly, I have tried to run my Apache server, and it works fine. It displays my index.html file, which I set with DirectoryIndex. However, when I tried to put php code into it, it got automatically commented out, which I assume is because I haven't set it to properly execute on the server side.
Now, with all that said, I am wondering what else I may be missing. I have two set-ups, one where I have a .php file, and one where the php is inline with the html.
index.html
<!DOCTYPE html>
<body>
<?php echo "Hello everybody."; ?>
</body>
</html>
index.php
<?php phpinfo(); ?>
The index.php file loads fine, but the index.html doesn't run the php code. How do I get the inlined version of php to work?
Note: I have set-up my Mac OS to work fine with .php files, but it is also having trouble with inline php within an Html file. What am I missing?
SOLUTION: Html files themselves cannot include php. Instead, the file must be a .php extension, and within a .php file, you can have text, html, and JavaScript.
I do not think .html files are run through php at all so the <? ... ?> is treated as a normal tag which is invisible.
Change the extension to .php.
Php can contain html.
Edit:
There exists an option to configure for example Apache to parse html files as if they are php if you for some reason cannot or do not want to use php endings.
This, in my opinion, is not a good solution as it hides the fact that the page is dynamic to a future maintainer.
There is a similar question which has a similar problem:
PHP code is not being executed, instead code shows on the page
You might want to check out points 2 to 5 in the accepted answer:
LoadModule (It seems, that you have configured that properly)
Set Apache to run PHP files (this is the third point, and it seems that
you didn't configure that). Add the following line to your httpd.conf file: AddType application/x-httpd-php .php
Make sure, that you have the file ending with the .php extension (after you have configured Apache to run PHP files, see the previous point)
Change your code to use the long PHP opening tag (<?php instead of just <?)
You need to set short_open_tag = On in your php.ini file
I just installed XAMPP 1.8.1 and have restarted my computer, started running Apache and MySQL, and created a test file in a test folder in my htdocs directory under XAMPP.
When I go to xampp/index.php, their page comes up fine. But my test file only returns the actual characters in my PHP file in the "Response" tab in firebug, but a completely blank white screen in the window. The file is definitely .php extension - can anyone help?
The crazy thing is, I had this working 6 months ago just fine and have just gotten back to it on a new install.
I think you might be using short tag <? ?> or <?= ?> instead of <?php ?>.
Check your php.ini. It locates at \path\to\xampp\php\php.ini. The short_open_tag should be On.
; Allow the <? tag. Otherwise, only <?php and <script> tags are recognized.
; NOTE: Using short tags should be avoided when developing applications or
; libraries that are meant for redistribution, or deployment on PHP
; servers which are not under your control, because short tags may not
; be supported on the target server. For portable,redistributable code, be sure not to use short tags.
short_open_tag = On
I have an Apache server running PHP-5.3.0 for Windows. For the creation of pdf files, I need to activate the pre-bundled pdf library (referred here) in my php by editing the configuration file. How can I do this?
Or is there any other way to enable pdf creation?
Go to PHP's root directory > php.ini. Ctrl+F 'extension=php_pdflib.dll' and remove the semicolon (;) at the start of the line. Then restart Apache. If the semicolon isn't there, then it should already be activated. If there isn't any results from the Ctrl+F, it likely means you don't have it installed. You could try adding 'extension=php_pdflib.dll' (anywhere will do).
You can use a small file to test whether the library is loaded, just write in it:
<?php phpinfo();
Watch for php.ini in the output of this script, and add the following line to the file (you may need additional privileges to do that, right click your editor -> Run as Administrator):
extension=php_pdflib.dll
Restart apache, and check that pdf has been installed by checking the aforementioned phpinfo file.
Unless you're doing really advanced PDF stuff (and you need the non-free version of php-pdf for that), I can really recommend Prince XML. It converts XML and HTML into PDF and adds additional CSS properties, like page dimensions and numbers, PDF bookmarks and the like. Their documentation is better in demonstrating that than any of their marketing pages.
I solved it using TCPDF.. Its easy to handle. No need to edit php.ini.
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.