In my ddev container, I configured multiple vhosts in Apache using conf files in sites-available that I added and enabled in the Dockerfile.
In the docs, it is said that we should use $WEBSERVER_DOCROOT which is /var/www/html by default but this value is not available in any custom conf files (apache-site.conf or sites-available files).
So I had to hardcode it and furthermore I had to do this in each conf file because I was unable to define a value for all vhosts and share it.
My Dockerfile :
ADD sites-available/my.site1.tld.conf /etc/apache2/sites-available
RUN a2ensite my.site1.tld
My conf files :
my.site1.tld.conf :
<VirtualHost *:80>
ServerName my.site1.tld
DocumentRoot $WEBSERVER_DOCROOT/my.site1.tld/www
</VirtualHost>
Finally, I could make it work. I had to copy the whole content of apache-site-default.conf from ddev apache configs
to apachesite.conf and append
Define WEBROOT $WEBSERVER_DOCROOT
at the end.
Then in each conf file in sites-available I can retrieve the value as ${webroot}.
I thought that apache.conf was automatically appended to the default conf but it is not the case. I would have preferred to use Macro but I could not succeed (adding RUN a2enmod macro && a2enconf myvhost-macro didn't work).
In DDEV-Local v1.15+, the ability to do multiple docroots with both Apache and Nginx is built-in. There's even an example in the .ddev/nginx_full and .ddev/apache directories showing exactly how to do it.
Related
I install LAMP on my droplet in digital ocean, it did works good but now just tell "this site can't be reached, refused to connection" my IP is 157.230.139.112
My project worked well, however, from one day to the next, that simply appeared. I did not have anything important and decided to delete it and create a new droplet, however the same thing happens, I can make migrations and connect with the bd but only rejects the connection.
I did install composer, all the packages, configure my db and my etc/apache2/sites-enabled/000-default.conf and point to the public folder.
Am I doing something wrong?
Your apache server block might not be pointing to your laravel location correctly.
So, you might try configuring Apahce2 site configuration file for Laravel.
Run the command below to create a new configuration file called laravel.conf
sudo nano /etc/apache2/sites-available/laravel.conf
Copy paste the content below into the file and save it. Remember to replace 'Mywebsite' with your own domain name and directory root location.Remember to point to laravel public folder for security.
<VirtualHost *:80>
ServerAdmin admin#MyWebsite.com
DocumentRoot /var/www/html/MyWebsite/public
ServerName example.com
<Directory /var/www/html/MyWebsite/public>
Options +FollowSymlinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Save the file and exit.
Enable the Laravel and Rewrite Module
Enable the VirtualHost by running ..
sudo a2ensite laravel.conf
sudo a2enmod rewrite
Alternatively, compare your localhost apache serverblock configuration with that on the server, ie. if you are running apache locally
I have a question about a bad practice in Laravel.
I have only one server folder available for Laravel (in IIS).
There, I have the production site.
If I want to add a copy for development and testing against the test database, where must I place it?
Inside the production's version public folder? I donth think because it's unsafe. Sure will be an obvious best practice for that.
You can open a new port for it.
Example:
Config Virtual host with Production site:
Create a configuration file our laravel production project by typing the following commands
cd /etc/apache2/sites-available
sudo nano production.conf
In the production.conf file created paste the following content to the file and close it after saving.
Replace laravelproduction.com with the domain name of your website inside the file.
<VirtualHost *:80>
ServerName laravelproduction.com
DocumentRoot /var/www/html/production/public
<Directory /var/www/html/production>
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Enable the newly created .conf file and disable the default .conf which is pre-created by apache and enable mode rewrite for this to function appropriately. These are the comand to help you do that.
sudo a2dissite 000-default.conf (disable the default .conf file)
sudo a2ensite production.conf (enables the newly created .conf file)
sudo a2enmod rewrite (enables the rewrite)
Also, restart your apache server so that it can pick the changes that you have made by typing this command
sudo service apache2 restart
Config Virtual Host With Dev site
Create a configuration file our laravel dev project by typing the following commands
cd /etc/apache2/sites-available
sudo nano dev.conf
In the dev.conf file created paste the following content to the file and close it after saving.
Listen 8100
<VirtualHost *:8100>
ServerName laraveldev.com
DocumentRoot /var/www/html/dev/public
<Directory /var/www/html/dev>
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Enable the newly created .conf file and disable the default .conf which is pre-created by apache and enable mode rewrite for this to function appropriately. These are the comand to help you do that.
sudo a2ensite dev.conf
Finally restart your apache server so that it can pick the changes that you have made by typing this command
sudo service apache2 restart
This is how I usually use it. I hope to help you. ^_^
I have started working in laravel and using lampp. I have watched many tutorials that use a vhost to make user-friendly url. I want to do it on Ubuntu 16.04.
Following tutorial is not working for me:
https://ourcodeworld.com/articles/read/302/how-to-setup-a-virtual-host-locally-with-xampp-in-ubuntu
<VirtualHost *:80>
DocumentRoot "/opt/lampp/htdocs/basicwebsite/public"
ServerName mywebsite.dev
</VirtualHost>
Setup a virtual host for a Laravel project
First, copy the default configuration file and rename it:
$sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/myVhost
open myVhost.conf file using this command:
$sudo nano /etc/apache2/sites-available/myVhost.conf
Add the directives:
assuming that the Laravel project is in /var/www/html/
ServerAdmin webmaster#localhost
serverName www.myAwesomeLink.com
DocumentRoot /var/www/html/laravel-app/public
<Directory /var/www/html/laravel-app>
AllowOverride All
</Directory>
so now the file will look something like this:
save and close.
Now add an entry in the hosts file:
$sudo nano /etc/hosts
add this line:
127.0.0.1 www.myAwesomeLink.com
save and close.
Enable site and the rewrite mode:
$sudo a2enmod rewrite
$sudo a2ensite myVhost.conf
Restart the server:
$sudo service apache2 restart
Serve the Laravel project:
open the project folder
php artisan serve
this will serve on port 8000 by default
you can also specify the port
php artisan serve --port=4200
Open the browser:
http://www.myAwesomeLink.com:8000
or any other specified port.
Source.
Its not working because the browsers have updated their security terms and policies including SSL certificates over .dev domains. just change your extension from .dev to something else like .localhost or .test.
<VirtualHost *:80>
DocumentRoot "/opt/lampp/htdocs/basicwebsite/public"
ServerName dev.mywebsite.test
</VirtualHost>
Also change the extension in /etc/hosts from .dev to .test.
127.0.0.1 dev.mywebsite.test
Also keep in mind to restart the service to load the new added virtual host i.e: restart the Apache server
Hope it helps.
I think you also need to add a host in /etc/hosts. Open the hosts file and add this line:
127.0.0.1 mywebsite.dev
You will need to restart server after this.
1.Create new file under this path /etc/apache2/sites-available/myweb.conf
2.Copy the following to the file
# Indexes + Directory Root.
DirectoryIndex index.php
DocumentRoot /var/www/html/mywebsite/public
ServerName dev.mywebsite.test
<Directory "/var/www/html/mywebsite/public">
Options All
AllowOverride All
Allow from all
</Directory>
3.Run "sudo a2ensite myweb.conf"
4.Add this line "Listen 80" to file "/etc/apache2/ports.conf"
5.Restart apache server
Actually I have many sub folders inside htdocs directory each folder contain an index.php file and have a separate action.
How may I set my domain name so it will be pointing to all of these sub folders?
Lets say i have c:\server\ht docs\folder1, c:\server\ht docs\folder2 and so on. I would like my domain name to act like localhost. When typing www.domain name.com/folder1 it will take me to c:\server\folder1 and so on for all of the folders.
I tried with localhost and it works.
Step 1:
Edit the windows "host" file located in
C:\Windows\System32\drivers\etcas an administrator.
Add the following line in the host file and save it:
127.0.0.1 www.domain_name.com
Step 2:
Open the "httpd-vhosts.conf" file located in
C:\xampp\apache\conf\extra
Add the below lines and save.
<VirtualHost *:80>
ServerName www.domain_name.com
ServerAlias www.domain_name.com
DocumentRoot c:/xampp/htdocs
</VirtualHost>
Now restart apache server using XAMPP Control Panel
You can resolve using VirtualHost configure or redirect URL
All the answers about adding domain to xampp subfolders are missing some steps, so I'll add mine which is more or less complete.
If you've changed httpd.conf or httpd-vhosts.conf files, return them to default. Specifically, in httpd.conf make sure your DocumentRoot points to default location, we will instead use vhosts file to point domains to different subfolders each:
DocumentRoot "/opt/lampp/htdocs/"
<Directory "/opt/lampp/htdocs/>
in httpd.conf file (main apache config) find and uncomment:
#Include etc/extra/httpd-vhosts.conf to: Include etc/extra/httpd-vhosts.conf
in etc/extra/httpd.vhosts file, add your domain and specify its DocumentRoot (That should be one of the folders in htdocs):
<VirtualHost *:80>
ServerAdmin webmaster#example.ge
DocumentRoot "/opt/lampp/htdocs/example-landing-testing"
ServerName example.local
ErrorLog "logs/example.testing-error_log"
CustomLog "logs/example.testing-access_log" common
</VirtualHost>
in your system's hosts file, add the following:
127.0.0.1 example.local
restart apache
no need to restart system
Optional: If you're running xampp in WSL, you will also need to modify windows's hosts file to point to WSL's IP:
Open notepad as administrator
Open file: C:\Windows\System32\drivers\etc\hosts
In wsl terminal instance, run this handy command to get its IP:
ip addr show eth0 | grep 'inet\b' | awk '{print $2}' | cut -d/ -f1
Add IP to hosts file:
172.20.13.40 example.local
Save, no need to restart system
I've got my MAMP setup working with virtual hosts and it's been great. The one problem I have is that localhost doesn't work so long as virtual hosts is enabled. I haven't been able to find out if that's normal behavior or not. Can I make both localhost and virtual hosts work on MAMP?
Yes, this is possible. This will need to added to the vhosts, but it can't be added just like any other... it has to be configured so it's the default vhost. To accomplish this, you need to set up your apache config to allow vhosts, (i'm assuming you've already taken care of that).
Your Vhosts config needs a few things before you start listing Vhosts in order for localhost to work. first a NameVirtualHost directive, then a master vhost (your localhost), followed by your regular vhosts. Apache will attempt to match the provided host against all of your named vhosts, and when it fails, it will serve your default vhost (which is your first listed vhost) by default. In order to accomplish this, I recommend changing 3 files: etc/hosts, apache.conf and vhosts.conf.
In your hosts file, give your machine a name other than localhost on the first line where it sets 127.0.0.1 to localhost:
hosts
127.0.0.1 localhost puededev
then in your apache.conf change your ServerName directive to match the new hostname. This is usually set to 127.0.0.1 or localhost, and typically followed by a Directory directive block with some permissions settings
apache.conf
ServerName puededev
Now in your vhosts, you will set your NameVirtualHosts config, and your default virtual host, followed by your other vhosts:
vhosts.conf
NameVirtualHost puededev
Listen 80
Listen 8080
# list out any other ports you are using
<VirtualHost localhost:*>
ServerAdmin webmaster#example.com
ServerName localhost
DocumentRoot /home/usr/mamp/htdocs
<Directory /home/usr/mamphtdocs>
order deny,allow
Allow from 127.0.0.1
Allow from ::1
</Directory>
</VirtualHost>
It is also possible to use whatever configuration you use now, and create aliases to different application that will work off of virtual hosts. this is how phpmyadmin runs with MAMP, and you'll notice you can still use localhost/phpmyadmin as an accessible path, even though you are likely getting an forbidden/you do not have access error when you just use localhost/ at the moment.
Aliases will depend on whether your installation is set to manage aliases in external files, but you can always define an alias in the apache.conf. You would likely use this method if you want to do something like localhost/sampleapp instead of a vhost set to http://sampleapp/
Alias /sampleapp /path/to/sampleapp
<Directory /path/to/sampleapp>
Order allow,deny
Allow from all
</Directory>
now go to: http://localhost/sampleapp