Remote PHP Debugging from within WSL2 in Visual Studio Code - php

I'm running Windows 10, with a WSL2 Ubuntu instance. I do my development within the WSL2 instance with the "Remote - WSL" extension of Visual Studio Code. So my VSC is running as a WSL2 application, not as a Windows application. I have an additional remote server (I'll refer to this as "Server X" which actually hosts/runs the PHP code. This remote server does not support the use of the "Remote - WSL" extension, so I use an "SFTP" extension to push my changes to this server. And I cannot run the code locally (in either Windows or WSL2) due to the database connection being unsupported.
I'm trying to configure remote debugging of the code on Server X from within VSC running as a WSL2 application (IE: using the "Remote - WSL" extension). The intent is to listen for a browser request to initiate the debug session.
What's happening is when I turn on "Listen for Remote Connection" in VSC when running as a WSL2 application, it doesn't detect the browser when I refresh it. I've determined the reason is because while running as a WSL2 application, my IP is different than when I'm outside WSL (which is where I'm refreshing the browser). So in short, I'm initiating a browser session outside of WSL (IP: 192.168.1.2), the remote server attempts to connect to a debugger at 192.168.1.2:9003, but doesn't find one because my VSC is listening on 192.168.1.3:9003 while it's running as a WSL2 application.
I've confirmed if I instead run VSC as a Windows application (IE: not using Remote - WSL extension on WSL2 instance) everything works fine after adjusting some setting paths to point to Windows PHP rather than WSL2 PHP.
I've been trying to play around with using SSH tunnels to re-route my port 443 traffic from Windows through WSL, but have been unsuccessful so far.
Has anyone run into this issue and have any idea how to get around it? Or is what I'm trying to do unsupported/discouraged?

So WSL runs under the 172.16. 0.0/12 private address range and is not directly accessible by anything external to the host Windows machine. As such, populating xdebug.client_host with this IP, will not work.
My initial idea of using port forwarding was correct, but not in the direction I thought. Instead of redirecting the outgoing web traffic (443 since my site is using SSL) from Windows through WSL, then redirect from WSL to Server X. I instead just needed to redirect the incoming xdebug traffic (9003) from Windows to WSL. (Probably what #Derick was alluding to)
To do this, I left xdebug configured as it normally would have been if WSL wasn't in the picture.
So:
zend_extension=xdebug
xdebug.mode=profile,debug
xdebug.idekey=<ide key value here>
xdebug.client_host=<ip of windows host, as backup>
xdebug.start_with_request=trigger
xdebug.trigger_value=<my trigger value>
xdebug.discover_client_host = 1
Then, using the following PowerShell script on the Windows host to redirect port 9003 from the Windows host to the WSL guest:
If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
$arguments = "& '" + $myinvocation.mycommand.definition + "'"
Start-Process powershell -Verb runAs -ArgumentList $arguments
Break
}
$remoteport = bash.exe -c "ifconfig eth0 | grep 'inet '"
$found = $remoteport -match '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
if ($found) {
$remoteport = $matches[0];
}
else {
Write-Output "IP address could not be found";
exit;
}
$ports = #(9003);
for ($i = 0; $i -lt $ports.length; $i++) {
$port = $ports[$i];
Invoke-Expression "netsh interface portproxy delete v4tov4 listenport=$port";
Invoke-Expression "netsh advfirewall firewall delete rule name=$port";
Invoke-Expression "netsh interface portproxy add v4tov4 listenport=$port connectport=$port connectaddress=$remoteport";
Invoke-Expression "netsh advfirewall firewall add rule name=$port dir=in action=allow protocol=TCP localport=$port";
}
Invoke-Expression "netsh interface portproxy show v4tov4";
Above script is modified from the script found here:(https://dev.to/vishnumohanrk/wsl-port-forwarding-2e22)
Which itself is modified from here: (https://github.com/microsoft/WSL/issues/4150#issuecomment-504209723)
Note*: You have to install net-tools in the WSL guest in order for the above script to work, so: sudo apt install net-tools.

Related

GAE dev_appserver crashes CGI / FastCGI on windows

I installed python 2.7 and the Goole Cloud SDK.
After that I installed the php runtime using this command :
gcloud components install app-engine-php-windows
I then boot up a local dev server using this line :
dev_appserver.py <app-directory>
The server boots up fine, but when I send multiple requests to the server, I see multiple popups (one after te other) saying "CGI / FastCGI has stopped working". I can then "Debug" or "Close program".
In the logfile I see this :
ERROR:root:php failure (255) with:
stdout:
ERROR:root:php failure (-1073741819) with:
stdout:
OS specifics : Windows 10 Pro 64-bit.
Also, adding extension="php_curl.dll" to php.ini does not avoid my problem as stated in other issues similar to this one.
Can anyone help with this issue?

php command is not recognized in wamp

I'm working on websocket. I came across this article, and simply downloaded their file and try running it in my localhost.
https://www.sanwebe.com/2013/05/chat-using-websocket-php-socket
What I understand is, they want to sue local server's websocket server.
But I have problem in starting up the server. I'm using windows 10 with wamp 2.2. As I checked webscket is enabled in my php.ini's extention.
I followed this example to cmd the right path to start it but to no avail:
https://www.sanwebe.com/2013/05/chat-using-websocket-php-socket/comment-page-1#comment-5593
It says 'php.exe' is not recognized as an internal or external ...
I then searched online again, thus set the path to my php folder in the system's environment variable. The path is: C:\wamp\bin\php. Then I closed the cmd and relaunched. Nothing worked out. The same error shows up.
This is what I did on cmd:
1) cd C:\wamp\bin\php
2) php.exe -q C:\projects\myfolder\server.php
Please help me to connect to wamp server's websocket to run the example I've downloaded.In the console, the error shown is:
WebSocket connection to 'ws://localhost:9000/demo/server.php' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
I found the answer from this site: http://rodrixar.blogspot.my/2011/07/how-to-run-php-sockets-in-wamp.html
I did the following,
1) open cmd
2) cd C:\wamp\bin\php\php5.6.19
3)php.exe -q C:\projects\mysite\server.php
4) Firewall open up and allow access for CLI
5) now connection made already..

