Issues with Apache and Virtual Hosts - apache

I'm, trying to run both MediaWiki and Wordpress on an Apache server. I've got the MediaWiki site set up with a couple of sub-domain Virtual Hosts, so everything is fine there. This is installed at /var/www/html/mediawiki.
I'm trying to install Wordpress on it's own directory, /var/www/wordpress.
In my config file for Wordpress' virtual host, I've got:
<VirtualHost *:80>
ServerName domain.com
ServerAdmin admin#domain.com
DocumentRoot /var/www/wordpress
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<Directory /var/www/wordpress/> AllowOverride All</Directory>
Obviously domain.com is not the domain.
Whenever I visit domain.com, however, it seems to be loading the MediaWiki install from /var/www/html/mediawiki, which is obviously not what I want.
Anyone got any ideas what I'm doing wrong here?

Run apachectl to see all the servers/vhosts running on your server both port 80 and 443
apachectl -S
Also I believe that:
<Directory /var/www/wordpress/> AllowOverride All</Directory>
should be inside of your virtual host block

Related

Apache2 ServerName and ServerAlias not working

On a nearly fresh Ubuntu 20.04 LTS computer, I would like to set up a virtual host on my local machine. So I created a index.html under /var/www/test/ with the following content:
you have entered a test page
I have set up a test.conf file under /etc/apache2/sites-available/
with the following content:
<VirtualHost *:80>
ServerAdmin webmaster#zhihu.com
DocumentRoot /var/www/test/
ServerName zhihu.com
ServerAlias www.zhihu.com
<Directory /var/www/test/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
The localhost is working:
/etc/hosts config is probably working as indicated by ping
ping zhihu.com
PING zhihu.com (127.0.1.1) 56(84) bytes of data.
64 bytes from xxx (127.0.1.1): icmp_seq=1 ttl=64 time=0.045 ms
but browser cannot bring me to the domain which should now be hosted in /var/www/test/.
I have also a2ensite test.conf and a2dissite 000-default.conf and service apache2 reload
So I think the only possible place for error to occur is ServerName and ServerAlias. Why are they not working?
Could you please enable VirtualHost using a2ensite and access site in incognito mode.
Ensure that the ssl certificate for the site includes both example.com and www.example.com
and ServerAlias is set to www.example.com

Hosting another website on linux AMAZON EC2 intance running bitnami wordpress

I have an EC2 instance created with Bitnami wordpress, I am trying to host my other website on the same instance website.tld
I followed the steps on this guide
https://docs.bitnami.com/aws/components/apache/#how-to-create-a-virtual-host
Then I went to "/opt/bitnami/apps/wordpress/conf/httpd-vhosts.conf" and changed it to
<VirtualHost *:80>
ServerName mywordpress.com
ServerAlias mywordpress.com
DocumentRoot "/opt/bitnami/apps/wordpress/htdocs"
Include "/opt/bitnami/apps/wordpress/conf/httpd-app.conf"
</VirtualHost>
<VirtualHost *:80>
ServerName website.tld
ServerAlias www.website.tld
DocumentRoot "/opt/bitnami/apps/website/htdocs"
ErrorLog "logs/website-error_log"
CustomLog "logs/website-access_log" common
</VirtualHost>
<VirtualHost *:443>
ServerName mywordpress.com
ServerAlias www.mywordpress.com
DocumentRoot "/opt/bitnami/apps/wordpress/htdocs"
SSLEngine on
SSLCertificateFile "/opt/bitnami/apps/wordpress/conf/certs/server.crt"
SSLCertificateKeyFile "/opt/bitnami/apps/wordpress/conf/certs/server.key"
Include "/opt/bitnami/apps/wordpress/conf/httpd-app.conf"
</VirtualHost>
I created the empty folders "/opt/bitnami/apps/website/htdocs" for my new website then added an index.html inside htdocs
Then I restarted the apache server
sudo /opt/bitnami/ctlscript.sh restart apache
mywordpress.com works fine as before, but when i try to open website.tld I get this error
Forbidden
You don't have permission to access / on this server.
Am i doing it wrong? is there any other configurations i missed?
What is more confusing is there are httpd-vhosts.conf files inside the apache2 server and inside each folder in the apps/ folder, I am not sure which of all I should be adding my new domain tag into? Following the bitnami docs I edited the one inside apps/wordrpess/config
I am not a server side guy, is there a UI for the apache server that can help me setup the virtual host?
Thank you in advance.
You have to set the permissions for this directory in apache2.conf/ httpd.conf.
<Directory [your path]>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
And set the permissions with chmod 755

Setup Certbot on xampp Apache Ubuntu

