First thing, I could see out there has already solved questions around the problem.
PHP web socket unable to bind socket
Issue in setting the socket server
socket_bind(): unable to bind address [99] (Ubuntu on Amazon EC2)
and many other resources, all of them said that problem is in-used port or external IP,
etc.
But I could not get over it.
My server is running on CentOS 6.3 and using CPanel (it is the HP server https://www.hpcloud.com/).
The web socket demo source code what I get is on https://code.google.com/p/phpwebsocket/
My setting is
$master = WebSocket("127.0.0.1",4444); // even I tried with localhost, they worked same
Here is the step what I tried and the corresponding errors:
1/. I tried following commands to ensure a port which I was using is available to use
$ lsof|grep 4444
$ netstat -a -p -n
But I always got the error although this port 4444 is free
Warning: socket_bind(): unable to bind
address [98]: Address already in use in
/home/myapp/public_html/websocket/server.php on line 60
2/. The strange thing is when I checked the port 835 which was using by
crond 1621 root DEL REG 252,1 39835 /lib64/libpam.so.0.82.2.#prelink#.B1eyGx
atd 1633 root DEL REG 252,1 39835 /lib64/libpam.so.0.82.2.#prelink#.B1eyGx
The funny thing happened:
Then I ran the server.php on my terminal command shell
php /home/myapp/public_html/websocket/server.php
the error has gone, instead of it is
Server Started : 2013-08-16 03:19:54
Master socket : Resource id #4
Listening on : 127.0.0.1 port 835
I thought that it started working, but actually it did not, because when I open server.php by the browser with URL
http://mysite/server.php
The error is "permission denined"
Warning: socket_bind() [function.socket-bind]: unable to bind address
[13]: Permission denied in
/home/myapp/public_html/websocket/server.php on line 60
socket_bind() failed
Edited: About permission, I could open the client.html in same level directory with server.php without problem.
The folder code permission is 755 and user is not root.
All of my commands was implemented under root privilege
Any help is greatly appreciated :(
I would assume that the problem is that you are attempting to load the Websocket server in your webbrowser. Most likely, there are security settings for the apache user that does not allow your server to listen on uncommon ports.
CentOS usually ships with SELinux enabled by default. Part of CentOS Linux's security policies for Apache are that by default, Apache will only allow services access to recognized ports associated with HTTP (ie, port 80, 8080 etc).
With SELinux enabled, you could allow Apache to listen on tcp port 4444 by adding a rule to allow that inside SELinux using the 'semanage' command:
~$ semanage port -a -t http_port_t -p tcp 4444
Related
Apache24/conf/httpd.conf:
Port Listen 8080
I have set everything and tried port :80 and :8080, both doesn't work, what am I missing?
It worked properly now.
steps on how it worked
Legend: IPv4Address: 192.168.1.5 it should be different on your machine
cmd>ipconfig
copy IPv4Address
open Apache24/config/httpd.conf
line 59: Listen IPv4Address:8000
line 60: Listen 8000
line 218: ServerName IPv4Address:8000
save file
cmd> cd C:\Apache24\bin
cmd>./httpd for me httpd without ./httpd didn't work for some reason
refresh http://localhost:8000 or http://IPV4Address:8000 and it should work!
I think because I had run cmd>npm run dev ports 80 and 8080 were taken (although the server is offline now), luckily port 8000 is free.
Thanks #JamesYoung
I think you should check your computer process.
Below are the process check command
# for window
tasklist | findstr "httpd"
# for linux
ps -ef|grep httpd
Hello I'm newbie for symfony frame work.
currently using Symfony version 3.4.
I'm implementing websockets to my project using Gos Web Socket Bundle (https://github.com/GeniusesOfSymfony/WebSocketBundle) and documentation also.
after run this command
`php bin/console gos:websocket:server`
getting message like this.
`Failed to listen on "tcp://127.0.0.1:8080": An attempt was made to access a socket in a way forbidden by its access
permissions.`
in config.yml added this
`# Web Socket Configuration
gos_web_socket:
server:
port: 8080 #The port the socket server will listen on
host: 127.0.0.1 #The host ip to bind to`
If I changed port no 8080 to 80 I will get any error from command prompt but in browser it doesn't work. If I used 8080 websocket server is not running. Help me out! spent whole full day on this.
Without being a root (or via sudo) you are not allowed to listen to privileged ports (<1024).
As for the port 8080 check if there is another service already running on it:
lsof -i :8080
Have you tried selecting another port, for example, 8888?
Hope this helps...
I have downloaded PhpStorm and set all the required configuration. When I try to run the project on port 80, I get this error.
Failed to listen on localhost:80 (reason: Permission denied)
And when I try to use any other ports like 8080 ,I get this error.
Failed to listen on localhost:8080 (reason: Address already in use)
I have tried several different random ports. But I get this already in use error all the time.
I have xampp installed. And when I try to run the url in browser with port , it works fine. The problem is that it isn't working on PhpStorm.
I am stuck.
The errors description are very clear:
The error:
Failed to listen on localhost:80 (reason: Permission denied)
You really don't have permission to use this port; so you need to change your user or use sudo to run your application.
and the error:
Failed to listen on localhost:8080 (reason: Address already in use)
The address that you are trying to use localhost:8080 is already in use by other processes/software.
Normally, if you change the port will solve the problem: (eg. 9090).
But, if you want to know which program is using the port 80 in Unix (Mac OSX, Linux), you can use the lsof command:
To do this:
In the terminal, you need to use:
sudo lsof -i :80
That will result something like this:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
httpd 82 root 4u IPv6 0x763617bed21ecc33 0t0 TCP *:http (LISTEN)
httpd 226 _www 4u IPv6 0x763617bed21ecc33 0t0 TCP *:http (LISTEN)
On this result, we can see that the /usr/sbin/httpd is listening on port 80 on my machine, which is the Apache server.
To know the details of the process that is listening on port 80 you can use the ps command:
ps u PID_of_target_process
that will return a result similar to this:
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
root 82 0.0 0.0 2463324 4248 ?? Ss 9:48AM 0:00.93 /usr/sbin/httpd -D FOREGROUND
To kill the process by the PID you can use the kill command, like the following:
sudo kill -KILL PID_of_target_process
After you kill the process the port will be available again.
The PHPStorm / Intellij built-in web server listens on port 63342 by default.
https://confluence.jetbrains.com/display/PhpStorm/Using+the+Built-in+Webserver+in+PhpStorm
You can set the port in the Run/Debug Configurations under PHP Built-in Web Server:
Stop your Apache server from XAMPP.
Run your PHPStorm with ROOT privileges.
If running PHPStorm is showing your the same error saying Failed to listen on localhost:8080 (reason: Address already in use). The ports 80 is used by any other application. Try checking your used ports with a free tools out there. Stop the process using port 80 and try running the phpstorm.
Xampp for Mac
if you find you cannot get apache to run and you have
no apache web server already running!
......in terminal type.....
sudo apachectl stop
......then run......
sudo /Applications/XAMPP/xamppfiles/bin/apachectl start
.....if you have a port not specified you need to go into
applications/xampp/xamppfiles/etc/httpd.conf and on line 52 or 53
you have a ip or localhost you can set.
adding a port number
add :port number example 192.168.64.2:80 or localhost:80
save and run sudo /Applications/XAMPP/xamppfiles/bin/apachectl start }}}}}}}}}}}}}
XAMPP 5.6.3-0
Mac Yosemite 10.10.5
I ran sudo lsof -nP -iTCP:81 and found that Dropbox was blocking it first, so I unlinked that (never use it). Now, when I run that command, it is empty.
If I run sudo lsof -nP -iTCP:80 I get:
httpd 75 root 4u IPv6 0xaac1841fb411203d 0t0 TCP *:80 (LISTEN)
httpd 532 _www 4u IPv6 0xaac1841fb411203d 0t0 TCP *:80 (LISTEN)
Which I think is okay, since it's on a different port, right?
If I look inside the /Applications/XAMPP/logs for the error_log, ssl_request_log, and access_log there isn't anything logged since two months ago.
If I look inside the php_error_log I see this:
[08-Jan-2016 16:13:43 UTC] PHP Warning: PHP Startup: Unable to load dynamic library '/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20131226/php_pdo_mysql.dll' - dlopen(/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20131226/php_pdo_mysql.dll, 9): image not found in Unknown on line 0
I found a similar problem in this question. I ran the command in the top answer (but obviously changed the dir path to mine), and it didn't work. I read the forum with the link he attached and someone said that on Mac is is DYLD_LIBRARY_PATH not LD_LIBRARY_PATH, so i tried that as well, and it still doesn't work. I've tried restarting my computer and the osx-manager multiple times.
If I look inside the /Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20131226/ directory, it doesn't have php_pdo_mysql.dll in there. Is it supposed to be in there already, or is it trying to load the library in there, and it's not working?
I get the dynamic library error every time I try to start it, so I'm guessing that is the issue, but I'm not sure how to fix it.
For clarity, I have these lines in my httpd.conf file:
Listen 81
ServerName localhost:81
And in my php.ini file I have the extension=php_pdo_mysql.dll line uncommented, and it's the only extension uncommented. Does it depend on another extension? I'm so lost.
Update
$ . /Applications/XAMPP/xamppfiles/xampp stopapache
$ XAMPP: Stopping Apache...not running
$ . /Applications/XAMPP/xamppfiles/xampp startapache
$ XAMPP: Starting Apache...fail.
$ XAMPP: Another web server is already running.
But running lsof -nP -i :81 still gives me no results! =(
Well, I had to shut down the Apache server running on port 80 for this to work. I thought I wouldn't have to, since I had it configured to run on port 81. My only guess to why this happened is that I had it configured on port 80, started it, and then changed the configuration to 81 before shutting it down. I also had to comment out the php_pdo_mysql extension. I couldn't figure out that issue.
Alright, when I go to install Apache 24 by command prompt with this code going into it's bin.
httpd.exe -k install
then I run httpd.exe
I get this error.
AH00558: httpd.exe: Could not reliably determine the server's fully qualified do
main name, using fe80::d939:4e4:4915:276. Set the 'ServerName' directive globall
y to suppress this message
(OS 10013)An attempt was made to access a socket in a way forbidden by its acces
s permissions. : AH00072: make_sock: could not bind to address [::]:80
(OS 10013)An attempt was made to access a socket in a way forbidden by its acces
s permissions. : AH00072: make_sock: could not bind to address 0.0.0.0:80
AH00451: no listening sockets available, shutting down
AH00015: Unable to open logs
and then I pinged my port that is using 80. I get the PID of 4 which is my system with a description of NT Kernel & System.
Anyway I can fix this?
you could try to run command prompt as administrator
The port 80 is already used and when you try to modify it in the file conf/httpd.conf nothing changes. My mistake was that I assumed that the install folder is the one I have chosen to use via installation. If you go to services and find the Apache service and check the path to executable, you will see that it is not pointing to the folder that you thought you have installed it on. However, if you change the line "Listen 80" to "Listen 8080' in the httpd.conf file from the folder taken from the service path, it will most likely allow you to start the service.