In this article, we are trying to explain on configuring Laravel-based web application so that it can be deployed in Apache Webserver. In order for a Laravel-based web application to be accessed from certain URL via Web Browser such as Mozila Firefox, Google Chrome by sending request to Apache Webserver, then in order to process the request Apache Webserver needs to be properly configured.
The configuration is needed so that Apache Webserver can understand the incoming request and in the end, Apache Webserver can send the correct output to be rendered which is the intended Laravel-based web application in Web Browser.
The configuration file exists in different path on different operating system. The name of the configuration file itself can also vary depends on the version of Apache Webserver. In the context of the focus of this article is using Ubuntu Linux operating system distribution specifically Ubuntu 16.04 (Xenial Xerus). In this operating system we are using Apache 2.4.18. The location is at /etc/apache2/apache2.conf.
Below is the file which is opened with vim editor through the execution in bash prompt :
Below is the content of the file which is needed to be added :
<VirtualHost *:80> ServerAdmin webmaster@localhost ServerName localhost.test.web ServerAlias localhost.test.web DocumentRoot /var/www/html/laravel-test/public CustomLog /var/www/html/laravel-test/logs/localhost.test.web-access_log combined ErrorLog /var/www/html/laravel-test/logs/localhost.test.web-error_log <Directory /> #Options FollowSymlinks #AllowOverride None Options All AllowOverride All Require all granted allow from all </Directory> <Directory /var/www/html/laravel-test/public > DirectoryIndex index.php Options All AllowOverride All Require all granted allow from all </Directory> </VirtualHost>
After editing the file, Apache Webserver need to be restarted. It is done by executing the command below :
service apache2 restart
If the restart proces or activating the Apache Webserver is successful, it can be accessed by typing the URL specified above in the Apache Webserver configuration file in /etc/apache2/apache2.conf which is http://laravel.test.web.
Remember to add an entry in /etc/hosts in Linux operating sytem or in C:\Windows\System32\drivers\etc\hosts to make an alias or naming alias of an address which is pointing to our local machine since it is only for test or experiment as follows :
The content of /etc/hosts :
127.0.0.1 localhost.test.web # 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
The content of C:\Windows\System32\drives\etc\hosts :
# Copyright (c) 1993-1999 Microsoft Corp. # # This is a sample HOSTS file used by Microsoft TCP/IP for Windows. # # This file contains the mappings of IP addresses to host names. Each # entry should be kept on an individual line. The IP address should # be placed in the first column followed by the corresponding host name. # The IP address and the host name should be separated by at least one # space. # # Additionally, comments (such as these) may be inserted on individual # lines or following the machine name denoted by a '#' symbol. # # For example: # # 22.214.171.124 rhino.acme.com # source server # 126.96.36.199 x.acme.com # x client host 127.0.0.1 localhost 127.0.0.1 localhost.test.web
This is the output of the execution of the URL in the Web browser as follows :