问题
I have just installed a laravel project into my Home/public_html folder. I gave it a name, let's call it laravel for this purpose. So the template installed to Home/public_html/laravel and then I ran a composer install. I got a database password error. I fixed that, ran it again, and all went well. I then created a migration, a controller, and a view. I tried to navigate to it via localhost/laravel/public/events (events is my created view) I get a 404. I remembered I needed a config file in etc/apache2/sites-available I created the config file with this structure:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /home/user/public_html/laravel/public/
<Directory /home/user/public_html/laravel/public/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/laravel-error.log
CustomLog ${APACHE_LOG_DIR}/laravel-access.log combined
</VirtualHost>
I then created a symlink into the sites-enabled folder. That didn't help.
I then navigated to localhost/laravel and it just gives me the directory structure.
What have I missed? What have I done wrong?
I have another folder inside public_html with its own config file that works perfectly (it points to home/user/public_html/. It also has a symlink. Is there something in each project that tell the project which config to use? Do they just work? My knowledge of this really stops here. Basically, I've exhausted what I know. What am I missing/doing wrong?
Oh and I have restarted apache as well. - a couple of times through the steps I just detailed.
回答1:
Exposing the Laravel instalation to the web server is never a good idea. Since you can access the file listing of the laravel folder, I believe your document root is set to /home/user/public_html.
Better approach to solve this problem will be as follows.
Keep entire laravel installation outside
public_htmldirectory. Let's assume inside/home/user/developmentYou may need to add following to the apache configuration below
DocumentRoot.Alias /laravel /home/user/development/laravel/publicAdd following
DirectoryConfiguration<Directory /home/user/development/laravel/public/> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory>Add following to
.htaccessfile in/home/user/development/laravel/public/belowRewriteEnginerule.RewriteBase /laravel
Restart the apache2 server, your site should be available on localhost/laravel. Make sure there are no folder named laravel inside the public_html folder.
来源:https://stackoverflow.com/questions/23622219/visting-a-laravel-project-with-localhost-via-apache