How to install LinkAce self-hosted bookmark archive on shared hosting

We are going to install LinkAce on a shared hosting without using the docker. First of all, visit the LinkAce GitHub page and download the zip file. Now upload this zip file to your server and extract it. Then create a .env file and copy the content of .env.example to this file. After that we need to run the following command to generate a secret key for the application and prepare LinkAce for the setup.

php artisan key:generate

But as most of the shared hosting doesn't provide ssh/terminal access, so we need to follow a different approach to generate the secret key. 

Create a new file called generate_key.php and paste the following code to it.

<?php
$key = 'base64:'.base64_encode(random_bytes(32));
$file = __DIR__ . '/.env';

// Check if the .env file exists
if (file_exists($file)) {
    $env = file_get_contents($file);

    // Replace APP_KEY if it already exists, or append it otherwise
    if (preg_match('/^APP_KEY=.*$/m', $env)) {
        $env = preg_replace('/^APP_KEY=.*$/m', 'APP_KEY='.$key, $env);
    } else {
        $env .= "\nAPP_KEY=$key\n";
    }

    file_put_contents($file, $env);
    echo "APP_KEY generated successfully: $key";
} else {
    echo ".env file not found!";
}
?>

Access it through your browser (https://yourdomain.com/generate_key.php). This will generate a key and update the .env file.

Delete the generate_key.php file after use to prevent unauthorized access.

Now create a database and then open the .env file and replace your database's info here. Before we start to install the script, we need to point our web server to /public. For that create a .htaccess file and paste the following code in it and then save it.

RewriteEngine On

# Redirect all requests to the public directory
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L,QSA]

Now open the URL pointing to LinkAce in your browser. The built-in setup should start. Follow the instructions to configure a database and register your user account.

Post Comment

Comments