Change Laravel base URL from localhost to localhost/laravel5 - apache

I'm trying to change Laravel base URL to localhost/laravel5, I tried to change APP_URL variable in .env file, I did the same changes to this line in config/app.php file:
'url' => env('APP_URL', 'http://localhost/laravel5')
And here my /etc/apache2/sites-available/laravel.conf file:
<VirtualHost *:80>
ServerName localhost/laravel5
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/laravel5/public
<Directory /var/www/html/laravel5>
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I also tried to restart apache2 service, but nothing changes

Make your virtual server like this in apache
<VirtualHost *:80>
ServerName laravel5.app
DocumentRoot /var/www/html/laravel5/public
<Directory /var/www/html/laravel5/public>
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
and run
sudo a2ensite laravel5.app
service apache2 reload
Finally, make sure to edit your /etc/hosts file and add an entry for laravel5.app:
# other entries...
# your entry...
127.0.0.1 laravel5.app
And then you can access your app at http://laravel5.app

I recommend You to use something like Homestead or Valet for developing Check the docs here

Related

virtual host not working in ubuntu 16.04

I'm working on an Ubuntu 16.04 server with Apache and I'm trying to setup 2 virtual host in the local server(192.168.50.200) . The problem is I don't know how to setup the .conf files correctly. i have created two configuration file in the site_available folder, enabled both configuration file using a2ensite command. And the below IP and URL included in the etc/host file
192.168.50.200 test.site1.com
192.168.50.200 test.site2.com
site1.conf
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName test.site1.com/
DocumentRoot /var/www/site1.com
<Directory /var/www>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
site2.conf
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName test.site2.com
DocumentRoot /var/www/site2.com
<Directory /var/www>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
these configuration links are available in the site_enabled folder.
After these configuration i restrated the apache server and also try to reboot the server but no luck.

Apache2 does not serve ServerAlias without www

This is my sites-available/FlaskApp.conf file
<VirtualHost *:80>
ServerName www.mywebsite.design
ServerAlias mywebsite.design
ServerAdmin myemail#gmail.com
WSGIScriptAlias / /var/www/FlaskApp/flaskapp.wsgi
<Directory /var/www/FlaskApp/FlaskApp/>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/FlaskApp/FlaskApp/static
<Directory /var/www/FlaskApp/FlaskApp/static/>
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
www.mywebsite.design works when i open on the browser correctly. However when i go to mywebsite.design the Ubuntu Default "It Works" page shows up.
I followed this tutorial Hosting a FlaskApp
When i tried IPAddress as the Servername like this -
ServerName 139.55.55.55
for some reason the opening the IP address on the browser opens correctly but both www.mywebsite.design or mywebsite.design don't shows the same Ubuntu Default Page
I had mywebsite.design on /etc/hosts like this -
127.0.1.1 mywebsite.design mywebsite
. probably because i named the project that way at some point!
Removed it and just put my name there and it worked!

Apache Virtual Hosts on different domain names AND ports

I use a Ubuntu 16.04 server VM on which I have to configure the following domains:
maindomain.com:80
otherport.com:8080
Each domain pointing to the VM's IP, but to a different directory obviously.
I managed to get bind9 to make these domains point to the VM's IP when the VM is the DNS server, and I configured Apache to get the following results:
Good:
maindomain.com:80 returns maindomain's index
otherport.com:8080 returns otherport's index
Bad:
maindomain.com:8080 returns otherport's index
otherport.com:80 returns maindomain's index
If I put both on port 80, each is separated, but if I do different ports it seems that Apache just cares about the port.
How could I block the access to maindomain.com:8080 and otherport.com:80?
maindomain.com.conf file:
<VirtualHost maindomain.com:80>
ServerAdmin webmaster#localhost
ServerName maindomain.com
ServerAlias www.maindomain.com maindomain.com
DocumentRoot "/var/www/html/maindomain"
<Directory /var/www/html/maindomain>
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
otherport.com.conf file:
<VirtualHost otherport.com:80>
ServerAdmin webmaster#localhost
ServerName otherport.com
ServerAlias www.otherport.com otherport.com
DocumentRoot "/var/www/html/otherport"
<Directory /var/www/html/otherport>
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I managed to get it done, but I think it's more of a dirty hack than an actual solution. I made two more virtual hosts like so :
maindomain.com.trap.conf
<VirtualHost *:8080>
ServerAdmin webmaster#localhost
ServerName maindomain.com
ServerAlias www.maindomain.com maindomain.com
DocumentRoot "/var/www/html/maindomain"
<Directory /var/www/html/maindomain>
Require all denied
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
The other one having the names and port switched.
By the way, I left <VirtualHost *:80> and <VirtualHost *:8080> in the first two .conf files I mentioned in my first post.

Apache web server multiple project folder hosting issue

I have configured /etc/apache2/sites-enabled/000-default.conf as follows .
ServerName 0.0.0.0
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
WSGIDaemonProcess python-app threads=15 maximum-requests=10000
WSGIScriptAlias / /var/www/html/myapp/myapp.wsgi
WSGIProcessGroup python-app
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/html/myapp>
Order deny,allow
Allow from all
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/var/www/html/test"
<Directory "/var/www/html/test">
AllowOverride All
</Directory>
</VirtualHost>
Now my project folder structure is like :
I am able to access myapp (python flask project) . But not my test project html files. Looks like the myapp.wsgi (via flask app) is managing all the urls . url like test\index.html (to access test project) is not configured in flask app and hence getting error.
It worked after updating WSGIScriptAlias /api /var/www/html/myapp/myapp.wsgi. Need to call apis with /api in-front
Initially it was WSGIScriptAlias / /var/www/html/myapp/myapp.wsgi overriding all url mappings.

vHosting on Apache2.2 won't work properly

So, I set up two virtual hosts on my apache and now, I can't access the server via localhost anymore.
Here's my vhosts.conf:
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin webmaster#serv.net.local
DocumentRoot "W:/www"
<Directory "W:/www/">
AllowOverride All
Order Allow,Deny
Allow from all
</Directory>
ServerName serv.net.local
ErrorLog "logs/serv.net.local-error.log"
CustomLog "logs/serv.net.local-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#symfony.net.local
DocumentRoot "W:/www/symfony/web"
<Directory "W:/www/symfony/web/">
AllowOverride All
Order Allow,Deny
Allow from all
</Directory>
ServerName symdev.net.local
ServerAlias symfony.net.local
ErrorLog "logs/symdev.net.local-error.log"
CustomLog "logs/symdev.net.local-access.log" common
</VirtualHost>
All domains are in my hosts-file and are properly resolved. But I can only access the second vHost and get a connection reset error when trying to access localhost or serv.net.local. Same for using 127.0.0.1...
Any ideas whats wrong with this config?
According to discussion in comments, VirtualHost DocumentRoot was not readable because it contained no index, and directory listing was disabled, so fixing it solved the issue.