Running php script without web Server - php

I was used eclipse as my ide and I have test.php. I want to run and debug that php script in eclipse. How I do it ?

You can run PHP scripts without a web server. PHP doesn't have anything to do with web servers.
You need to download PHP, of course. And then you can configure Eclipse to run your scripts in the command line. See
http://www.php.net/manual/en/features.commandline.usage.php
for command line usage of PHP

You can turn your computer into a webserver very easily with xampp.
http://www.apachefriends.org/en/xampp.html

So, you need to setup local webserver and run it.
for example Denwer (type you name and , mail for download) - this is build of appach server for local develop. (P.S. try to find there on your lang.)
By default Denwer setups to the C:\WebServers\
And yor site should be in C:\WebServers\home\sitename.ru\www
Then you should run servise and type in browser smt like sitename.ru
And Denwer setup MySql DB on you system

Microsoft Windows 7, Eclipse Mars.2 (4.5.2), PHP 7.0.4 (stand-alone install in C:\php), Eclipse PDT for PHP extension 3.7.0
Current Eclipse documentation is not clear, but newer PHP versions have the PHP -S option, to run a simple web server test environment. I succeeded with the following setup, and note this allows for a top-level/root URL to your project. Eclipse wants to use your Workspace folder as the web root, so if using subfolders in your URL is acceptable, then configuration is easier.
In Eclipse:
1. Run > External Tools Configuration
Create a new Program.
Location: C:\php\php.exe (your PHP installation)
Working Directory: ${workspace_loc:/myproject} (your project folder)
Arguments: -S localhost:8080 (change as desired)
On the Common tab at the bottom, almost hidden, there is a "Launch in background" option that is checked by default. Unchecking this did not work for me, so remember that Eclipse will launch a PHP processes in the background, so check Windows Task Manager.
Run this External Program to start the PHP web server.
In a web browser
2. Verify you can open your projects default page in a web browser.
Example: http://localhost:8080/
In Eclipse
3. Run > Run Configurations
Create new PHP Web Application. Name configuration, e.g. myproject-config.
Create a new Server. Name server, e.g. myproject-server.
Base URL: http://localhost:8000 (Match your PHP web server setting)
Leave all other Server settings blank.
Back on the Configuration, you must select a file, e.g. /index.php.
URL: Uncheck Auto Generate
URL: Make file name/path match above, and you can add parameters.
Apply your changes.
Test
Now you can select Run, or in the PHP Explorer you can select your project or default file and click the Run toolbar button.
Note that you will need separate Configurations for each PHP file.
Maybe not the easiest or greatest solution, but it allows you to stay in Eclipse.

Related

With an HTML form, how can I start debugging the action PHP script with proper GET/POST data? (using PhpStorm and XAMPP)

I'm using PhpStorm 2021.1.3 as an IDE with XAMPP as a PHP7.4 engine. I have installed Xdebug 2.9.2, and it works properly since I can start the debugger on specific PHP scripts.
My issue is that I have an HTML form in a PHP webpage (let's call it "mainpage.php", which sends its data to another PHP file (let's call it "analyze.php").
The issue is that if I start the debugger on that other PHP file ("analyze.php"), it doesn't get the GET/POST data, since I didn't use the form at all. Is there a way to pass the GET/POST data when launching the debugger?
I've looked into the run configurations, but they only seem to mention PHP options, and not GET/POST data.
I tried using the HTTP Request, but the only examples I've seen use actual web hosts and production environments, as far as I could tell. I only have this XAMPP development environment at the moment. My PHP files are not in the www folder of XAMPP, since PhpStorm seemed to have no problem so far copying the file at the right place when needed.
Any idea where I should look for?
Ok, thanks to #waterloomatt I managed to find a workaround. The crux of the issue in my case is this PhpStorm bug: https://youtrack.jetbrains.com/issue/WI-54542 Therefore, this answer will probably be irrelevant once this bug is resolved.
Here's the solution on Linux :
Step 1 : Create a server on PhpStorm.
In File->Settings->PHP->Servers, click on the "+" symbol to add a new server. Fill the server infos.
The port is 63342, which is the port PhpStorm uses for running the code. Note that I gave this server the name "localhost63342". This detail is important.
Step 2 : Launch XAMPP normally.
Launch XAMPP as you do normally. The issue is with PhpStorm, not XAMPP.
Step 3 : Before launching PhpStorm, add an environment variable
Open a command prompt, and run the following command:
export PHP_IDE_CONFIG=serverName=localhost63342
Note the server name, which is the same as the name of the server we defined in PhpStorm.
I could make that environment variable more permanent, but since it is a soon-to-be-resolved PhpStorm bug, I think that'll do.
Step 4 : In the same command prompt, launch PhpStorm
We defined an environment variable, which is valid as long as the command prompt remains open. We then can launch PhpStorm with this command prompt. In my case, with the following command:
./$HOME/phpstorm/PhpStorm-203.7148.74/bin/phpstorm.sh
Step 5 : Launch a debugging session
My Chrome browser already has the "Xdebug helper" extension: https://chrome.google.com/webstore/detail/xdebug-helper/eadndfjplgieldjbigjakmdgkmoaaaoc?hl=en That extension is already configured to use the PHPSTORM IDE Key, as shown here:
In PhpStorm, I put a breakpoint where I want in my code. I click the button to make PhpStorm listen for PHP Debug Connections. I then launch the code from the page I want using the launcher button (Chrome is Alt+F2 on my computer).
The code runs normally, and I can navigate from page to page. When, on a specific page, the code hits a PHP breakpoints, the code is suspended, and I can execute it line by line using PhpStorm's debugger. Since I filled the forms to get to this page, I get the GET/POST data.
It's not as direct as a PHP HTTP Request I suppose, but it works.

