0

I followed this guide on installing and using apache, and changed the conf files so that it would serve my project which is located in /home/user/Desktop/app/src/.

The index.php itself is in the php/ folder. these files are in the src folder

Here are the conf files that I have for this project

/etc/apache2/sites-available/chatapp.conf:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName chatapp
    ServerAlias www.chatapp
    DocumentRoot /home/user/Desktop/RT_chatapp/src/
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

/etc/apache2/apache2.conf:

<Directory />
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Require all granted
</Directory>

<Directory /usr/share>
        AllowOverride None
        Require all granted
</Directory>

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        DirectoryIndex index.php index.html
        Require all granted
</Directory>

I am running php 8.2.5 and apache 2.4.41 ps I thought it might be worth mentioning that I am pretty new to web servers using apache and such

I tried adding "index.php" to the directoryIndex as well as modifying the document root to /home/user/Desktop/RT_chatapp/src/php/ instead but that didn't work.

Hemzyy
  • 9
  • 5
  • are you saying the content of `/home/hamza/Desktop/RT_chatapp/src/index.php` isn't showing? – timchessish Jul 10 '23 at 14:38
  • it does but only once I access it by clicking on php/ on the web page. The website works fine, I'm just asking if there's a fix so that when I open http://localhost, the webpage displays the main page directly instead of the "index of /" page as shown in the screenshot – Hemzyy Jul 10 '23 at 14:43
  • and the file is defintely not under src/php/? From the config you've given that's the only thing I can see that would give the effect you are seeing. Is there anyhing else going on (e.g. in the .htaccess) – timchessish Jul 10 '23 at 14:46
  • If you're identifying the site as `chatapp` wouldn't you be better adding that to your hosts file and then accessing it as `http://chatapp`? – timchessish Jul 10 '23 at 14:52
  • the index.php is well under "src/php/". any changes I made to the config has resulted in the website not working at all. (ex changing the document root to "/home/user/Desktop/RT_chatapp/src/php/" resulted in the server loading correctly the index.php but not loading the js and css files that are under "src/js" and "src/css" respectfully. Could you elaborate on the .htaccess part ? – Hemzyy Jul 10 '23 at 14:54
  • the index file should be on the document root. If you have a separate php directory that should only be for files to be included, not those to be directly accessed. DocumentRoot tells the server where to find files directly under / in the url, including any index file. – timchessish Jul 10 '23 at 14:59
  • so you're saying I should just move the index.php outside of the php/ folder and put directly under src/? – Hemzyy Jul 10 '23 at 15:03
  • yes, exactly. Not sure what you're using the php folder for, but it shouldn't be for directly accessed files – timchessish Jul 10 '23 at 15:09
  • I thought it was "good practice" to separate files. but yes it works now, thank you for your answer. – Hemzyy Jul 10 '23 at 15:31
  • glad I could help – timchessish Jul 10 '23 at 15:41
  • Does this answer your question? [How do I disable directory browsing?](https://stackoverflow.com/questions/2530372/how-do-i-disable-directory-browsing) – Nico Haase Jul 10 '23 at 15:46

1 Answers1

-1

as @timchessish said, a very simple fix was to just move the index.php directly under src/ where the DocumentRoot was set to in the config file

Hemzyy
  • 9
  • 5