Apache virtualhost with debian 8 - apache

I would like to configure an apache virtualhost with Debian 8
I have installed apache2
I have create a configuration in sites-available
<VirtualHost *:80>
ServerName wiki.domain.com
ServerAlias wiki.domain.com
DocumentRoot /home/www/htdocs/wiki/
<Directory /home/www/htdocs/wiki/>
Options -Indexes FollowSymLinks
AllowOverride All
</Directory>
ErrorLog /home/www/logs/wiki/wiki_error.log
LogLevel warn
CustomLog /home/www/logs/wiki/wiki_access.log combined
ServerSignature Off
</VirtualHost>
Create a symbolic link in sites-enabled
ln -s /etc/apache2/sites-available/wiki /etc/apache2/sites-enabled/wiki
And reboot apache
/etc/init.d/apache2 restart
This configuration works with Debian 7 but with Debian 8 i am not redirected to my wiki directory when I use my domain wiki.domain.com

Add Require all granted in the directory to allow apache to access to your directory

Here is an easiest and recommanded way to enable a site with apache2:
a2ensite wiki && service apache2 restart

Related

Setup vhost for application running on port 8000 from wsl2 ubuntu

I'm trying to setup a vhost for an application running on port 8000 from wsl2 ubuntu.
I went through the following steps.
cd /etc/apache2/sites-available
touch staging-admin.domain.test.conf
added the following configuration
<VirtualHost *:8000>
ServerAdmin admin#server.test
ServerName staging-admin.domain.test
ServerAlias staging-admin.domain.test
<Directory /home/user/env/php7.4/admin/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
DocumentRoot /home/user/env/php7.4/admin/public/
ErrorLog /var/www/html/project/error.log
CustomLog /var/www/html/project/access.log combined
</VirtualHost>
then
sudo a2ensite staging-admin.domain.test.conf
sudo service apache2 reload
sudo a2enmod rewrite
sudo service apache2 restart
and finaly added the following to /etc/hosts
127.0.0.1:8000 staging-admin.domain.test
when I try to open it in the browser
This site can’t be reached staging-admin.domain.test’s server IP address could not be found.
Did I miss something or do something wrong?

Homestead with subdomains

I use homestead and Laravel 5.4 and I need to enable sub-domains, in my main windows 10 machine I added a hosts in (C:\WINDOWS\system32\drivers\etc\hosts) record :
192.168.10.10 myapp.dev
192.168.10.10 website.myapp.dev
so this works ok, when I navigate to website.myapp.dev it displays homepage as if I go to myapp.dev, and also my homestead server is apache2 not nginx
In this route when I go to website.myapp.dev I get the expected output (website.myapp.dev) in the log:
Route::get('/', function(Illuminate\Http\Request $request){
\Log::info($request->fullUrl()); // logs website.bikser.dev
});
however my this route is not firing up when I go to website.myapp.dev :
Route::domain('{account}.myapp.dev')->group(function () {
Route::get('/{account}', 'WebsiteController#view');
});
So I need this route to work so I could use sub-domains , I didn't change anything in .htaccess file coz I don't know if I should and also I tried to edit apache2.conf and add this lines:
<VirtualHost *:80>
ServerName myapp.dev
ServerAlias *.myapp.dev
</VirtualHost>
but still my {account}.myapp.dev route does not fire up , pls help
EDIT:
just added this code as was suggested by : #headmax, but when I navigate to myapp.dev it says
NotFoundHttpException , this is the code that I added :
<VirtualHost *:80>
ServerName myapp.dev
DocumentRoot home/vagrant/code/public
<Directory "home/vagrant/code/public/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
#Require local
Require all granted
</Directory>
</VirtualHost>
First change the right of your new doc root :
sudo chown -R $USER:$USER home/vagrant/code/public
Note: The default Apache configuration in Debian 8 requires that each
virtual host file end in .conf.
We copy the default vhost for your own site.conf 000-default.conf
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/myapp.dev.conf
You need to edit the file and add here your virtualhost paste
sudo nano /etc/apache2/sites-available/myapp.dev.conf
We need the simple way look like this :
<VirtualHost *:80>
ServerAdmin admin#myapp.dev
ServerName myapp.dev
ServerAlias www.myapp.dev
DocumentRoot /home/vagrant/code/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Now that we have created our virtual host files, we can enable.
sudo a2ensite myapp.dev.conf
Output: Enabling site myapp.dev. To activate the new configuration,
you need to run: service apache2 reload
Restart Apache
service apache2 reload //to reload configuration
sudo systemctl restart apache2 //to apply the configuration change
Now your are done test the site.
You need a root directory to tell apache where are stored you site files.
Here example myapp.dev is a folder and the public folder are (a child) where public files stored.
<VirtualHost *:80>
ServerName myapp.dev
DocumentRoot home/vagrant/code/public
<Directory "home/vagrant/code/public/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
#Require local
Require all granted
</Directory>
</VirtualHost>

