Can't configure virtual host in apache ubuntu - apache

I've tried to configure virtual host on apache for project on laravel. For this I created file in /etc/apache2/sites-available/app.conf:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName app
DocumentRoot /var/www/html/app/public
<Directory />
Options All
AllowOverride All
</Directory>
<Directory /var/www/html/app/public>
Options All
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
ServerSignature On
</VirtualHost>
Then I've activated the host:
sudo a2ensite app.conf
And had following message in the terminal:
Enabling site app.
To activate the new configuration, you need to run:
service apache2 reload
Then I reloaded it
Also I've modified the '/etc/hosts':
127.0.1.1 Alexandra
127.0.0.1 app
So, now when i go on app/ in browser, it shows me folders of the project:
Index of /
app/
laravel/
project/
site/
Now if I want to display 'welcome page', I should go to app/app/public
Where is mistake in my configuration process?

Your app.conf should be edited to:
DocumentRoot /var/www/html/app/public/app/public
It appears you installed laravel in /var/www/html/app/public/app
UPDATE
You probably have the default site's DocumentRoot set to /var/www/html. If this is the case, then please:
Install laravel in:
/var/www/app
Define it's DocumentRoot as:
/var/www/app/public
Restart apache
sudo service apache2 restart

Related

Error in apache2 server for SSL certificate

So I have purchased an SSL certificate, and need to add it to my Ubuntu running apache2 web service, however for some reason, my .conf file shows me the same error over and over again.
After running the code apache2ctl configtest they mentioned...
AH00526: Syntax error on line 58 of /etc/apache2/sites-enabled/eblossom.conf:
Invalid command 'SSLEngine', perhaps misspelled or defined by a module not included in the server configuration
Action 'configtest' failed.
And in my .conf file...
<VirtualHost *:80>
#ServerName www.example.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
# 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
Alias /static /home/najaaz/eblossom/static
<Directory /home/najaaz/eblossom/static>
Require all granted
</Directory>
Alias /media /home/najaaz/eblossom/media
<Directory /home/najaaz/eblossom/media>
Require all granted
</Directory>
<Directory /home/najaaz/eblossom/eblossom>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIScriptAlias / /home/najaaz/eblossom/eblossom/wsgi.py
WSGIDaemonProcess eblossom python-path=/home/najaaz/eblossom python-home=/home/najaaz/eblossom/venv
WSGIProcessGroup eblossom
</VirtualHost>
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile /home/najaaz/eblossom/eblossom_lk.crt
SSLCertificateKeyFile /home/najaaz/eblossom/eblossom.lk.key
SSLCertificateChainFile /home/najaaz/eblossom/eblossom_lk.ca-bundle
</VirtualHost>
I a using a Django framework and I don't understand where and how this error is caused.
Could anyone help me with this?
Thanks!
Run the following, and try again:
a2enmod ssl && systemctl restart apache2
Basically what this command does is that, it enables mod_ssl.

Apache 2 Forbidden 403 Error despite "Require all granted"

I am getting the apparently infamous apache 2 forbidden error #403, and I tried following the guides on the subject, but none seem to be working.
I am using Ubuntu Server and Apache 2.4.41
My website structure looks like /var/www/html/index.html
My apache2.conf [/etc/apache2/apache2.conf]:
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/html>
Order allow,deny
Allow from all
Require all granted
</Directory>
My vhosts.conf [/etc/apache2/sites-available/000-default.conf]:
<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 webmaster#localhost
DocumentRoot /var/www/html
# 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
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
Require all granted
</Directory>
# 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>
From an Apache standpoint, your configuration seems ok.
Please verify the permissions on your /var/www/html directory. The user that runs Apache should have at least read and traversal (x) permission.
I gave the user running Apache2 permissions to the /var/www/html folder, and was then able to access the website.
Here is a URL with several permissions, I don't know specifically which one was responsible, but I believe it was sudo chmod g+w /var/www/html
https://askubuntu.com/questions/767504/permissions-problems-with-var-www-html-and-my-own-home-directory-for-a-website

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>

Can't get Laravel 4.2 to work / 404

I've tried installing and reinstalling and going through dozens of possible solutions and nothing has worked.
I installed Laravel 4.2 to /var/www/project.
I then created a new virtual host:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/project/public
<Directory /var/www/project/public>
# Don't show directory index
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
And enabled it with:
sudo a2ensite project.conf
And restarted apache2. However, when I go to my domain, all I get is a 404:
Not Found
The requested URL / was not found on this server.
What am I doing wrong?
Fixed.
I had to:
sudo a2dissite 000-default.conf
If you are using Linux, add this
ServerName projectname
below <VirtualHost>
Add the line
127.0.0.1 projectname
to the etc/hosts file. So it should work without having to disable other sites.
Restart your apache and test it with http://projectname.

Can't add subdomain on LAMP VM Instance on Google Compute Engine

I'm trying to add the blog.mydomain.com subdomain in Apache on a Google Cloud LAMP VM Instance.
In the /etc/apache2/sites-available folder there are three files: default, default-ssl, and lamp-server. I assumed lamp-server is the file being used, so I copied this file to blog.mydomain.com and edited the contents to be:
<VirtualHost *:80>
ServerName blog.mydomain.com
ServerAlias blog.mydomain.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/blog.mydomain.com/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/blog.mydomain.com/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
After saving this new file I did sudo a2ensite blog.mydomain.com and then service apache2 reload. After doing this my main website (www.mydomain.com) went down and only would show a page that says "Error establishing a database connection". This message did not come from my application.
What am I doing wrong?
This doesn't make any sense. If you add blog.mydomain.com by issuing a2ensite which creates virtualhost record in sites-available and in sites-enabled which shouldn't impact your original website unless you changes something.
If there is an entry for www.mydomain.com in the virtualhost and its goes to the right folder, you should not get "Error establishing a database connection" I'm guessing this is a wordpress instance.
Make sure your blog.mydomain.com points to the server ip address. Ping it before adding it to the servers web servers configuration.
Also get rid of these lines from the blog.mydomain.com configuration:
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
and restart the web server and load blog.mydomain.com and www.mydomain.com.
The message "Error establishing a database connection" is probably coming from the /var/www/blog.mydomain.com/ directory.