PHP on local files? - php

I don't have anything extra installed on my computer. Whenever I try to include one local PHP file on another, nothing happens. My question is if it should be working, or if I have to have some kind of server for it to work?

Well, you obviously need a server for a server side language... Don't you think?
Have a look at PHP servers such as Apache, or install an all-in-one such as XAMPP or WAMP.
At the very least, you need to install PHP and run it from the command line.

Related

I had XAMPP on my device but I have to uninstall it now my project does not run on localhost

XAMPP has some error about ports I uninstall it but did not back up any information and now my project does not run on local host is there any way for me to restore my old project or I have to do it again on new XAMPP? another problem is after reinstalling XAMPP windows do not know PHP what should I do?
by the way I am a very beginner in this :)))
So, I will try to explain this:
Websites (i.e. with PHP) need a webserver. For example when you go to stackoverflow.com, you automatically call a webserver who then compiles the PHP scripts on the server to HTML code.
This principe does also apply to your local installation.
When you call localhost, you basically call yourself as the webserver. XAMPP is a tool that can "simulate" a webserver on your PC, thats why PHP sites do not work without it, because your browser doesn't know what to do with PHP code, it only understands HTML.
If you install XAMPP again you should be able to get it running.
If you have any questions/problems with the XAMPP installation, feel free to ask again.

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!

How to serve a PHP file in Windows without XAMPP?

The situation is simple: I have a PHP file and I want to serve it on my localhost. I already have MySQL set up and don't want to install XAMPP or other bulky packages which come with their own MySQL or any other thing such as that.
I tried many Node.js ways to serve a PHP file but none worked for me.
Please, I just have a file and want to "run" it. How can I do that?
Unfortunately, if you want to run a "server-side" code (in your case PHP) in your Windows computer, you have to use a web server that simulate for you it.
XAMPP (or WAMP) enables localhost port to receive connections from yourself and it is a smart way to try in "local" your code.
If you want to run PHP but you don't want to install XAMPP, then you can install a linux distribution and run "apache HTTP server" that is already installed in most distributions. But in every case you need a tool to simulate the "server-side" part.
First of all nodeJS means nodeJavaScript. So it will not support php with mystery magical things.
You could only install Apache server and mySQL. Then you don´t need any XAMPP and the tools it brings with it.
Try to install Apache standalone.
Not sure if this works but should be no problem.
But all in all i would recommend you to use XAMPP

do we need a "local server" like tomcat to use phpmyadmin?

I already have mysql installed, but I have not installed anything else that simulates a server on my computer.
Is it possible to install and use phpmyadmin without having a local server running on my computer?
not possible, you need a webserver to deliver the web-page to a browser
You'll need a webserver, see the documentation if in doubt: http://www.phpmyadmin.net/documentation/
You need some webserver which can serve static files and execute PHP scripts to use phpMyAdmin.
If you don´t want to install a web-server and php, you can install for example MySQL Workbench to manage just mysql.
For phpmyadmin you will need a web-server.
Actually you have to install servers like WAMP, XAMP or TOMCAT. They deplye the admin site for phymyadmin. So if you don't install an application on your pc, how would you use it, untill and unless you are using on another server.

Working with PHP offline

Is there a tool or extension for a browser to working with PHP offline? I read about you need to install an Apache server.
Is there an easier way to view offline in browser to see how the PHP code executes?
XAMPP sets up a local install of MySQL, PHP, and Apache that you can develop on.
In Windows, install XAMPP or WAMP
Which are Windows Apache Mysql and Php bundles
In Linux install LAMP
Which is a Linux Apache Mysql and Php bundle
Both of which could help
Nope, simpler than xampp is not possible.
This won't be much use to you now, but there has been recent talk (and submission of code) of providing a built-in web server into PHP itself.
See the RFC at https://wiki.php.net/rfc/builtinwebserver
You could then write your script (e.g. app.php), execute php -S localhost:8000 to start the web server and then see the results in your browser at http://localhost:8000/app.php.
In the mean time, you can install Apache/PHP/MySQL/etc. on your local box, as the other answers have suggested, either manually or with a package like XAMPP.
No. PHP code must be processed by a PHP engine, and the easiest way to do so in a web environment is to use a web server. It does not need to be httpd, but it must be something.
if you are on a Mac, you have Apache installed already. the additional instructions you will need to add PHP and MySQL database server can be found here http://www.entropy.ch/software/macosx/
if you are using Windows, XAMPP is a self contained Apache/MySQL/PHP environment that runs as a stand alone application.
that should get you started. good luck

Categories