How to set up a debugging using the Turnkey Linux LAMP stack and VS Code

johna by | December 19, 2023 | Web Development

In my previous post I gave instructions on hosting a website and database on the Turnkey Linux LAMP stack. This post is a continuation and covers setting up debugging the website in Visual Studio Code.

First step is to modify the php.ini file on the server. You can do this in Webmin. In the System menu press PHP Configuration. On the row for "Configuration for mod_php" press Edit Manually to open the file for editing.

PHP Configuration

Then add a configuration section for Xdebug, as follows:
[xdebug]
xdebug.mode=develop,debug
xdebug.discover_client_host=1
xdebug.client_port = 9003
xdebug.start_with_request=yes

After saving this change you will need to restart the Apache Webserver. This can be done in Webmin. Press Apache Webserver in the Servers menu and then press the apply changes icon button near the top right corner.

Edit Configuration Manually.jpg

Then start VS Code and add the extensions PHP Extension Pack by Xdebug which includes PHP Debug and PHP IntelliSense and SFTP by Natizyskunk.

You need PHP on your workstation for these extensions to work, so download it from windows.php.net. The LAMP stack currently includes PHP 7.4 so I downloaded PHP 7.4.32 NTS Windows 64-bit. Once downloaded and uncompressed move it to your preferred location, you then need to tell the extensions the path to php.exe with the following three settings in settings.json (use your own path, not mine and ensure php.exe is included):

"php.executablePath": "D:\\Documents\\php-7.4.32-nts-Win32-vc15-x64\\php.exe",
"php.debug.executablePath": "D:\\Documents\\php-7.4.32-nts-Win32-vc15-x64\\php.exe",
"php.validate.executablePath": "D:\\Documents\\php-7.4.32-nts-Win32-vc15-x64\\php.exe"

settings.json

You can now configure SFTP. Press Ctrl+Shift+P to bring up the command prompt and type SFTP: config. You can then enter a configuration similar to the following, using your website details, and FTP user and password.

{
    "name": "My Website",
    "host": "mywebsite.local",
    "protocol": "sftp",
    "port": 22,
    "username": "mywebsite",
    "password": "abc123",
    "remotePath": "/var/mywebsite",
    "uploadOnSave": false,
    "useTempFile": false,
    "openSsh": false
}

sftp.json

Next configure the debug settings.

{
    "name": "Listen for Xdebug",
    "type": "php",
    "request": "launch",
    "port": 9003,
    "pathMappings": {
        "/var/mywebsite": "${workspaceFolder}/"
    }
}

launch.json


You are now ready to debug. Press F5 to start listening for Xdebug connections and set breakpoints where needed.

If you need to set up URL rewriting, see my next post How to enable URL rewriting using the Turnkey Linux LAMP stack.

Related Posts

Web Development Retro Computing

Converting dBase IV programs to run in the browser

by johna | September 13, 2024
Some pointless entertainment trying to get some old dBase programs running in the browser.

Website Hosting Web Development

How to set up a website and database using the Turnkey Linux LAMP stack

by johna | November 18, 2023
If you need to host your own website for the purposes of web development, Turnkey Linux LAMP Stack is an easy to install all-in-one solution that you can set up on a spare computer or a VM (Virtual Machine).

Web Development

Intermittent "Unable to read data from the transport connection: net_io_connectionclosed" errors

by johna | May 6, 2020
If you are having intermittent problems sending email in .NET using System.Net.Mail consider switching libraries.

Comments

There are no comments yet. Be the first to leave a comment!

Leave a Comment

About

...random postings about web development and programming, Internet, computers and electronics topics.

I recommend ASPnix for web hosting and Crazy Domains for domain registration.

Subscribe

Get the latest posts delivered to your inbox.