How to enable PHP's built-in web server on wercker - php

I have setup my wercker.yml file with the following step midway:
- script:
name: Serve application
code: php -S localhost:8000 >> /dev/null &
That appears to run, however, in another step when I try cURL to http://localhost:8000 I get the following:
curl: (7) Failed to connect to localhost port 8000: Connection refused
It does it for all ports, not just 8000. Has anyone else managed to get PHP's in built server working in wercker, or open any ports?

Assuming you're using the wercker CLI and trying to set up a development pipeline, you need to use wercker dev with the --publish 8000 argument. This will forward the traffic from your host on port 8000 to the container on port 8000.
Also, if you're using boot2docker, you can't specify localhost, since boot2docker spins up a VM that runs docker. In that case you'll need to use your boot2docker IP, which you can find by running the boot2docker ip command.

Related

HTTP_Request2 GET error

I am trying to connect to my Amazon EC2 website from my PHP server hosted on Godaddy. So using HTTP_Request2, I use the following:
$request = new HTTP_Request2('http://XX.XX.XXX.XXX:3007/something/something', HTTP_Request2::METHOD_GET);
This returns the following:
Error: Unable to connect to tcp://XX.XX.XXX.XXX:3007. Error: Connection refused
Now I know the port on my Amazon server is open and works when using jQuery to connect to it from my own machine or even my Godaddy website. However when trying to do the same thing except with PHP, it isn't working. I have made sure that I have installed request2 package on my Godaddy server.
Found out the problem. The problem is GoDaddy doesn't allow using custom ports (such as 3007 port I was trying to use) with curl or request2. A workaround to use on another server you are trying to connect to (if you manage/own that server):
sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3000
was posted at https://stackoverflow.com/a/16573737/4553140

Persistent connection of websocket into live server

I have implement rachet websocket with codeigniter and it's working fine in localhost. This is a main server.php that we need to run from terminal / cmd
require __DIR__ . "/../vendor/autoload.php";
use Chat\Chat;
use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
$server = IoServer::factory(new HttpServer(new WsServer(new Chat)), 2000);
$server->run();
I run this file from cmd with following command
D:\wamp\www\my_project\api\application\third_party\Realtime\bin server.php
This command start socket and now any user access my site through browser then they are connect with socket and I can sent message to him. When I close terminal / cmd then socket close automatic.
Now my development is done and I upload all source on "openSuse" server. So my question is how I run above server.php file on live server ? (for example amazon ec2 OpenSuse server). because server don't have terminal / cmd.
Also this should run persistent so any time any user access my site they are connect to server and I will send him message.
I try many way but it's not working any how.
after installing haproxy i create confing file haproxy.cfg into /etc directory
In this file i have set
backend ws
server ws1 my_public_ip:2000
backend www
timeout server 30s
server www1 my_public_ip:80
Here port 2000 is websocket port and port 80 is my apache port
I also try with 127.0.0.1 but it gives following error
[ALERT] 293/101352 (2291) : Starting frontend public: cannot bind socket [0.0.0.0:80]
After skip this error i create supervisor.conf file in /etc/ directory and add rachet program as per your given link
Here in command i gave full path to server.php file
command = bash -c "ulimit -n 10000; exec /usr/bin/php /srv/www/htdocs/ci_chat/application/third_party/Realtime/bin/server.php"
But it gives me following error
Error: Another program is already listening on a port that one of our HTTP servers is configured to use. Shut this program down first before starting supervisord.
My apache run on port 80
pgsql run on 5432
Now i can not understand which service need to shutdown.

Telnet connection on localhost Refused

EDIT:
I want to telnet into my web server on localhost, and request my php file from command line:
I have:
1) cd'd into the directory I want to serve, namely "/www" (hello.php is here)
2) run a server at directory www: python -m SimpleHTTPServer
3) telnet localhost 80
but "connection is refused". what am I doing wrong?
You're probably trying to connect to a wrong port. Check with netstat -lntp which port is your http server listening on. The process will be listed as python/pid_number.
If you're using Linux then try this:
$ telnet localhost 80
GET /hello.php

Can't connect Websocket when using vagrant envirionment

I'm using Vagrant box using puphpet, the environment is PHP 5.5 + ubuntu 12.04 + apache + mysql. My Vagrant VM ip: 192.168.11.11, local machine hosts points to 192.168.11.11 reactphp.dev, and it works.
And, I'm using this code: https://github.com/muuknl/phprealtimechat to test websocket.
Then I visit reactphp.dev in my Chrome browser, and I start server script using: php bin/server.php, and after I type in the username I just got the error:
WebSocket connection to 'ws://192.168.11.11:2000/' failed: Error in connection establishment: net::ERR_CONNECTION_TIMED_OUT
It works well when I changed the websocket ip to `ws://127.0.0.1:2000/', but why it does not work if I change to my VM's ip address?
It's been a while I haven't used PuPHPet, but when I had troubles connecting through the port (minus port 22), I've had to issue the command sudo ufw disable in the vagrant machine.
If uwf isn't the managing firewall of your vm, try sudo service iptables stop, or sudo iptables -F.
Perhaps they've changed the behavior since then, but it's still good to try.
The SSH tunnel (over the opened port 22) might allow you to access the local port 2000, which is proxified over. The actual port 2000 of the VM might be limited due to firewall.
Try it, and tell me if this works. If not, I'll dig in deeper.

cURL couldn't connect to host, but it connects to my domain address

I am new to Linux. I had the php project in the Linux server. I am using the cURL command in my php page to access Google, but it says it couldn't access the host.
From the command line, I can ping the Google site, while cURL and Wget commands fail.
I had checked the firewall: selinux=disabled and selinuxtype=targeted.
Try this command from a terminal
telnet www.google.com 80
Do you get any output? Like Connected to www.google.com? If not, then the outgoing access to google.com on port 80 is blocked.
Ping uses the ICMP protocol. cURL (and telnet) uses TCP on port 80 or 443.

Categories