Check if php-cgi server is connectable remotely - php

I have a php server listening on a port that seems to have issues. How can I connect to the php-cgi server to find out it if it up or not? (Sort of "ping" the php-cgi process)
I need to determine if the issue I'm having is due to the http server or the php-cgi server. Therefor I want to be able to "ping" the php-cgi server to make sure it is accepting requests. If not, I know it is the php-cgi server that is the cause of the problem.

Try to use telnet
telnet localhost portnumber.
So if you running on port 80 of your localhost type in
telnet localhost 80
It should connect if it does not, your server is not running!

Related

Connection Firebird DB via SSH

I am creating an application with Laravel and Firebird 2.5 and wants to run it on a DigitalOcean server structure. We have 2 servers for the application, one for the web services (lets call it www) and one for the database services. I did a successful setup with Mysql and it works well but we all know Firebird is a rough one. So this is what we did so far:
Install a LEMP stack in www and Firebird 2.5 SuperServer. As I said these are digital ocean servers, both runs Ubuntu 14.04.
We created an SSH tunnel between the two server with the following structure:
ssh -L 9500:127.0.0.1:3050 username#db_server_ip_address (Private address)
But when we tried to hook up the application on www with the database server got the following error:
unavailable database
In the Laravel Configuration file used the following set up:
DB_HOST=127.0.0.1
DB_DATABASE=/home/username/database.gdb
DB_USERNAME=username
DB_PASSWORD=password
The credentials are correct, we can use it on the remote (db) server.
What do you think what could be the problem? Is it the SSH tunneling?
Warning: I don't use SSH that much, and have never used SSH tunneling, my answer is based on looking at documentation.
The ssh -L 9500:127.0.0.1:3050 does not do what you think it does:
Specifies that connections to the given TCP port or Unix socket on the local (client) host are to be forwarded to the given host and port, or Unix socket, on the remote side. This works by allocating a socket to listen to either a TCP port on the local side, optionally bound to the specified bind_address, or to a Unix socket. Whenever a connection is made to the local port or socket, the connection is forwarded over the secure channel, and a connection is made to either host port hostport, or the Unix socket remote_socket, from the remote machine.
(from ssh(1))
In other words, as far as I can tell the proper command would be:
ssh -L 9500:<ip-address of the Firebird server>:3050
The second problem seems to be that your Laravel config does not specify a port, so it is likely still trying to connect to port 3050 (the Firebird default port), instead of port 9500 that you configure. I don't know Laravel, but a property DB_PORT=9500 seems logical (but maybe these properties are specific to your own deployment, in which case you may need to do some more work).

Run newer webserver without root permissions

I want to use PHP 7 when it comes out, but my server admin refuses to upgrade past PHP 5.3.3 and I don't have root privileges. I can run a webserver on port 1024 or higher, but I need it to be available on ports 80 and 443.
I am considering connecting to this userland webserver via a local SOCKS client in PHP. Can I effectively run a PHP 7 webserver on port 80 and 443 this way, and will it be possible to handle PHP requests and sessions correctly?
No. Port 80 is a privileged port.

Can we run node and apache both on same port

I have a application in nodejs and PHP. For now i am using different both.
Can i run node and apache both on same port 8080
Is, there is any way to run any application both on 8080
Thanks
An port is usually connected only to one application. So you have to use different ports.
Proxy -
But you could for example create an virtual host in apache and configure this host as proxy. In this configuration you could access the node.js server on the same port. The node.js server would run on another port.
For TCP based applications, no. You can have only one application listening on a single port at time. If you had 2 network cards, you could have one application listen on the first IP and the second one on the second IP, both using port 8080.... but I doubt that is your case.
I guess you can run them on UDP protocol, which could allow you to have two applications listen to the same port, but as UDP is unreliable and it doesn't establish connection, just sends/receives packets. You might experience big packet loss on UDP.
So, short answer - no.
Actually, there might be a way using iptables. Add a rule of this nature
iptables -A INPUT \
-p tcp \
-m bpf --bytecode "14,0 0 0 20,177"
-j redirect .. Port 80
Check the first few bytes of the connection, and redirect the connection. Then you can accept both http and node.js on the same port, but have the servers running on separate ports.
The syntax above is incorrect, and I have not tried it, but I know people who have used this strategy successfully.

which Apache server will it use?

Lets us consider a case, there are 2 apache server running, and one domain is available.
if we make a request like this, http://domain1.com/example1.php it should request one
apache server where actual domain is present. When http://domain1:8000/example1.php it should point to a application in a another server (other machine) under a same domain group.
Now a question is, if http://domain1:8000/example1.php is requested, then it will run in which server? which server will interpret it? which server will execute those files, either apache server in domain1 system or, a apache server that domain1:8000 (this is other machine, to which request is port forwarded) points?
A server will listen on a specific port, so if you are using different ports, it will go to whatever server is listening on that port, regardless of the domain.
Since you're using port forwarding, then it can only be processed by where ever you forward the ports to. So, port 80 is being forwarded to your main server and port 8000 to the other server. If you didn't forward, and all were going to the first server, then you would get an error if the first server were not also listening on port 8000.

How does PHP communicate with MySQL on the same server

Does anyone know how php requests data from mysql?
If I have mysql in the same machine as php, does it open a tcp connection to the localhost on port 3306 or does it have some other way of getting the data?
Is it the same in linux and windows?
Thanks
if available it uses a unix socket, otherwise localhost.
Note that even if you specify localhost in the connection string it will try to use the faster "unix socket" if available
Usually PHP opens up a local pipe found at /tmp/mysql.sock to connect to a local version of the server, unless you use an IP address in your connection string.
PHP opens a connection to port 3306 is the server via TCP to allow data communication. Hence, you can specify which port to connect to in mysql(i)_connect etc, and why, you need to have firewall rules for mysql.
It is the same in Windows as Linux
So yes, TCP :)
EDIT: Revision, In linux, php looks to connect to mysql via /tmp/mysql.sock the tmp directory needs to have correct permissions.

Categories