All we need is an easy explanation of the problem, so here it is.
I’m getting this error after putting my file inside html directory and I’m confused about this setting. I think I have to open the index.php
file, but I’m getting a 500 error. Let me know about any error you notice please.
This is data from /etc/apache2/sites-available/fullstack1.conf
:
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName www.fullstack1.xyz
ServerAlias fullstack1.xyz
DocumentRoot /var/www/html/fullstack1
<Directory /var/www/html/fullstack1/public/>
DirectoryIndex index.php
AllowOverride All
Require all granted
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
LogLevel warn
</VirtualHost>
This is data from /etc/apache2/apache2.conf
:
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
How to solve :
I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.
Method 1
Looks like you have a couple of items to look at in the fullstack1.conf
file:
-
Your
DocumentRoot
should point to the directory that visitors to the site will start from which, based on the<Directory>
entity, should be:/var/www/html/fullstack1/public
-
The final slash in the
<Directory>
entity is unnecessary:<Directory /var/www/html/fullstack1/public>
-
If you are running a modern version of Apache, these two lines can be removed from the
<Directory>
entity:Order allow,deny Allow from all
These permission statements are now handled with the
Require
statements. -
If Apache does not know what to serve when people visit the bare domain, it will default to showing the directory structure or present an error. As you’re running a PHP-based site, you can add this line immediately after
DocumentRoot
:DirectoryIndex index.php index.html index.htm
This will look first for
index.php
in the/public
directory and fail first toindex.html
if the PHP file does not exist, then toindex.htm
.
Once these items are taken care of, restart (or reload) the Apache server:
sudo service apache2 restart
This should give you what you need 👍🏻
Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0