How to remove symlink from folder

I have a WordPress installation on a bad server that I want to migrate.

I tried to make a backup via some WordPress plugins, but it was taking forever, generating an enormous zip file.

I asked help from my host support but they haven't replied since.

Looking for a solution I found a www symlink inside the www folder, which is causing the backup to run recursively, re-backing up the entire site again and again, never completing.

I installed the two most known file manager plugins, but both could not delete this symlink, returning an error.

Knowing that I don't have a FTP access, how do I manage to get rid of this symlink?

Is there a plugin that can handle symlinks? Or any way to run a command line to delete this thing?

Topic file-manager backup migration Wordpress

Category Web


I made it, inserted this code in the functions.php file and it worked:

function remove_symlink() {
    $linkfile = 'www'; //symlink to delete
    $old = getcwd(); // Save the current directory
    chdir($_SERVER['DOCUMENT_ROOT']); //Location of the file to be deleted

    if(file_exists($linkfile)) {
        if(is_link($linkfile)) {
            unlink($linkfile);
        } else {
            exit("File exists but not symbolic link\n");
        }
    }
    chdir($old); // Restore the old working directory ;
}

remove_symlink();

Note that you need to change the current working directory (chdir) to the symlink directory you want to delete.

Thanks for the insights!


Do you have any access to the server? SSH access? If you can get to a command line on the server you could try one of these commands. Using sudo would try and run the command as an administrator, so you would need a password:

unlink /path/to/symlink

sudo unlink /path/to/symlink

rm /path/to/symlink

sudo rm /path/to/symlink

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.