Fully step by step guide how to debug php by vim+vdebug and xdebug

in utopian-io •  6 years ago  (edited)

Repository

https://github.com/AlanZheng/Tutorial.devel

What Will I Learn?

  • How to recompile vim from source code to enable a feature, such as enable python3
  • How to configure the vdebug for vim.
  • How to configure xdebug and work together with vdebug.

Requirements

Difficulty

  • Intermediate

Tutorial Contents

  1. Verifying vim information by run: vim --version to see its output is +python3 or -python3, plus symbol means this feature enable, otherwise disabled. The default vim distribution disabled python3 on CentOS e17. So we have recompiled the vim from source code to enable it.

    vim_version

  2. Get the vim source code from : https://github.com/vim/vim by below command:

    git clone https://github.com/vim/vim.git
    

    Then changing the directory into vim source code to run ./configure --enable-python3interp=yes, after that just type make command to compile it. if things done you can find the vim executable in src directory, so goes into src directory and run ./vim --version to check again. I believe the output will have +python3 as above picture. Now you can install the new vim to replace the default one.

  3. Get the vdebug source code from https://github.com/vim-vdebug/vdebug.git by below command:

    git clone https://github.com/vim-vdebug/vdebug.git`
    

    Then copy/move its content in your ~/.vim/ directory. You should call :helptags ~/.vim/doc in vim to generate the necessary help tags, after that to run :help vdebug in vim, if you see something like below, that means your vdebug worked well with vim.

    vdebug_doc

  4. Add below code into your ~/.vimrc

    let g:vdebug_options = {}
    let g:vdebug_options["port"] = 7000
    
  5. Configure your xdebug, you should add below code into your php.ini:

    xdebug.remote_enable=1
    xdebug.remote_host=127.0.0.1
    xdebug.remote_port=7000
    xdebug.remote_log="/tmp/xdebug.log"
    

    NOTE: the xdebug's port must same with vdebug's as above.

  6. To create a file phpinfo.php, and put below code in it.

    <?php phpinfo(); ?>
    

    Then to verify if xdebug configure worked well:

    php phpinfo.php | grep xdebug
    
  7. Open a php file by vim, then press F10 to set a break point to cursor line, then press F5 to let vdebug waiting for connection as below.

    vdebug_break

  8. After that to access this php from browser(firefox/chrome), the xdebug should work now, and you will able to see debug status in the vim, more vdebug command you can type :help vdebug in vim.

    vdebug_debug

    If there is anything won't work for your case, please contact me freely.

Refer to:

http://alanzheng.top/doku.php?id=tutorials:php:debug_php_by_vim

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

I thank you for your contribution. Here are my thoughts;

  • Structure

    • Formatting of the post is kinda untidy and images are not showing. I advise you to use markdown language to format.
  • Language

    • Your post contains a large number of complex sentences. They are understandable, but addressing them will both increase your language ability and the efficiency of the post. Here is an example sentence:

      • "To verify if your vim enable python3 by run: vim --version, it will output below information, if you see +python3, that means your vim enabled python3, if you see -python3, that means you need recompile vim from source code to enable python3."

      As you can see, there are multiple sentences in one sentence, separated with commas. Some languages like Turkish support this kind of sentence-crafting and it is quite easy to understand that. But in English, it can result in complex sentences.

  • Content

    • You might consider changing topics to preserve some uniqueness. The concept is generally too simple and similar can be easily found on the internet. Being unique with tutorials on Utopian is not required, but preferable as we value rare posts more than others.

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

@yokunjon, thanks for review and suggestion! I fixed them, please review it again. I write the markdown by Typora, if you know better one, please suggest. :-)

Thank you for your review, @yokunjon!

So far this week you've reviewed 8 contributions. Keep up the good work!