Are .htaccess files ignored by default in an Apache setup on Ubuntu 12.04 / 14.04 LTS?

When setting up the most minimal Apache installation possible (which seems to be standard in most tutorials these days) like this...
(on a naked Ubuntu 12.04 / 14.04 LTS)
sudo apt-get install apache2
sudo service apache2 restart
...then .htaccess files (even if they just have a simple deny from all inside) are completely ignored (because the vhost default config has an AllowOverride None inside 12.04 respectivly nothing inside 14.04).
Question
Is this definitly Apache2's standard on Ubuntu 12.04 / 14.04 LTS's or am I just using weird server providers ?
Yes, this is the default configuration of Apache in 14.04 LTS.
My /etc/apache2.conf had this by default:
...
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
...
and the /etc/apache2/sites-available/000-default.conf had this
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to...{removed lengthy text}
#ServerName www.example.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
# Available loglevels..{removed lengthy text}
#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...{removed lengthy text}
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>

Set DocumentRoot on local directory in apache

I got a local directory, which will need a DocumentRoot.
When I go to serverip/nivon-zuidholland I must have a DocumentRoot of public.
How would I manage this in apache2 config?
I inserted this in my apache2.conf. I tried to put this into my sites-available/nivon-zuidholland.conf but this doesn't work as well.
I can't restart apache2 because it returns DocumentRoot not allowed here.
<Directory "/var/www/html/nivon-zuidholland">
AllowOverride All
DocumentRoot /var/www/html/nivon-zuidholland/public
</Directory>
In your /etc/hosts add this:
127.0.0.1 nivon-zuidholland.local
Create a directory: /var/www/nivon-zuidholland (set group to www-data)
Create a Virtual host file: /etc/apache2/sites-available/nivon-zuidholland.conf
<VirtualHost *:80>
ServerName nivon-zuidholland.local
ServerAdmin webmaster#nivon-zuidholland.local
DocumentRoot /var/www/nivon-zuidholland
ErrorLog ${APACHE_LOG_DIR}/nivon-zuidholland_error.log
CustomLog ${APACHE_LOG_DIR}/nivon-zuidholland.log combined
</VirtualHost>
Place a symbolic link to this vhost conf file in sites-enabled directory
ln -s /etc/apache2/sites-available/nivon-zuidholland.conf /etc/apache2/sites-enabled/nivon-zuidholland.conf
Restart Apache server: sudo service apache2 restart
You should be able to access the site by going to: http://nivon-zuidholland.local/

Need help setting up passenger with apache

I'm trying to setup passenger with apache on Fedora 14. The install went ok but I'm unable to configure apache correctly.
I made these changes to the file. I cannot start apache unless I comment out the virtual host portion.
LoadModule passenger_module
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.7/ext/apache2/mod_passenger.so
PassengerRoot
/usr/lib/ruby/gems/1.8/gems/passenger-3.0.7
PassengerRuby /usr/bin/ruby
<VirtualHost *:80>
ServerName localhost
DocumentRoot /home/antarr/pull/public
<Directory /home/antarr/pull/public>
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>
You also need the following two lines in your apache2.conf or in a conditionally loaded, module specific conf file:
PassengerRoot /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.7
PassengerRuby /usr/local/bin/ruby
Instead of modifying httpd-vhosts.conf override DocumentRoot in your httpd.conf
# Override default DocumentRoot with you root
DocumentRoot "/home/antarr/pull/public"
<Directory "/home/antarr/pull/public">
Allow from all
Options -MultiViews
Require all granted
</Directory>
Before restarting server make sure your conf change is reflected
apachectl -S
The Document root should point to your root folder. And restart apache.