I have Laravel Lumen in Docker container and Sublime Text in OSX host.
I was able to make the Xdebug working when running PHP urls from the browsers,
but how to get it working with scripts run from the docker machine?
I saw that Xdebug was disabled by default in composer, but was able to make env variable to enable it. Still it cannot connect to my Sublime Text's Xdebug plugin.
What are the extra steps to make it work?
php ini:
xdebug.remote_autostart=1
xdebug.remote_enable=On
xdebug.remote_handler=dbgp
xdebug.remote_connect_back=0
xdebug.remote_host=host.docker.internal
xdebug.remote_mode=req
xdebug.remote_port=9002
xdebug.remote_log = /var/www/html/xdebug.log
Sublime's Xdebug config:
{
"path_mapping": {
"/var/www/html" : "/Users/mark/projects/todolist/api/"
},
"url": "http://localhost",
"super_globals": true,
"close_on_stop": true,
"port": 9002,
"debug": true,
"host":"0.0.0.0"
}
Related
I have a Homestead VM with multiple nginx sites and a couple of apache sites too, everything configured through the Homestead.yaml file (short example below):
sites:
- map: site1.local
to: /home/vagrant/site1
php: "7.1"
#type: "apache <= (commented on purpose, not an error)
- map: site2.local
to: /home/vagrant/site2
php: "7.1"
I've been working turning On and Off the type: "apache" setting so the VM starts running apache (instead of nginx) or not, depending on the site that I need to work on at the specific moment.
My Issue now is that, after upgrading Vagrant and Homestead, it always keeps starting apache by default, no matter if it is specified or not, ALWAYS!; so everytime I start the machine, I need to ssh-it and flip the server.
I even tried using the services config directive as follows, without luck:
services:
- enabled:
- "nginx"
- disabled:
- "apache2"
Any thoughts? Please help!
Versions I am using:
Vagrant 2.2.7
Homestead 10.8.0
I had a similar issue. It turned out that I needed to log in the VM through SSH, and run the following command:
sudo systemctl enable nginx.service
When you look at restart-webserver.sh in the Homestead scripts directory, you will see that it verifies whether nginx is enabled, otherwise it always tries to restart Apache.
I know there are a lot of similar questions on SO and GitHub about this but none are working in my case.
I need for a project to use gulp + browsersync with an apache vhost (created with MAMP PRO 5.5).
Gulp is working (it does all the tasks I need). Browsersync is set up but it opens my website on a different port that the one which is used by MAMP. I've tested with default Port and Mamp default port. Browsersync still opens the website with the correct url but not the correct port.
I understand that I can't use the same port but how can I set up Browsersync ?
Here is my gulp relevant part :
gulp.task('browser-sync', ['sass', 'scripts'], function () {
browserSync.init({
open: 'external',
host: 'my-domain.dev',
proxy: 'my-domain.dev',
https: {
key: "/Users/path-to-custom-certificate/my-domain.dev.key",
cert: "/Users/path-to-custom-certificate/my-domain.dev.crt"
},
//port: 443, // If I try same port as MAMP, Browsersync increments this port ex 444
browser: "google chrome"
});
});
Mybe something can be configured in APACHE ?
I hesitated to delete my question but in case it could helps :
Finally, it appears that my Browsersync code is correct. When I run gulp, it opens the wrong url with the Browsersync default port :
https://my-domain.dev:3000
But when I open the correct url (my-domain.dev) set in apache, Browsersync is connected and reloads that page.
Has anyone made Laravel Valet (secure) work nicely with Browser Sync while using Laravel Mix. I am doing something like this but it keeps pointing me to https://shadow-api.test:3000 where as I simply want to omit the port.
mix.browserSync({
proxy: 'shadow-api.test',
host: 'shadow-api.test',
open: 'external',
https: {
key: "/Users/aligajani/.config/valet/Certificates/shadow-api.test.key",
cert: "/Users/aligajani/.config/valet/Certificates/shadow-api.test.crt"
}
});
For your information, I am using the latest versions of everything, fresh install and intend on building a SPA (with token auth). I haven't had similar issues with BrowserSync before simply because I wasn't using Valet.
Better late than never.. this works for me:
.browserSync({
proxy: 'https://mass-importer.faaren.test',
host: 'mass-importer.faaren.test',
open: 'external',
https: {
key: "/Users/fabianhagen/.config/valet/Certificates/mass-importer.faaren.test.key",
cert: "/Users/fabianhagen/.config/valet/Certificates/mass-importer.faaren.test.crt"
}
});
I had to prefix the proxy domain with https://. It still opens under port 3000 (or another if this port is already used), but browsersync is working.
I'm trying to set up php debugging with VSCode and xDebug, but xDebug can't connect to the host. Thus, VSCode doesn't hit any breakpoints either.
When I start the debug listener in VSCode, run a Bash shell in the php-fpm container and try to connect to the host, it fails:
$ docker-compose exec php-fpm bash
root#178ba0224b37:/application# nc -zv 172.20.0.1 9001
172.20.0.1: inverse host lookup failed: Unknown host
(UNKNOWN) [172.20.0.1] 9001 (?) : Connection refused
I'm confused about the IP addresses, because in the Docker settings the Virtual Switch subnet is set to 10.0.75.0, and the network adapter vEthernet (DockerNAT) uses the IP 10.0.75.1. How do the containers get the IP range 172.20.0.x?
From my desktop I am unable to request the webpage using 172.20.0.1.
It works fine with 10.0.75.1, which shows the phpinfo() as expected, but the breakpoint is not triggered.
phpinfo() shows xDebug is configured and the settings match what I have in the php-ini-overrides.ini config.
I've disabled the firewall, tried different IP's, and checked the port and various xDebug, php, docker-compose, and VSCode debug settings.
I've been searching far and wide, but I guess I'm still missing something. My guess is that it has to do with the network connection, but I don't know what else I can change to fix this issue.
Setup
Host is Windows 10 with docker-compose and VSCode.
I got the docker debug-test directory from https://phpdocker.io/generator
Basically it uses two docker containers: nginx:alpine and phpdocker/php-fpm
My VSCode workspace looks like this:
(The readme files come from the phpdocker.io generator and contain some basic Docker info)
index.php contents:
<?php
phpinfo(); // <-- VSCode breakpoint here
echo 'hello there';
?>
The IP addresses for the containers:
/debug-test-php-fpm - 172.20.0.3
/debug-test-webserver - 172.20.0.2
$_SERVER['REMOTE_ADDR']: 172.20.0.1 <- the host?
Configs and logs
launch.json contents:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"pathMappings": {
"/application/public": "${workspaceRoot}/public"
},
"log": true,
"port": 9001,
"xdebugSettings": {
"max_data": 65535,
"show_hidden": 1,
"max_children": 100,
"max_depth": 5
}
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9001
}
]
}
docker-compose.yml contents:
###############################################################################
# Generated on phpdocker.io #
###############################################################################
version: "3.1"
services:
webserver:
image: nginx:alpine
container_name: debug-test-webserver
working_dir: /application
volumes:
- .:/application
- ./phpdocker/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
ports:
- "8000:80"
php-fpm:
build: phpdocker/php-fpm
container_name: debug-test-php-fpm
working_dir: /application
volumes:
- .:/application
- ./phpdocker/php-fpm/php-ini-overrides.ini:/etc/php/7.2/fpm/conf.d/99-overrides.ini
php-ini-overrides.ini contents:
upload_max_filesize = 100M
post_max_size = 108M
# added for debugging with Docker and VSCode
xdebug.remote_enable=1
xdebug.remote_connect_back=On
xdebug.remote_autostart=1
# xdebug.remote_host=172.20.0.1 # using remote_connect_back instead, which should work for any IP
xdebug.remote_connect_back=1
xdebug.remote_port=9001
xdebug.profiler_enable=0
xdebug.var_display_max_depth = 5
xdebug.var_display_max_children = 256
xdebug.var_display_max_data = 1024
xdebug.remote_log = /application/xdebug.log
xdebug.idekey = VSCODE
xdebug.log contents after one visit to the page:
Log opened at 2019-01-30 12:37:39
I: Checking remote connect back address.
I: Checking header 'HTTP_X_FORWARDED_FOR'.
I: Checking header 'REMOTE_ADDR'.
I: Remote address found, connecting to 172.20.0.1:9001.
W: Creating socket for '172.20.0.1:9001', poll success, but error: Operation now in progress (29).
E: Could not connect to client. :-(
Log closed at 2019-01-30 12:37:39
Log opened at 2019-01-30 12:37:39
I: Checking remote connect back address.
I: Checking header 'HTTP_X_FORWARDED_FOR'.
I: Checking header 'REMOTE_ADDR'.
I: Remote address found, connecting to 172.20.0.1:9001.
W: Creating socket for '172.20.0.1:9001', poll success, but error: Operation now in progress (29).
E: Could not connect to client. :-(
Log closed at 2019-01-30 12:37:39
This is no paste error, it actually logs the request two times for some reason.
Debug console in VSCode after starting the debug listener:
<- launchResponse
Response {
seq: 0,
type: 'response',
request_seq: 2,
command: 'launch',
success: true }
Any thoughts? I'm lost..
Perhaps it has to do with the DockerNAT setup?
Sorry for the long post. I'm still new to Docker, I hope this has all the info needed.
Edit: solved
See my answer below.
After some coding I stumbled upon the solution.
The IP address in the php debug settings was incorrect. Since my system has VPN connections, multiple ethernet adapters, multiple virtual switches, and multiple virtual machines, it's a bit tricky to find out what's used where.
I discovered the IP by accident when I ran netstat on the php container during a request:
$ docker-compose ps --services
php
app
$ docker-compose exec php sh
/var/www/html # netstat
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 08674b3fd785:58060 192.168.137.12:http TIME_WAIT
tcp 0 0 08674b3fd785:58062 192.168.137.12:http TIME_WAIT
[...]
udp 0 0 08874b3cd785:35298 192.168.65.1:domain ESTABLISHED
I tried the 192.168.65.1 IP first, but that didn't work.
The 192.168.137.12 is the IP of a Hyper-V Virtual Machine that the php script connects to. Apparently the php container can connect to that, so maybe then it could also connect to the Windows adapter that's bound to that virtual switch, in other words: 192.168.137.1 .
Adding this to the xDebug settings solved the problem:
xdebug.remote_host = 192.168.137.1.
I have load laravel project which runs fine with valet domain something.dev
Tried to implement browser sync with laravel-mix
mix.browserSync({
proxy: 'something.dev'
});
After running npm run watch it is pointing me to http://localhost:3000/
Can i point to to valet domain instead of localhost:3000 ?
Here is the output of npm run watch
Asset Size Chunks Chunk Names
mix.js 2.59 kB 0 [emitted] mix
[Browsersync] Proxying: http://something.dev
[Browsersync] Access URLs:
--------------------------------------
Local: http://localhost:3000
External: http://192.168.1.131:3000
--------------------------------------
UI: http://localhost:3001
UI External: http://192.168.1.131:3001
--------------------------------------
[Browsersync] Watching files...
I had similar issues myself getting browserSync working with Valet, but the options I use are:
mix.browserSync({
proxy: 'something.test',
host: 'something.test',
open: 'external'
});
host overrides any detection of hostname in browserSync
open tells it which URL to open (local by default)
If you're using valet and ran into an issue where the browsersync doesn't start, here's the answer. I was banging my head on the wall over this but found a clue in their Upgrade to Mix 6 docs. After reading this, here's my setup:
// package.json
{
...
"scripts": {
"build": "mix --production",
"dev": "mix watch" // <--- add this script, you need to run mix watch
},
...
}
Then in my webpack.mix.js
// webpack.mix.js
const mix = require('laravel-mix');
const homedir = require('os').homedir();
const host = 'your-local-domain.test';
// ... other mix stuff
mix.browserSync({
hot: true,
ui: false,
proxy: `https://${host}`,
host,
port: 8080,
open: 'external',
notify: true,
files: ['**/*.php', 'dist/**/*.(js,css)'],
// if you're using valet with https, point to cert & key
https: {
key: `${homedir}/.config/valet/Certificates/${host}.key`,
cert: `${homedir}/.config/valet/Certificates/${host}.crt`,
},
});
Let me know if I'm missing anything!