Not able to open the .php file in browser - php

I am trying to open .php file in any browser but it is being downloaded..
What is the problem? somebody plz help me..
When i type localhost/hel.php in address bar of browser it shows me download dialog.
Thanks in advance

The webserver needs to know that the requested file is to be executed using the PHP interpreter. If the webserver is not installed, running or configured, the file will be downloaded very much the same as a .zip or .mp3 file would.
It is not clear what server you use, if any, so I will not post particular instructions unless you clarify.
[EDIT]
Alright, for Apache, it's quite simple. I assume you're using a UNIX-like OS, since most popular Windows packages, such as XAMPP or WAMP, come with PHP + Apache already configured and ready to go.
Apart from Apache and PHP, you also need to install mod_php, which is an Apache extension that allows the webserver to use the PHP interpreter to run PHP files. Use your favourite package manager and install the missing package. Its exact name varies between Linux distributions, so I cannot tell you which one to look for exactly, but it will usually be something along the lines of "libapache2-mod-php".
Once that is installed, go to your php.ini file and make sure the module is enabled. After restarting the webserver, PHP files should be working as expected.

Maybe this is the answer? apache2 on ubuntu - php files downloading
For second question from your comment:
Do you include
Include /etc/phpmyadmin/apache.conf
in
/etc/apache2/apache2.conf
and restart apache with
sudo service apache2 restart
?

Related

How do I run this code in my browser from the VS Code terminal? [duplicate]

