Apache2 changing localhost directory - apache

I had been install apache2 and php5 and i know that is index.php file in var/www/html/index.php but i want to change it to /home/pc/www/public/index.php and i setup in etc/apache2/sites-available/000-default.conf document root to "DocumentRoot /home/pc/www/public/" here is my conf file:
<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 /home/pc/www/public/
# 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
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
And when i try to get access to localhost in firefox i get this error:
Forbidden
You don't have permission to access / on this server.
Apache/2.4.7 (Ubuntu) Server at localhost Port 80
But when i set DocumentRoot to default directory it works. Please help.

Does the Apache user (usually apache or nobody) have permissions to that directory? Make sure you have at least o+r permissions on the directory.

Solution from OP.
I was need change directory in apache2.conf too.
Here is code what I was need to change in apache2.conf file:
<Directory /home/pc/www/public/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>

Related

Routing problem on my Symfony project on Apache

I looked at different topic regarding my problem but it still doesn't work.
I have just deployed my website in Symfony, on my Debian with Apache.
I manage to go to the main page, but the others return me a 404 error.
I saw that it was necessary to add the .htaccess file for the routing, something that I did but it still does not work.
But when I enter the url: https://myWebsite/index.php/movie it works.
(Tell me if you need more code)
EDIT : on the url https://myWebsite.fr the Symfony Tool Bar doesnt work, the error in the console is : https://mywebsite.fr/_wdt/af9d59
RESOLVED : I added the allowoverride in my HTTPS .conf and its working.
There is my website.conf on my Apache folder "sites-available" :
<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 mywebsite.fr
ServerAdmin webmaster#localhost
DocumentRoot /var/www/project/public
<Directory /var/www/project/public>
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
# 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}/project_error.log
CustomLog ${APACHE_LOG_DIR}/projec_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
RewriteEngine on
RewriteCond %{SERVER_NAME} =mywebsite.fr
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
My second .conf mywebsite-le-ssl for the https (using certbot) :
`
<IfModule mod_ssl.c>
<VirtualHost *:443>
# 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 mywebsite.fr
ServerAdmin webmaster#localhost
DocumentRoot /var/www/mywebsite/public
# 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}/project_error.log
CustomLog ${APACHE_LOG_DIR}/projec_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
RewriteEngine on
# Some rewrite rules in this file were disabled on your HTTPS site,
# because they have the potential to create redirection loops.
# RewriteCond %{SERVER_NAME} =mywebsite.fr
# RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
SSLCertificateFile /etc/letsencrypt/live/mywebsite.fr/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mywebsite.fr/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
`

Different landing pages for the same domain VPS

I have a self-managed VPS server with no control panel running Ubuntu. I managed to point my domain to the server successfully. Then I installed apache2. I created an index landing page in directory:
var/www/gci/
By default system created another directory with default index landing page:
var/www/html/
Then I edited the gci.conf under directory:
/etc/apache2/sites-available/
to include the following lines:
ServerAdmin myemail
DocumentRoot /var/www/html
ServerName burooq.com
The whole file contents is as follows:
<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 myemail
DocumentRoot /var/www/html
ServerName burooq.com
# 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
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
My issue is basically, when I access my domain using http://Burooq.com, it lands on the index page under gci folder. However, when I use https://Burooq.com, it lands on the index page under html folder. How is that possible and how would I point both request to one landing page.

Apache does not pick up default index file when I enter domain name

I installed an ubuntu server 16.04 and LAMP, it works very well and I can load default web by using ip address.
Also I created a new virtual host by domain synappse.ir. If I enter synappse.ir/index.html, it loads the page and there is not any issue but when I enter just the name of the domain without index.php, it can not find or load the index.html file!
Here is my config file for virtual host :
<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 ServerNamei
# 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 nasser.man#gmail.com
ServerName synappse.ir
ServerAlias synappse.ir
DocumentRoot /var/www/synappse.ir
DirectoryIndex index.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
# 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>
Is there any other configuration for enabling this feature?
Sorry, pages were cached, every thing is ok.

Apache2 - Mod_rewrite and .htaccess

I am using Ubuntu 14.04 and apache 2.
Here is my phpinfo file: https://www.vivashost.com/phpinfo.php
Here is my .htacess file:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^feature-pricing-tables.html$ feature.html
Here is my /etc/apache2/sistes-available/000-default.conf file:
<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
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ServerName vivashost.com
Redirect "/" https://www.vivashost.com/
# 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
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
But when i try to open https://www.vivashost.com/feature.html it is giving me 404 error.
I am trying to make a rewrite rule that when you open feature.html apache2 must load the content from feature-pricing-tables.html file.
Where is my mistake, can you please help me out fix this thing ?
Thanks in advance!
This is a very common mistake that is made: You've declared the rule backwards.
Currently, your rule says that if I access feature-pricing-tables.html, then load up the content of feature.html.
Use this instead:
RewriteRule ^feature.html$ feature-pricing-tables.html [L]
Also, the L flag is necessary here - in case you add any other rules, you want to stop processing if there's a match for this rule.

Apache works on localhost but not on server name

As my user id suggests, I am a novice programmer.
I am trying a simple Apache server configuration in ubuntu,
I have created below .conf file in /etc/apache2/sites-available/awesome.conf with below code. Also I have created a symbolic link in /etc/apache2/sites-enable and restarted the Apache.
<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.myawesome.org
ServerAdmin webmaster#localhost
DocumentRoot /var/www/awesome
DirectoryIndex hello.php
# 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
</VirtualHost>
when I access localhost/awesome/hello.php I get the desired text "Hello World".
But when I type www.myawesome.org it dispays below message:
"Server not found"
Any help/guidance is appreciated.
Regards....
You need to edit the hosts file and add the ServerName here pointing to localhost
Open hosts file with:
sudo nano /etc/hosts
...and at the end of this file add:
127.0.0.1 www.myawesome.org