You can try using .htaccess & .htpasswd
create file .htaccess & put :
AuthType Basic
AuthName "restricted area"
AuthUserFile /opt/lampp/htdocs/test/.htpasswd # should be you file path & .htpasswd
require valid-user
the above solution for whole directory. if you want for single file than use this in .htaccess
AuthType Basic
AuthName "demo.php" # name of the file for which you want authentication
AuthUserFile /opt/lampp/htdocs/test/.htpasswd #path of the folder
<Files "demo.php">
require valid-user
</Files>
in .htpasswd
test:do43GnYbHanDE #username test & pwd (download)
You can create your .htpasswd password from here