I tried to setup a SSL certificate with: https://certbot.eff.org/lets-encrypt/ubuntuxenial-apache documentation.
It worked, the only problem was that it's on the wrong Apache server. I got 2 Apache server's on my Ubuntu 16.04 System. 1 is linking to /var/www/html and the other one (this one is of my XWAMPP server) is linking to /opt/lampp/htdocs
The Apache server that links to /var/www/html on this one the SSL is activated. With the command: sudo certbot --apache
I want it to be activated on the Apache server of the XAMPP. How can I edit this command so it calls the other Apache server?
I solved this with next steps:
(*) First of all, you should be avaible certbot command and your virtualhost should be configured for the domain that you need https. f.e. mydomain.com. verify the domain is avaible in your browser.
sudo yum install certbot python2-certbot-apache
certbot --apache-ctl /opt/lampp/bin/apachectl
This, create the cert, in /etc/letsencrypt/live/mydomain.com/.
Also, step 2 create a new vhost file in /opt/lampp/etc/extra/. please review.
then, add this new file in your vhost zone (/opt/lampp/etc/httpd.conf).
restart your xampp apache.
It will work but for this you need and static ip and portforward 80 and 443 to your system ip and link with domain you can try no-ip they will give you free domain after that you need to visit https://www.sslforfree.com/
after this follow the step they say. After verifying you can download the ssl file. you need to put extract file in C:\xampp\apache\conf
after this goto C:\xampp\apache\conf\extra
and edit httpd-vhosts.conf and following thing you can change according to your domain or root directory
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host2.example.com
DocumentRoot "C:/xampp/htdocs/dummy-host2.example.com"
ServerName dummy-host2.example.com
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>
<VirtualHost *:443>
ServerAdmin webmaster#osticket.dev
DocumentRoot "C:/xampp/htdocs/upload"
ServerName osticketamcat.ddns.net
ServerAlias osticketamcat.ddns.net
SSLEngine on
SSLCACertificateFile "C:\xampp\apache\conf\ssl\ca_bundle.crt"
SSLCertificateFile "C:\xampp\apache\conf\ssl.crt\server.crt"
SSLCertificateKeyFile "C:\xampp\apache\conf\ssl.key\server.key"
ErrorLog "logs/dummy-host.example.com-error.log"
CustomLog "logs/dummy-host.example.com-access.log" common
<Directory "C:/xampp/htdocs/upload">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order Deny,Allow
Allow from all
Require all granted
</Directory>
I solved this issue.
sudo certbot --apache-ctl /opt/lampp/bin/apachectl
sudo nano /opt/lampp/etc/httpd.conf
------------
# Virtual hosts
Include etc/extra/httpd-vhosts.conf
Include etc/extra/httpd-vhosts-le-ssl.conf #Add it here

Virtual Host on CentOS5

I'm trying to add a new virtual host to a CentOS 5 box.
I've added a new section in virtualhost.conf matching existing entries:
<VirtualHost ip address:80>
ServerAdmin email#email.com
DocumentRoot /home/stuff/public_html
ServerName stuff.stuff.com
ErrorLog /var/log/httpd/stuff.stuff.com-error_log
CustomLog /var/log/httpd/stuff.stuff.com-access_log combined
<Directory /home/stuff/public_html>
Options All
AllowOverride All
</Directory>
<IfModule mpm_itk_module>
AssignUserId stuff stuff
</IfModule>
</VirtualHost>
I then do a reload using the command: /etc/init.d/httpd reload
I've put a placeholder index.php in the directory, and would expect to see an "it works" when visiting the domain, but instead Chrome shows "ERR_NAME_NOT_RESOLVED"
What steps am I missing here? (I'm used to working in a windows environment, this is my first real encounter with CentOS)
Resolved this as a DNS issue, resolved locally editing hosts to match the IP.

What is wrong with this apache2 configuration?

I want to set up apache2 so that the wordpress website is served via port 80 and some other php website served via port 8080. This is on my local machine running Ubuntu 15.10.
The sites-available/000-default.conf contains:
Listen 80
Listen 8080
NameVirtualHost *:8080
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
<Directory /var/www/html/>
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:8080>
DocumentRoot /var/www/php-website
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
When I enter localhost into the browser, I get the Wordpress website. When I enter localhost:8080, I get (redirected it seems to) localhost.
What could be wrong here? I though there might be something wrong with the second VirtualHost config so it's defaulting to the first, so I changed their order. Same thing happened however.
It could be a problem with wordpress configuration. I think wordpress uses wordpress adress (url) or site adress (url) to redirect if you are in another domain. So you should configure this adresses to localhost and localhost:8080.
It was a browser issue. Chrome and Firefox were automatically changing the URL to localhost. It works with curl and in Incognito/Private modes.