Debugging di bahasa apapun pasti dilakukan. Tidak terkecuali di PHP. Hanya saja masih banyak orang yg melakukan debug di PHP dengan cara-cara tradisional, yaitu dengan menambahkan script var_dump, print_r, die dan sebangsanya untuk menyelidiki setiap tahap baris code. Cara tradisional ini sangat boros waktu, tidak efisien, dan sering membuat frustasi. Penulis sendiri sering sekali habis waktu hanya mencari baris mana yang mengakibatkan bug menggunakan cara
tradisional tadi. Makanya, semua coder PHP seharusnya memaksakan diri untuk menggunakan debugger. Sudah lama debugger ini ada, cuman memang coder malas men-setupnya. Dengan berdatangannya File Editor baru yang canggih2 dan gratis, debugging ini makin mudah. Mari kita coba dengan VS Code Editor. Show
[XDebug] xdebug.remote_enable = 1 xdebug.remote_autostart = 1
– Aplikasi dengan frontend html & javascript, backend silex & propel Debugging dengan XDebug sangat membantu, daripada memakai var_dump, print_r dan sebangsanya. Silakan mencoba. Jika anda menggunakan PHPStorm sebagai IDEnya, silakan lanjut ke Part 2. / 24 February 2017 / Alexander Celeste On February 23rd Eric and Alex gave a presentation at their local WordPress user group, MSPWP, on using Docker to mount local copies of WordPress sites for development. They demonstrated editing a site from Visual Studio Code. Finally, they covered getting started with debugging using XDebug in VS Code. Only a week and a half before they gave their presentation they first began experimenting with Docker, and quickly recognized it as the future for their local development sandboxes of client (and personal) websites. It was recognizing its potential so immediately that led them to want to share their finding with others. The remainder of this post is a reproduction of the tutorial document that they made available after the presentation to the user group (and this post is, for all intents and purposes, their own place to archive it for anyone to find in the future, and they hope for those who find it that it is useful to you). Install DockerTo install Docker go to the Docker download page. An Example docker-compose.ymlThe first part of
our presentation showed how to create a WordPress install using the standard WordPress image. Here is the contents of the
We created a new folder, Run your Docker WordPress SiteIn a Terminal at the folder that contains your Start the Docker container: Hint: You can omit the The first time you run the container it will take longer to start as it downloads and sets up the images specified in your YAML. At this point you should be able to point your browser at To see all the containers Docker is running type the following in Terminal: A Note on the Files for this WordPress InstallAfter running the container once notice that the files for this WordPress installation are all in the To demonstrate this, add a new PHP file named
Save the file, then point your browser to Stopping your DockerTake down the container by running the following in a Terminal at the folder you created above: Or simply quit the Docker app from the menubar; in this case when you relaunch Docker the containers (in this case, your WordPress site and its database) will automatically be ready to use. But to continue with this tutorial, for now leave it running. Install Visual Studio CodeTo install Visual Studio Code go to the Visual Studio Code download page. Installing ExtensionsVisual Studio Code has a number of extensions. To access these go to the Extensions area by clicking the square item at the bottom of items in the lefthand sidebar of the window. You can install whatever extensions you’d like, but for the purposes of this tutorial make sure to install PHP Debug. Opening a folder in Visual Studio CodeGoing back to the top item in the lefthand sidebar (Explorer) a Welcome screen should still be shown. In it select the Open folder… option, and
select your Editing Local FilesOpen up Try your hand at navigating in Visual Studio Code and editing some more by making a change to the Set up XDebugTo set up XDebug in your container we need to modify Change the Note, to find your Mac’s IP Address run the following in Terminal:
You can now restart your container. Using XDebug to Debug PHP in Visual Studio CodeGo to the Debug area by choosing the debug item from the lefthand sidebar (thrd item down). Click on the green Run button, the first time you do this it should give you a menu to choose what kind of debugging to do, select PHP. This will create and open your
To test debugging, add a breakpoint in your Just reload the page in your browser and the debugger should come forward when
your breakpoint gets hit. Look at the variables in the You can also manipulate the page as it loads using the Debug Console (should be towards the bottom of the Visual Studio Code window). For example, you can modify the post title by typing the following into the console and hitting return: The debugger can also be invoked for PHP notices, warnings, and exceptions. It will also let you follow all the way through your theme or plugin files, to parent theme and even core files, should you wish. Copying a Live Site to your ContainerTo copy a live WordPress website to your container you need to both copy the Copy the
If WordPress is installed in a subdirectory, be sure to include that in the path to copy from. Assuming that you’re using something other than To copy the database, in an SSH connection to the live server, first dump the database contents (check in the live
Copy
Then import your backup file:
Yes, this will generate a warning about the idiocy of including the password on the command line, but in this case we don’t really care. To make a fresh backup of the database in your container, just grab it from MySQL:
Further Reading
About the PresentersEric and Alex Celeste do WordPress site management and development as Tenseg LLC. We have clients both locally and across the nation who work in a number of fields. We can be reached at . |