Menu

Secrets on Shared Hosting: Keeping My RapidAPI Key in a .htaccess-Blocked config.php
πŸ“°

Secrets on Shared Hosting: Keeping My RapidAPI Key in a .htaccess-Blocked config.php

DEV Community: phpΒ·Mobeen AhmedΒ·5 days ago
#VOfFyxsQ
#devto#dev#file#server#request
Reading 0:00
15s threshold

When I rebuilt ramrom.io as plain PHP for shared hosting, I hit a problem that has nothing to do with downloading videos: where do you put an API key on a host that gives you no environment variables, no secrets manager, and no shell?

The downloader talks to RapidAPI, and every request needs the key in a header. If it leaks, someone else burns my quota, and on a free tier that quota is the whole budget. So my rule was simple: the key must never reach the browser, never appear in a file the web server will serve as plain text, and never be typed into anything I might screenshot.

Shared hosting took the usual answers off the table. There is no .env loader and no place to set a server environment variable that survives a restart. So I did what PHP developers have done for twenty years: I put the key in a plain PHP file, and then I made sure nobody can read that file over the web.

The file is api/config.php , and it does almost nothing:

<?…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.