I want to run Apache on my desktop and only accept localhost connections. I am also using Ubuntu 18.04. I am hoping I can achieve this my modifying Apache's configuration file, I don't really want to use IPTABLES.
Open the terminal and edit the file 000-default.conf:
sudo nano /etc/apache2/sites-available/000-default.conf
Then add the following two lines to the block <Directory /var/www/html/>:
Require host localhost
Require ip 127.0.0.1
It should look like this:
<Directory /var/www/html/>
AllowOverride All
# ... other configurations ...
Require host localhost
Require ip 127.0.0.1
</Directory>
Save and exit the file then restart the apache2 service:
sudo systemctl restart apache2
Related
I have a website which I used to deploy in localhost running the command: sudo /etc/init.d/apache2 start and then typing the URL: http://XXX/myfirstphpsite/src where XXX is my IP address and myfirstphpsite/src the repertory containing my website.
However, now I want to type the following URL:
http://pharaohohparis.tld instead of the last URL to deploy in local my website.
For that, I did the following:
I went to the repertory: /etc/apache2/sites-available/ and created a new file named: pharaohofparis.tld.conf in which I inserted:
<VirtualHost *:80>
ServerName pharaohofparis.tld
DocumentRoot /var/www/html/myfirstphpsite/src
<Directory /var/www/html/myfirstphpsite/src>
Options Indexes FollowSymLinks Includes
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I actived the virtual host by typing:
sudo a2ensite pharaohofparis.tld.conf
sudo service apache2 reload
I edited the file /etc/hosts by adding the line:
127.0.0.1 pharaohofparis.tld
However, when I type the URL: http://pharaohofparis.tld, I got the DNS error "DNS_PROBE_FINISHED_NXDOMAIN". How can I fix this ?
EDIT: THE PROBLEM WAS LINUX SUBSYSTEM. THERE WAS NO PROBLEM IS A REAL UBUNTU.
As I said in my Edit above: the problem was apparently Linux Subsystem. There was no problem is a real Ubuntu.
I ma having difficulty setting virtual host after updating ubuntu to 13.10!!
this is what i tried:
Fire up the terminal and type:
sudo a2enmod vhost_alias
If you did not get any error messages and your return looks like below, you are on the right track.
Enabling module vhost_alias.
Run '/etc/init.d/apache2 restart' to activate new configuration!
Next thing to do is to go to sites-available directory by typing
cd /etc/apache2/sites-available/
OK, now we are in apaches directory where all the definition files for virtual hosts are. We want to copy the default template one, cryptically named default
sudo cp default our-test-site
This will create a copy of the default template named our-test-site (you of course should substitute this with anything you wish). Let’s edit it, type
sudo gedit our-test-site
This will open up the file in the editor, below are the contents of default vhost file (as usual YMMV if you did some customization)
ServerAdmin webmaster#localhost
DocumentRoot /var/www
Options FollowSymLinks
AllowOverride None
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
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
Alias /doc/ "/usr/share/doc/"
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
We need to add one line and edit two lines.
Add ServerName our-test-site.local just above the DocumentRoot directive (in front of line 4).
Edit DocumentRoot /var/www path on line 4 and set it to /path-to-the-test-site-WITHOUT-trailing-slash. It should look something like this
DocumentRoot /path-to-the-test-site-WITHOUT-trailing-slash
In case you did not notice my subtle hints, there should NOT be a trailing slash at the end of the path.
Edit path on line 9 and set it to /path-to-the-test-site-WITH-trailing-slash/. It should look something like this
DocumentRoot /path-to-the-test-site-WITHOUT-trailing-slash
In case you did not notice my subtle hints, there SHOULD be a trailing slash at the end of the path.
And there you have it, almost done, the virtual host file is setup. Enable it by typing
sudo a2ensite our-test-site
The response should look like this
Enabling site our-test-site.
Run '/etc/init.d/apache2 reload' to activate new configuration!
At this point the virtual host setup is done, all that is left is to tell the server that our-test-site.local should be resloved to 127.0.0.1. We do that by typing
sudo gedit /etc/hosts
and adding 127.0.0.1 our-test-site.local after the localhost (line 1).
The entire hosts file should look like
127.0.0.1 localhost
127.0.0.1 our-test-site.local
127.0.1.1 ubuntu-vm
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
Save it, close the editor and finally type
sudo /etc/init.d/apache2 restart
or
sudo apache2ctl restart
So there you go, your virtual host is setup, open the browser and type http://our-test-site.local and enjoy.
Update: In case you encounter problems accessing the content of the localhost, you should add the ServerName localhost into your default virtual host (as described above for the new virtual host). Then disable and enable site, and restart the apache
sudo a2dissite default
sudo a2ensite default
sudo /etc/init.d/apache2 restart
Update 2: In your new virtual host file you should change your
AllowOverride None
to
AllowOverride All
for your first two directory nodes (the / one and the one with the path to your site). That will allow all the .htaccess files to work properly and allow redirection.
And of course do not forget to
sudo a2dissite our-test-site
sudo a2ensite our-test-site
sudo /etc/init.d/apache2 restart
The problem was that with Apache 2.4/ubuntu 13.10 and above the sites-available files are like name.conf instead of
sudo cp default our-test-siteof
I did it like so
sudo cp default.conf our-test-site.conf
And so on.
I have various virtual hosts for my web development work, including
cnm. The
sites-available/cnm
my file says very simply:
<VirtualHost *:80>
ServerName cnm
DocumentRoot /var/www/cnm/public_html
</VirtualHost>
I upgraded to Ubuntu 13.10, and when I point my browser to cnm/, I see the
/var/www/index.html file that seems to be indicated in the default file
sites-available/000-default.conf
which says (among other things):
<VirtualHost *:80>
DocumentRoot /var/www
What do I need to do to get Apache to read my cnm document root when I browse to cnm/ ?
NOTES:
I already tried renaming my sites-available/cnm file to sites-available/cnm.conf and enabling it with a2ensite cnm and service apache2 reload. That is a good thing, but it changes nothing.
I already tried changing <VirtualHost *:80> to <VirtualHost cnm.localhost> or to <VirtualHost cnm>. That did nothing.
Ubuntu 13.10 uses apache 2.4, you should check all your apache configuration. But for this present case you should note that a2ensite and a2dissite commands won't be able to see your files in /etc/apache2/sites-available if it does not end with .conf, so rename it to sites-available/cnm.conf and run a2ensite cnm.
Then your Virtualhost definition is certainly better with *:80, it means this virtualhost is activated for all IP interfaces (*) on port 80. cnm.localhost or cnm are not valid values here, only IP numbers (Ip of your apache server) or * for all, and a port number.
Then check how you configuration is read by apache, running theses commands:
# load apache env
# be careful, there is a dot and a space
. /etc/apache2/envvars
# Check apache Virtualhosts config
apache2 -S
You should get something like:
VirtualHost configuration:
*:80 is a NameVirtualHost
default server something (/etc/apache2/sites-enabled/000-default.conf:1)
port 80 namevhost something (/etc/apache2/sites-enabled/000-default.conf:1)
port 80 namevhost cnm (/etc/apache2/sites-enabled/cnm.conf:4)
If it is ok, and if you have the right Ip in your hosts file for cnm, and you can test that with a ping, then using http://cnm/ should use the Virtualhost having cnm in the ServerName.
If you have an answer from the default Virtualhost then it means apache is not finding the name used in your Host header in the list of ServerName and ServerAlias available for that IP/port and fallbacks to the default Virtualhost. If you are really stuck (and you did not forgot to restart) you can always remove the default Virtualhost and keep only the one you are working on.
I found the answer to my issue. I needed to delete the files in /etc/apache2/sites-enabled.
Delete files in /etc/apache2/sites-enabled
Rename config files in /etc/apache2/sites-available to have a .conf ending
For each file in sites-available, run sudo a2ensite mysite.
Run sudo service apache2 reload
I couldn't find any step by step tutorial on how to make it work on my side. I gathered bits and pieces here and there, so for those who need all the steps to follow, here there are:
$ sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/local-mydefault.conf
$ sudo gedit /etc/apache2/sites-available/local-mydefault.conf
Paste the following into the local-mydefault.conf file (Change the path '/your/full/path' to where you want to have your files. And change username to your own username):
# ------------------------------------------------------
<VirtualHost *:80>
ServerName localhost
ServerAdmin webmaster#localhost
DocumentRoot /your/full/path
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /your/full/path>
DirectoryIndex index.php
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Require all granted
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
User username
Group username
# ------------------------------------------------------
Then type the following commands
$ cd /etc/apache2/sites-available/
$ sudo a2ensite local-mydefault.conf
$ sudo a2dissite 000-default.conf
$ sudo /etc/init.d/apache2 restart
I found the answer to this issue:
When upgrading to Ubuntu 13.10, the DocumentRoot does not seem to make a difference.
This is because Apache 2.4 moved the Directory configuration somewhere else. Your old .conf files still have these lines:
DocumentRoot "/var/www/myVhost"
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory "/var/www/myVhost">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
Remove (or comment out) the <Directory> directives so you only have:
DocumentRoot "/var/www/myVhost"
Now reload your settings: service apache2 reload and DocumentRoot is back. :)
Rename the file configuration "cnm" with the extension .conf
mv sites-available/cnm sites-available/cnm.conf
a2ensite sites-available/cnm.conf
And ready!
service apache2 reload
I have the same issue
on way is to disable 000-default and reload apache ,but this isn't the solution becuase you must have just one vhost at a same time :(
sudo a2dissite 000-default.conf
sudo service apache2 reload
I ran into a similar issue. My server name and my FQDN were the same to the default was running into the /var/www/html directory. I disabled the default configuration and my site worked like a breeze. Thanks #regilero.
sudo a2dissite 000-default.conf
fixed it for me.
Hello I have been looking through internet articles forums to solve my issue and so far it has been to no avail. I am trying to set up an Apache virtual host for my FuelPHP development on localhost but I keep getting slammed with the error 403 message. Here is my current setup.
#/etc/apache2/sites-enabled/000-default
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin webmaster#example.com
DocumentRoot "/home/supercomputer/Desktop/PHP/fuelProject/public"
ServerName localhost.home
<Directory "/home/supercomputer/Desktop/PHP/fuelProject/public" >
Options Indexes FollowSymLinks MultiViews Includes ExecCGI
AllowOverride All
Order Allow,Deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
I have pointed my Docroot to the public folder inside my fuelProject. Also to make sure Apache had access to the server files, I set the permissions for all of the files recursively to read, write, and execute just to be a 100% safe. Any clues as to what else could be going wrong?
PS: I am running ubuntu raring (13.04)
PSS: And I am trying to visit localhost.home and localhost.home/index.php. I also get the following warnings upon restarting the server
* Restarting web server apache2 apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[Fri May 03 15:46:58 2013] [warn] NameVirtualHost *:80 has no VirtualHosts
... waiting apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[Fri May 03 15:46:59 2013] [warn] NameVirtualHost *:80 has no VirtualHosts
Here is the correct way of adding Vhost for fuelphp application or any other php application
<VirtualHost *:80>
ServerName localhost.home
DocumentRoot /home/supercomputer/Desktop/PHP/fuelProject/public
ServerAdmin webmaster#localhost
<Directory /home/supercomputer/Desktop/PHP/fuelProject/public>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
And also the below line is not required I dont know why you have added
NameVirtualHost *:80
After doing all above add a host entry to your machine to do that
sudo vi /etc/hosts
add an entry of the virtual host
127.0.0.1 localhost.home
After doing all these things
restart Apache by running
sudo /etc/init.d/apache2 restart
And just load http://localhost.home in your browser you should be able to see your site up and running .
If you still get forbidden error .you need to give permissions to your whole application folder
follow run these commands to do so
sudo chown -R www-data:www-data /home/supercomputer/Desktop/PHP
sudo chmod -R 775 /home/supercomputer/Desktop/PHP
At last add yourself to www-data group
sudo adduser yourUserName www-data
The configuration I posted were working. The problem was with permissions. I had set only my containing fuel project folder to permission 777 but for some reason apache wanted access to almost all the folders containing it. Weird I know but setting all the permissions to 777, it worked. Reading the darn apache log sure helped. If you are having a similar problem, I suggest find the apache log and ACTUALLY READ IT
Testeed on Ubuntu 14.04: I did everything above but I didn't work. I missed to allow access to the directory in my apache2.conf. This is needed if you don't use a standard directory like /var/www or /usr/share/.
<Directory /usr/local/vufind>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
This was mentioned on the4 default PHP site. It's worth reading it!
I'm hosting a couple of webservers. I've set the first one up with no problems. On the second server when I attempt to navigate to it (http://192.168.1.47:99/) I get this error "The requested URL / was not found on this server." I know that the port is being forwarded properly because I can access "http://192.168.1.47:99/phpmyadmin" just fine. I've tried to figure this out for a week or so now and I'm at a loss. Any help would be greatly appreciated!
Ubuntu Linux 10.04
Apache2
php5
I'll provide any additional information that may be needed.
Thanks!
Update - Included config files
* apache2.conf
* httpd.conf
* ports.conf
* sites enabled
we need to change the following lines to /etc/apache2/apache2.conf:
Note :- Change here AllowOverride None to AllowOverride All usingsudo property
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
Now :- Restart your web server
sudo /etc/init.d/apache2 restart
It will work now..
As far as I understand you, you want your server to respond on Port 99. Your configuration is listening on Port 80 instead. Change the following line in sites-enabled:
<VirtualHost *:80>
to
<VirtualHost *:99>
and in ports.conf
NameVirtualHost *:80
to
NameVirtualHost *:99
Restart your apache. That should do it.
If you want to make it work without changing port you can follow these steps
sudo nano /etc/apache2/apache2.conf
and add following line at end
Include /etc/phpmyadmin/apache.conf
then restart apache
/etc/init.d/apache2 restart
Better explain here
https://askubuntu.com/questions/55280/phpmyadmin-is-not-working-after-i-installed-it