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

Organising the plugins folder in wordpress

WordPress has quite narrow expectation for plugin directory structure. It is tightly coupled with loading process and API functions. While I know attempts have been made to make it more flexible, I am not aware of any real breakthroughs or mainstream adoption. As of current state of core I would estimate you would waste more … Read more