4

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
bcrimmins
  • 135
  • 1
  • 1
  • 13
  • Did you set up your virtual host in hosts file? – Tai Le Mar 09 '18 at 00:18
  • Thnaks. Where would I find that "hosts" file. – bcrimmins Mar 09 '18 at 04:06
  • You can try `sudo gedit /etc/hosts` and write your virtual hosts in that file like this: `127.0.0.1 appname.com` – Tai Le Mar 09 '18 at 04:13
  • Here is my current hosts file. Do I need to add a line for the new app? 127.0.0.1 localhost 127.0.1.1 linuxstudio # The following lines are desirable for IPv6 capable hosts ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters – bcrimmins Mar 09 '18 at 21:55
  • Yes, you need to add a new line: `127.0.0.1 appname.com`, then you restart xampp and it will run – Tai Le Mar 10 '18 at 00:40

2 Answers2

10

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.

Ellesar
  • 341
  • 1
  • 11
  • 1
    Also restart apache after enabling rewrite mod `sudo service apache2 restart` – Angad Dubey Mar 09 '18 at 00:35
  • Thanks. I added those options, disabled then enabled the host, restarted Apache. No change. I noticed that you used quotes around the folder path in the Directory section. Is that required? I haven't seen that in any of the other examples I've come across. Should I try that? – bcrimmins Mar 09 '18 at 04:04
  • @Ellesar, thanks, but that didn't work. It seems like I must be missing something very basic. All I want to do is to re-diect http calls to appname.com to appname.com/public/ – bcrimmins Mar 09 '18 at 22:40
  • Can you show the .htaccess that you have in the project folder. Perhaps the issue comes from there. – Ellesar Mar 09 '18 at 23:25
4

Follow the steps and all will be good and easy,

1). Type following command in terminal

cd /etc/apache2/sites-available

2). Make a new config file

sudo cp 000-default.conf appname.dev.conf

3. Open the new config file and paste the following code

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin yourmail@example.com
        ServerAlias appname.dev
        DocumentRoot /var/www/html/appname/public

        <Directory /var/www/html/appname/public>
           Options -Indexes +FollowSymLinks +MultiViews
            AllowOverride All
            Require all granted
            <FilesMatch \.php$>
               #Change this "proxy:unix:/path/to/fpm.socket"
               #if using a Unix socket
               #SetHandler "proxy:fcgi://127.0.0.1:9000"
            </FilesMatch>
        </Directory>

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

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

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

4). CTRL+x, then press y then press enter and run following command in terminal

sudo a2ensite appname.dev.conf

5). Type following command and edit the /etc/hosts file

sudo nano /etc/hosts

127.0.0.1 appname.dev

press CTRL x then press Enter and type following command

sudo service apache2 restart

6). Now your app will execute on appname.dev successfully.

Shahrukh Anwar
  • 2,544
  • 1
  • 24
  • 24
  • 2
    Note: don't use `.dev` tld when running local applications, since `.dev` tld is like any other tld. Use `development`, `local` etc. – М.Б. Aug 06 '20 at 16:01