Add the following code in your htacess file
Options -Indexes will disabled the listing of files on the website.
Make sure .htaccess files is enabled on Apache server.By default .htaccess is disabled.
By Using Apache Virtual Host
If you do not want to create .htaccess files then add the following settings in Apache Virtual Host.
<Directory /var/www/public_html > Options -Indexes </Directory>Finally We need to restart the Apache service after making any changes in Virtual host to apply these changes.
sudo systemctl apache2 restart