Catarina Catarina - 1 year ago 88
PHP Question

Apache - 404 Not Found

Good Afternoon,

I'm elaborating a project and I've instaled php,mysql, apache2 in a virtualbox with ubuntu16.04. I'm working locally and I've instaled laravel 5.3, I have an API running and created a new virtual host and placed the

DocumentRoot my_folder/public
ServerName name_virtual_host
. Then I went to my host files and placed a new line: name_virtual_host
. When I place on my browser http://name_virtual_host, the laravel page appears like it is supposed, but when I type in http://name_virtual_host/api, it gives back:

Not Found

The requested URL /api was not found on this server.

Apache/2.4.18 (Ubuntu) Server at name_virtual_host Port 80 it used to
appear JSON.

my virtual Host:

<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName name_virtual_host
DocumentRoot /var/www/my_folder/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

if inside my folder I write the comand

php artisan serve

and put in URL:


, this works.

How can I solve this?
I think that the solution is creating the file .htaccess, but what should I put inside this file(.htaccess)?


Answer Source

Laravel should come with a public/.htaccess file which redirects all requests to index.php (the RewriteRule ^ index.php [L] part).

If you don't have this file, add it. If you already have this file, make sure mod_rewrite is enabled on your apache server (and restart it).

Without it, Apache will look for a file named api in your DocumentRoot when you ask for /api. The request must be sent to index.php, from the laravel documentation:

The public directory contains the index.php file, which is the entry point for all requests entering your application.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download