Cannot run the code after I activate the plugin
you can not, and should not be able to write to files directly. You need to use the wordpress filesystem api https://codex.wordpress.org/Filesystem_API which either requires a pre configuration on the site or user manual control. In addition it is just wrong to automatically write anything into wp-config.php as any mistake will bring down the site … Read more