Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
725 views
in Technique[技术] by (71.8m points)

php - Setting document root for Laravel project on Apache virtual host

I inherited a php/Laravel app that was running on an Apache server that I don't have access to. My task is to get it running on another Apache server. I'm pretty good with php but relatively new to Laravel and very new to Apache configuration.

I have figured out how to get the Laravel app running on Apache that is running on an Ubuntu VM (VirtualBox.) I can access the Laravel app in a browser on the Ubuntu VM via http://localhost. I can also access the Laravel app in a browser from the Internet via http://appname.com/public. However, if I just use http://appname.com, then I just get a folder listing of /var/www/appname.

I have tried several modifications to the /etc/apache2/available-sites/appname.conf file but haven't quite got it right yet, apparently. I have also read a number of posts around the nets about making modifications to various other config files including php config files and Apache config files. It seems like these other mods (while they may be workable) shouldn't be necessary.

Here is my current /etc/apache2/available-sites/appname.conf

    <VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName appname.com
        ServiceAlias www.appname.com
        DocumentRoot /var/www/appname/public

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    </VirtualHost>

Any advise is appreciated.

  • Bob
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You need to allow the mod_rewrite in the apache server and allowSymLinks. Source

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName appname.com
    ServiceAlias www.appname.com
    DocumentRoot /var/www/appname/public

    <Directory "/var/www/appname/public">
            Options FollowSymLinks
            ReWriteEngine On
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

in the DocumentRoot Directory i would also allow MultiViews

<Directory "/var/www/appname/public">
        Options FollowSymLinks MultiViews
        ReWriteEngine On
</Directory>

You may need to also do

sudo a2enmod rewrite

to enable module rewrite.

Edit 1:

In my .conf files i got them with the quotes and they are working. Did you enable the modudle rewrite?

Besides some options i also have the "/" folder with the next config.

<Directory "/">
    Options FollowSymLinks
    AllowOverride All
    ReWriteEngine On
</Directory>

and here i'll write my full code of public directory

<Directory "/var/www/appname/public">
        Options FollowSymLinks MultiViews
        Order Allow,Deny
        Allow from all
        ReWriteEngine On
</Directory>

Try it and see if it works, after delete the options that you don't like to use.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...