Could anyone please tell me how to run a php file locally on my system.
Currently I am using a server to run files.
I know both php & Apache to be installed.
I need to see out put of this program, for example:
<?php
$a=5;
$b=10;
$c=$a+$b;
print $c;
?>
Can you please tell how I can run these files of if I need anything more.
php have a easy way to run a light server:
first cd into php file directory, then
php -S 127.0.0.1:8000
then you can run php
You have to run a web server (e.g. Apache) and browse to your localhost, mostly likely on port 80.
What you really ought to do is install an all-in-one package like XAMPP, it bundles Apache, MySQL PHP, and Perl (if you were so inclined) as well as a few other tools that work with Apache and MySQL - plus it's cross platform (that's what the 'X' in 'XAMPP' stands for).
Once you install XAMPP (and there is an installer, so it shouldn't be hard) open up the control panel for XAMPP and then click the "Start" button next to Apache - note that on applications that require a database, you'll also need to start MySQL (and you'll be able to interface with it through phpMyAdmin). Once you've started Apache, you can browse to http://localhost.
Again, regardless of whether or not you choose XAMPP (which I would recommend), you should just have to start Apache.
In short:
Install WAMP
Put this file to C:\wamp\www\ProjectName\filename.php
Go to browser: http://localhost/ProjectName/filename.php
I just put the content in the question in a file called test.php and ran php test.php.
(In the folder where the test.php is.)
$ php foo.php
15
If you have apache running, put your file in server folder for html files and then call it from web-browser (Like http://localhost/myfile.php ).
3 easy steps to run your PHP program is:
The easiest way is to install MAMP!
Do a 2-minute setup of MAMP.
Open the localhost server in your browser at the created port to see your program up and runing!

Adding a variable to httpd.conf file stops Apache from working

In my efforts to solve an OCI8 error, I've been led to believe it is the result of an improperly setup environment variable.
What I'm trying to do: Fix this apache environment headache, by adding variables to a certain file.
My actual problem is similar to this error from another StackOverflow user. To quote his answer to his problem:
Problem solved!
To put variables in Apache's Environment section you just have to add
them in /etc/sysconfig/apache2 file:
LD_LIBRARY_PATH=/path/to/oracle/lib.
Notably, the solution called for the modification of the file apache2.
However, I found no such apache2 file on my system.
What I've done so far:
I searched over the net, but the closest I could come up with is /etc/httpd/conf/httpd.conf file. Assuming the httpd.conf is apache2, according to this thread, I should add the variable to the end of the file, and it should work.
So I added export LD_LIBRARY_PATH=/u01/app/oracle/product/11.2.0/xe/lib at the very end of the file.
And... apache won't even start anymore.
My system:
It's a Fedora 19 server, with Oracle 11g, PHP 5.5.4, Apache 2.4.6, and PEAR 1.9.4. In addition to this, I have the OCI8 plug-in for PHP downloaded and enabled, and have downloaded MDB2 and the MDB2_Driver_oci8.
Apache starts automatically when I boot up my system, though if for some reason I need to stop, restart, or check its status, the command I use is systemctl start httpd.service, if it means anything.
Thanks. I've been pulling my hair out on this problem.
A few things (hopefully an answer is somewhere inside)
First off, I wouldn't do this on Fedora. Fedora is the testbed for RedHat Enterprise/CentOS and it changes frequently. Even if this is just for your testing purposes, you'll find better support if you install CentOS 6 instead. The environment is virtually identical, but CentOS is better supported because so many people use it to run their servers.
Second, it sounds like you want to run the OCI8 connector (there's a reason I plugged CentOS 6). CentOS has many good repos like Remi. If you install CentOS 6 you can use his repository. This is important because this will save you a LOT of headaches down the road. Once you have his repo installed, you can do this
yum install php-oci8
And that should configure Apache to run your OCI8 extension. It's really that simple.

How can I view a PHP file without having to upload it to my ftp?

This is probably embarrassing short-sighted or just completely wrong, but I've made a header.php and a footer.php file and then an index.php file that calls them. Is there a way to view that index.php file from my desktop?
Use local webserver stack like XAMPP
This will allow you to view PHP Pages without having to upload them to your Server
Use an Apache Server:
XAMPP - http://www.apachefriends.org/en/xampp.html
This will install MySQL, PHPMYADMIN, Apache, PHP on your computer, so you can just upload files to
C:\xampp\htdocs\
and browse to :
127.0.0.1 OR localhost
via a browser with Apache Service running.
^ Assumes you are on Windows.
Another assumption if you was on a linux box (Ubuntu For example)
http://www.howtoforge.com/ubuntu_lamp_for_newbies
Install a webserver with support for PHP on your desktop.
Apache is a good choice. There are bundles of Apache + PHP available for most operating systems.
You would need to install a web server/PHP stack on your desktop. You could looks at something like WAMP (for windows) or MAMP (for Mac) to do this. Or if you happen to be using Linux just install Apache and PHP directly on your machine.
If you are on windows use WAMP If you are on mac use MAMP. For linux use XAMPP Plus read this How Web Servers Work

How to install PHP curl extension on wamp server WIN XP?

I have WAMP SERVER,PHP 5.3.0 and Apache server 2.2.11 I want to download a suitable CURL lib version for it
I studied the sites and found that this installation will not be easy it may not work if the version is not suitable please help me with details also I found here:
http://in.answers.yahoo.com/question/index?qid=20090827212635AAWBwZj
http://www.ozzu.com/programming-forum/curl-issue-for-wamp-server-t100949.html
but I'm not sure to get the perfect result cause my version is different
also I have another problem if I can not install it in a good way will my wamp server and databases go wrong or not?
Are you running WAMPSERVER? If not, I would recommend doing so if you wouldn't miss your current WAMP environment -- it comes with CURL along with many other useful features.
Check it out here: http://www.wampserver.com/en/
open php.ini file and find this line
;extension=php_curl.dll
remove ;
extension=php_curl.dll
save file
...
still problem exists
then check for this file
php_curl.dll
in
{wamp}\bin\php\php5.x.x\ext\
if it's not there than download it from internet and paste it to there
Restart Apache.

php SOLR extension is not loaded in wamp

I am trying to configure SOLR on PHP and using WAMP.Added extension in php.ini also pasted the
php_solr.dll in the extension directory.
Unfortunately the extension details is not appearing in my php info.
I am just confused that may be I am missing any configuration step/
Thanks in advance.
If you are using Linux then go to /etc/php5/apache2/conf.d/. If you find another .ini then create a solr.ini file, add the following line and restart the Apache service.
extension=solr.so
See my blog post for more information.
Let me know if you need more help.
I couldn't get that plugin to work and ended up going for solr-php-client from http://code.google.com/p/solr-php-client/
It does everything you need it to and you can include_once it into your scripts and know that you can deploy them on a standard PHP installation.
Installing Solr on Windows with Wamp
Solr is a great tool for full-text searching and more, from Apache Software Foundation. Its based on Apache Lucene search library and extends it. In this post I will let you know how to install Solr on Windows and integrating it with WAMP. Integration with WAMP is not mandatory if you are not using it.
The esyest way to install solr on Windows is to use Solr installer from BitNami. This can be found here http://bitnami.com/stack/solr. Download the installer and run it with administrative rights. Try to keep the installation path simple something like “c:/solr/” will be appropriate.
It will also install an apache server so if you don’t have wamp or apache already install than its super easy, just go with the flow. If you already have wamp installed than make this apache listen on some available port other than 80 (where wamp apache is listening).
Once the setup is complete Solr will be available for use in port selected during setup (see no big deal). Now if you have wamp and you don’t want to have two apache services running do the following steps.
Enable proxy_module and proxy_http_module via wamp menu or directly from apache conf file.
Open httpd.conf file and add following line at the end of the file
Include "c:/solr/apache-solr/conf/solr.conf"
Note that the path here should be correctly pointing to the solr.conf file. Use the path where you installed the Solr.
Now restart the wamp apache via wamp menu. If it starts correctly than its cool, otherwise check if you have correctly enabled the said modules, and path to solr config file.
Now check http://localhost/solr/ this should show the dashboard for solr.
Remember the extra apache service we need to disable it so it does not start automatically as we don’t need it. So goto Control Panel > Administrative Tools > Services , double click “solrApache” service and change its “Startup Type” to “Manual”. Now it will not start once your system is restated.
Happy solr searching

Categories