jcarlier
Posts: 9
Joined: Wed Apr 16, 2014 1:56 pm

connect to a php script from outside

Sat Apr 19, 2014 12:55 pm

hi,

i have installed a lamp server(apache2,php,mysql) on my raspi

i created a mysql database: test

i would like to execute a php script ( testconnect.php see below ) from outside my local network

i have no problems to execute it on local network :D
(in the browser:
http://raspi_ip/php/testconnect.php)

So i create a dyndsn on NOIP.com

and in my browser i introduce http://NOIPhostname/php/testconnect.php

i get no answer.. :x
maybe some parameters in php.ini or mysql/my.cnf ???
i must take open port: 60000 for my Internet Service Provider
i don't know how ...


thanks for your support
and sorry for my poor english

PS:
i succeeded to connect to ssh server (after changing iptables and port 60000 in sshd_config) by the command:
ssh NOIPhostname -p 60000 -l pi


-------------------------------------------------------------

in folder /var/www/php:
testconnected.php:

<?php
//Try connection
$db=mysqli_connect('localhost', 'pi', 'raspberry', 'test') or die ("Failed to connect: " . mysqli_error());
echo "Connected OK.";
// Clean up
mysqli_close($db);
?>
------------------------------------------------

Tarcas
Posts: 741
Joined: Thu Jan 09, 2014 5:38 am
Location: USA

Re: connect to a php script from outside

Sun Apr 20, 2014 2:11 am

If you're trying to connect to
http://NOIPhostname/php/testconnect.php
but the server is running on port 60000, you need to add a :60000 to specify that port, so the URLwould be:
http://NOIPhostname:60000/php/testconnect.php

This is all assuming that you already have port 60000 forwarded from the public Internet to your Pi, not firewalled, etc, (sounds like those are true since you were able to SSH to that port) and that Apache has been configured to run on port 60000 and SSH no longer is. (You can't have two services listening on the same port.) If any of those is not true and you don't know how to do it yourself, you will have to google it or let us know that that's the part that you need help with.

jcarlier
Posts: 9
Joined: Wed Apr 16, 2014 1:56 pm

Re: connect to a php script from outside

Sun Apr 20, 2014 7:34 am

thanks for your answer

192.168.0.233 ==> raspi ip

internet access provider:
port forwarding : 60000
adr ip: 192.168.0.233
dmz:192.168.0.0

in my browser:
http://192.168.0.233/ ==> ok (apache2 responds)
http://NOIPurl/ ==> nothing
http://NOIPurl:60000/ ==> nothing

Should i change something in apache config for listening in port 60000 ????

Thanks

User avatar
DougieLawson
Posts: 39303
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: connect to a php script from outside

Sun Apr 20, 2014 8:15 am

jcarlier wrote: Should i change something in apache config for listening in port 60000 ????
On my router port forwarding allows me to open port 60000 on the public side pointing to port 80 on the LAN side.

If your router doesn't allow that but only allows a direct port to port mapping you will need to change the Listen statement in your Apache2 config.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

jcarlier
Posts: 9
Joined: Wed Apr 16, 2014 1:56 pm

Re: connect to a php script from outside

Sun Apr 20, 2014 8:21 am

ok thanks

but i don't know how to change the Listen statement in Apache2 config !!! (

thanks for your reply

User avatar
DougieLawson
Posts: 39303
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: connect to a php script from outside

Sun Apr 20, 2014 8:25 am

jcarlier wrote:ok thanks

but i don't know how to change the Listen statement in Apache2 config !!! (

thanks for your reply
sudo nano /etc/apache2/httpd.conf
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

jcarlier
Posts: 9
Joined: Wed Apr 16, 2014 1:56 pm

Re: connect to a php script from outside

Sun Apr 20, 2014 8:43 am

when i sudo nano /etc/apache2/httpd.conf , i have a empty file ... :?:

User avatar
rpdom
Posts: 17275
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: connect to a php script from outside

Sun Apr 20, 2014 9:02 am

sudo nano /etc/apache2/ports.conf

jcarlier
Posts: 9
Joined: Wed Apr 16, 2014 1:56 pm

Re: connect to a php script from outside

Sun Apr 20, 2014 10:16 am

i have added:
Listen 60000

so ihave :
NameVirtualHost *:80
Listen 80
Listen 60000


i got an error:

apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:60000
no listening sockets available, shutting down
Unable to open logs
Action 'start' failed.
The Apache error log may have more information.
failed!

User avatar
DougieLawson
Posts: 39303
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: connect to a php script from outside

Sun Apr 20, 2014 10:51 am

You need to have a ServerName directive.
You also need to change that virtual host directive.
You should also comment out the listen 80.

Curiously, Apache2 has a mass of online docs at http://httpd.apache.org/docs
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Tarcas
Posts: 741
Joined: Thu Jan 09, 2014 5:38 am
Location: USA

Re: connect to a php script from outside

Sun Apr 20, 2014 6:22 pm

You also need to make sure that no other services are listening on port 60,000. It sounds like something is already bound to that port. (You mentioned SSH earlier; you'll have to disable port 60000 from that.)

To see what ports are currently bound to, type:
netstat -l
or
netstat -l --numeric-ports
The latter won't translate known ports (like 80 or 22) to service names like http or ssh. The former will.
If you find port 60000 in this list, something is already using it. Unfortunately the list won't tell you what is listening on any given port.

User avatar
DougieLawson
Posts: 39303
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: connect to a php script from outside

Sun Apr 20, 2014 6:37 pm

sudo apt-get install lsof
sudo lsof -i tcp:60000

Will tell you what task is bound to that port.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

jcarlier
Posts: 9
Joined: Wed Apr 16, 2014 1:56 pm

Re: connect to a php script from outside

Tue Apr 22, 2014 7:16 am

ok

i have installed lsof and i have nothing bound to that port

You need to have a ServerName directive.
You also need to change that virtual host directive.
You should also comment out the listen 80.


can you me explain in details the different steps ( i am a newbee in linux , i develop rather in android) ?

Which files should i change for listening port 60000 ?

Many thanks

User avatar
DougieLawson
Posts: 39303
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: connect to a php script from outside

Tue Apr 22, 2014 9:07 am

Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

jcarlier
Posts: 9
Joined: Wed Apr 16, 2014 1:56 pm

Re: connect to a php script from outside

Tue Apr 22, 2014 12:31 pm

ok
i got it ....

only change port 60000 in /etc/apache2/ports.conf

thanks for your support

jcarlier
Posts: 9
Joined: Wed Apr 16, 2014 1:56 pm

Re: connect to a php script from outside

Mon May 05, 2014 1:46 pm

hi

When i introduce in my browser http://Myxx.xxxx.me:60000 , i get a response from my server apache2 :D

(Myxx.xxxx.me = NOIP free account)


but when somebody try to make the same thing from outside , nothing appears.... :oops:


is there some Firewall parameters in raspberry to make?? (like windows 7)

maybe Iptables ??

thanks for your support

User avatar
DougieLawson
Posts: 39303
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: connect to a php script from outside

Mon May 05, 2014 2:57 pm

You need to port forward port 60000 on your router.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

jcarlier
Posts: 9
Joined: Wed Apr 16, 2014 1:56 pm

Re: connect to a php script from outside

Mon May 05, 2014 5:02 pm

i have already done that since i can connect to the port 60000...

i think it s a problem of firewall

User avatar
DougieLawson
Posts: 39303
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: connect to a php script from outside

Mon May 05, 2014 9:43 pm

There is no firewall until you create one with iptables or ufw. The default with the RPi is that ALL ports are open.

So the problem exists in your router config or outside your local network.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Return to “Advanced users”