PHP on Windows IIS with coreserver

i have the following server setup:
a DC with DNS [works perfect]
a webserver with GUI [works perfect]
a webserver Core [stuck at PHP installation]
I'm trying to install PHP on the core server. I have a simple site with a php file that shows the phpinfo();. From the GUI webserver I was able to manage to use the gui to do a lot of stuff, but now i'm stuck.
What did i do:
on the core server, i put a php folder and eddited the ini file
On the IIS of the GUI, i manage the Core server and added the module mapping for php. I could not browse (did not get the button witht the 3 points to browse) because its managing the coreserver so i just added the path manualy c:\php\php-cgi.exe
the next step would be to add that php path to the environment variables (path). I did this with powershell. When showing the $env:path, the path of php is added. Also after a reboot, it's still added
when following guides, now i should be able to let the cmd tool tell me what version of php i'm running. I tried php -v, php -m and php --version in command line and in terminal. What gave no errors, but also no other output.
Can someone help me debug this one? The core makes it harder for me because when i did this on a gui, it worked. But then i changed settings like the path environment in gui screens.
Thank you for your time!

which server to install for phpEclipse and how to do it?

I know this is a newbie question, but i want to study php. i have phpeclipse and its running well, the problem is when i run a simple html file with the default server the page says cant display this page and thats it. i dont know if i need to install a new server or is there something wrong with the server configurations. ive tried installing tomcat on my computer but i cant see it under windows->preferences->server->runtime enviroments->add. iv also tried under the same page to fetch geronimo v2.2 and 3.0 and the dependencies were wernt satisfied. iv also tried the repository for zend debugger. what do i need to do in order to compile and see php and html pages with php eclipse?
You don't need to compile PHP.
Depending on your operating system and PHP version there are a few options.
As of PHP 5.4+ you can run your application using PHP's built in server, on the command line, if you cd into your website root directory (i.e. where the index file is) and then run the following
php -S localhost:8989
Then if you navigate to http://localhost:8989 in your browser you should see your application.
If you are unable to run the inbuilt web server, you need to look at Apache2. Most PHP websites run inside the Apache 2 web server. You will generally need a *AMP (WAMP/LAMP) environment.
L/W (Linux / Windows)
A pache (Web server)
M ySQL (Database)
P HP
Hope this is enough of a pointer ;)

Running continuous PHP (script) background processes on a WAMP server