Gammu SMS gateway service shows "Error 27"

This is my first experience using Gammu as SMS gateway, and I have a problem with the setup.
This is my system:
Windows 8.1 x64
Gammu 1.33.0 Windows x64
XAMPP 1.8.1
Database connection to MySQL using ODBC
GSM modem used: Wavecom Fastrack M1306B
And here is my smsdrc:
[gammu]
port = com6:
connection = at115200
[smsd]
Service = sql
Driver = odbc
SQL = mysql
host = localmysql
DeliveryReport = sms
logfile = smsdlog
debuglevel = 1
PIN = 1234
commtimeout = 1
sendtimeout = 10
User = root
Password =
# host = localhost
PC = localhost
Database = smsd
And here is my gammudrc :
port = com6:
connection = at115200
What I've did:
Extract the directory of gammu/bin into xampp/htdocs/gammu
Created smsrdc & gammurc files with the configs above
Set the compatibility of gammu-smsd.exe to Run As Administrator
phpmyadmin > Create new db (smsd) > imported the sql from gammu\share\doc\gammu\examples\sql\mysql.sql
My ODBC settings :
(source: kaskus.com)
(I've tested and it's connected)
- I've added the gammu-smsd into windows serices
- test identify by running gammu --identify
- test sending sms manually from console
- test gammu-smsd -c smsdrc, and i had no error at all.
The problem is I couldn't run the gammu-smsd as a service, whether it's manually from the cmd nor started it from the services.
If I started the gammu-smsd from cmd ( gammu-smsd -c smsdrc -s ), the gammu-smsd showed up in the task manager, but disappeared in less than 1 sec.
Whenever I tried to manually start the gammu-smsd service from the Windows Services, it always shows me this kind of error:
(broken image: http://cdn.kaskus.com/images/2014/01/08/270124_20140108085812.png)
I've done some searchs, and what I've found is all about wrong connection into DB, port, or about Run As Administrator. But I'm quite sure it's not from config.
How can I solve this issue, so that I can run the gammu-smsd services properly?
Can you please help me?
Thanks.
Try running not as a service :
gammu-smsd -c smsdrc
in my case that do the job.

Connecting to Oracle 11gR2 XE on Ubuntu 13 server via PHP

I am trying to connect to Oracle 11gR2 Xe on Ubuntu 13 server from another computer in the network, via PHP.
I am using installs and examples followed from oci_connect like here:
<?php
query_cities();
function query_cities() {
if {
$c = oci_connect("hr", "hr", "localhost:1521/XE");
;
} else {
echo "No connection"; }
?>
or another example like:
$c = oci_connect("hr", "hr", "192.168.1.33:1521/XE");
I have already enabled the remote connection in DB via SqlPlus
SQL> EXEC DBMS_XDB.SETLISTENERLOCALACCESS(FALSE);
and i have unlocked the user HR
SQL> ALTER USER hr ACCOUNT UNLOCK;
but I can only find some connection via IPv6 on the network from SQL Developer, like netstat:
tcp6 0 0 192.168.1.33:1521 192.168.1.2:57563 ESTABLISHED 14843/oracleXE
tcp6 0 0 192.168.1.33:1521 192.168.1.2:59314 ESTABLISHED 15665/oracleXE
not from my browser and they are not on tcp IPv4. The browser window remain white .. no reaction, unresponsive and no error message.
Should this be due to the TNSLR IP is active only on IPv6 or non of the oci_connect formulas are good enough or I am missing some other else?
I would appreciate any help on this issues
Alright, on the basis of received advice to seek the error in logs, I've found the message "*There is something wrong with your system - please check that ORACLE_HOME and LD_LIBRARY_PATH are set and point to the right directories*" and I decided to go through the sophisticated process of installing the Oracle InstantClient and reinstall OCI8 package, after the model from st-curriculum.oracle - with very small modifications, as follows:
Oracle 11g R2 XE database and Apache2 / PHP server have been apriori installed on Ubuntu 13.10 server and system prepared (with prereqiuzite, swap file, kernel parameters, memory leak error recover, libraries and chkconfig emulator), as described in many posts.
I stopped apache2 server
service apache2 stop
and started DRCP connection pooling as in st-curriculum.oracle.com
I created a user named PHPHOL (and alternate install Oracle's sample HR schema, if not already done at oracle install)
Next I downloaded the Basic and the SDK Instant Client packages from OTN: oracle.com/technetwork/database/features/instant-client/index-100365.html and unzipped the packages in $ORACLE_HOME, (/u01/app/oracle/product/11.2.0/xe)
Then I downloaded the OCI8 packeage from pecl.php.net/package/oci8 and installed in /opt/oci8 as instantclient
phpise
./configure --with-oci8=instantclient,/u01/app/oracle/product/11.2.0/xe/instantclient_11_2
make / make install
I set the oracle environment path as in oracle technote
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe
LD_LIBRARY_PATH=/u01/app/oracle/product/11.2.0/xe/instantclient_11_2
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH=/opt/oci8/modules
nano /etc/ld.so.conf.d/oracle.conf
and insert: /u01/app/oracle/product/11.2.0/xe/instantclient_11_2
nano /etc/ld.so.conf.d/oci8.conf
and insert: /opt/oci8/modules
nano /etc/ld.so.conf.d/shared.conf
and insert the installed shared extensions location: /usr/lib/php5/20121212
ldconfig
Next I edited the configuration file php.ini to add: extension=oci8.so, set the date.timezone directive and added also the OCI8 1.4 extension class: oci8.connection_class = MYPHPAPP (for the st-curriculum.oracle.com examples, see link above)
I made the link: $ORACLE_HOME/instantclient_11_2/libclntsh.so.11.1. to points to $ORACLE_HOME/instantclient_11_2/libclntsh.so
Restart Oracle database and Apache services on Ubuntu 13.10 server
/etc/init.d/oracle-xe force-reload
service apache2 start
I verified in phpinfo() the oci8 was enabled, and I made the connect.php file like:
$conn = oci_connect("hr", "hr", "localhost/xe");
or like the one from st-curriculum.oracle.com example.
From another computer on the same network I connected through a browser to oracle database on Ubuntu server and I've got
Connected to Oracle!
I hope this help

Memcached can't connect on Windows 7 via PHP

On one computer with Windows 7 connecting to memcache runs OK, but on another I get:
Warning: memcache_connect() [function.memcache-connect]: Can't connect to localhost:11211
Code which I'm trying to run is:
$memcache_obj = memcache_connect('localhost', 11211);
I also can't connect via telnet, a failed connection.
start>run type CMD , in the console window type netstat -a -n , do you see something like 0.0.0.0:11211 ... LISTENING ? , if no , probably memcached is not running , or is configured to another port .
In the console , try c:\memcached\memcached.exe -d start 'supposing you have memcached installed in c:\memcached .
to run memcached as windows service , try memcached.exe –d install .
YOU SHOULD START THE CONSOLE AS AN ADMINISTRATOR . try start>all programs > Accessories , then right click on command prompt and run as administrator , then apply all of the above
Memcached is either not running on the machine that you can't connect on or the instance of memcached running on that machine is configured to use a different port.
If you don't have (or want) an instance of memcached one each machine you will need to change "localhost" to the IP of the machine that is running memcached (assuming they are networked).
If it is set up try starting memcached again, and ensure you're using port 11211.

Categories