I'm yet a newbie to PHP development, so far I used NetBeans for the job. Unfortunately NetBeans is not the best IDE, and it is unreasonably slow on my Mac. I'd like to use Eclipse PDT for PHP, as I know and like Eclipse a lot better (I'm coming from Java).
But I cannot set up a server in Eclipse... All docs and topics just showed ppl saving files in the htdocs folder of an external server (such as MAMP or XAMPP). As I don't need a database, I just want to use PHP's built-in server instead of installing and running a heawyweight app in vain.
I'd like to reproduce the only really good thing in NetBeans: I just click on the Run button, and I see the result in the Browser immediately. How do you set that up?
Even if I am a bit late to help you, I want to write down my solution, cause I've faced the same problem today.
I think the only chance is to start the php built-in webserver manually. Open a terminal in the desired root directory and start the webserver with
php -S localhost:8000
Then you can add a new server with Base URL: http://localhost:8000 and the choosen document root and you'll have the same functionality like in Netbeans.
Put together this hackety-hack-hack to make this work (even works with xdebug remote debugging if you set it up!!!).
UPDATE: one caveat with this solution is when you terminate the running CLI in Eclipse, it's terminating the wrapper script, not the php server directly. I've added some trapping and forawding of signals to child (php server) process. Works in OSX.
Overview:
Here's the bash script php5.6-server
:
#!/bin/bash
_sigterm() {
echo "Caught SIGTERM signal!"
kill -2 "$child"
}
_sigint() {
echo "Caught SIGINT signal!"
kill -14 "$child"
}
if [ $1 = "-v" ]; then
#This is needed for when eclipse trys to detect php version
/path/to/php -v
else
trap _sigterm SIGTERM
trap _sigint SIGINT
# This is why your router file needs to be in the doc root
ROUTER=${@: -1}
DIR=$(dirname $ROUTER)
/path/to/php -S localhost:8000 -t $DIR $ROUTER
child=$!
wait "$child"
fi
Here's a simple router.php
just to get it working:
<?php
// router.php
if (preg_match('/\.(?:png|jpg|jpeg|gif)$/', $_SERVER["REQUEST_URI"])) {
return false; // serve the requested resource as-is.
} else {
echo "<p>Welcome to PHP</p>";
}
Now in Eclipse go to Eclipse->Preferences->PHP->PHP Executables
and add a new server:
And that should be it. Now create a PHP CLI Run configurations using the wrapper executable as 'Alternate PHP' and for the php file specify the route file:
Then Run as CLI!!! A PHP server should now be listening on port 8000 on your localhost. I suspect this method may also work for HHVM's Proxygen server.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With