I got the 140dev Twitter framework (which uses the Twitter phirehose) manually
running (via the webbrowser on my local wamp server), but I can't
figure out how to run both get_tweets.php and parse_tweets.php as a
background process like with SSH commands:
nohup php script.php > /dev/null &
Some of you started using (the Windows equivalent of) cronjobs, but
this isn't the right way to go. I think this is because of creating
multiple connection (or re-connections) to the Twitter streaming phirehose isn't allowed?
How can I run both PHP scripts (get_tweets.php and parse_tweets.php)
as a background process on my local WAMP server (and later on a VPS)?
Just to clearify:
I am using a WAMP server (first to test a little bit and later to
run it on a VPS)
Using LAMP or any *nix server/system isn't an option (due to time,
experience and lack of skills)
I have searched for solutions (on google and stackoverflow), but they are either not working or not clear enough for me (I am new to this)
Thank you in advance.
Find the php/bin folder where the php.exe is located. Copy the folder path and add it to your PATH environment variable (Follow this for instance to edit your PATH variable.
Once this is done, you'll be able to execute php in the command line from anywhere. Just start php script.php with a command line in the right folder and it should work. There might be some configuration to make so that the php in command line uses WAMP's php.ini.

How to set up/view PHP server pages in Eclipse with the PDT plugin (for php)

I am trying to set up a PHP server on my localhost to run with the Eclipse PDT.
I want to be able to view the PHP site I am developing on something like http://localhost/MySite/index.php so that I can Run it straight from Eclipse.
I am using IIS 7.5 (windows 7 home premium) for the PHP server.
So far I have followed these instructions, but have not been able to get it to work:
Install CGI option in Windows Features
Install IIS Manager in Windows Features (so I can run inetmgr.exe)
Download the NTS-version of php and extract the zip to C:/php
Rename php.ini-development to php.ini and set the extension_dir variable
Run inetmgr and create a new website to run PHP applications (I removed the DefaultSite):
Site Name: My Site
Physical Directory C:/dev/MySite
Application Pool: DefaultAppPool
Bindings:
Host:
IP Address: All Unasigned
Port: 80
In inetmgr: Click on handler mappings and add a new Module Mapping:
Request Path: *.php
Module: FastCGIModule
Executable: C:/php/php-cgi.exe
Now I have many problems:
In IIS Manager, when I click Edit Site > Test Settings, there is a yellow exclamation-mark warning: Authorization: Cannot verify access to path (C:/dev/MySite):
The server is configured to use pass-through authentication with a built-in account to access the specified physical path. However, IIS Manager cannot verify whether the built-in account has access. Make sure that the application pool identity has Read access to the physical path. If this server is joined to a domain, and the application pool identity is NetworkService or LocalSystem, verify that \$ has Read access to the physical path. Then test these settings again.
When I try to load any .php file directly from the webroot (C:/dev/MySite) it displays as plain-text in my web browser
When I try to Run my project in Eclipse, it goes to http://localhost/MySite/index.php and there is a 404 Error: Website Not Found
When I go to http://localhost/ in my web browser, I also get a 404 Error.
If you download PHP 5.4.x you will be able to use the built-in web server for all of your development needs.
In your php folder, you would run:
php -S localhost:3030
Now you will be able to browse to http://localhost:3030/index.php
If you were using the Aptana IDE (or anything comparable), you would set this up like so:
Your run configuration would be:
I don't personally use Aptana (I did a few years ago); however, I thought it would be interesting to try this to find out if the integration would be seamless or not. I have to say, I am pretty impressed at how Aptana gets out of your way so you can do just about whatever you want.
Finally, if you are wondering about the "$HOME/local/php/versions" listed in my "Start command", I drive multiple PHP versions with a tool called php-version. Please be aware that this tool targets Linux/Mac users; however, if more people are interested, I may do a windows/powershell port (NOTE: I am the author).
I'm afraid I don't have an answer to you're question, but I wanted to share...
I never was a fan of running PHP on IIS or Apache. So I built a portable, no-install-required copy of nginx that I could move around with me or use on my Windows machines. (Just download the flavors of PHP, Nginx, and MySQL you want and start it). One of the reasons is that most production sites run nginx anyway, so this way I'm closer to what my server actually uses (unless you are on "shared-hosting" which still uses the Apache).
Second, I'm not sure why you need to "run" it from Eclipse. When you write PHP you usually are dealing with a lot of variables to get pages setup. I would say you need to worry more about adding Unit Tests to make sure things work right, and using a browser like Firefox (with firebug) for testing any requests you might be making. Things like AJAX, or dealing with session cookies often require more control than what Eclipse can give you.
Bottom line, I'm not sure why you think you need to do this.

Categories