How to Setup Website Directory (Custom Host) on Centos 7 - linux

I'm trying to figure out how to have the website function after i point the DNS to the server.
by default, (after fresh install of apache, mysql, php) the main server directory is situated at var/www/html so if i upload test html file, via default server ip the html file will show.
i'm trying to setup a custom folder i.e var/www/examplewebsite.com/public_html and then the public_html would function as the go-to folder for when user goes to my website. Multiple websites on one IP (server) would be great too
i found some information from http://bit.ly/1kguprn but i do not see the NameVirtualHost and the paragraph under that.
I'm a newbie to the Centos/Linux environment, any help would be greatly appreciated :)

You have a nice tutorial here: https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-centos-6
Basically, create a folder and an index for testing purposes:
sudo vi /var/www/example.com/public_html/index.html
add the Virtual directive in your apache config file (:
NameVirtualHost *:80
#
# NOTE: NameVirtualHost cannot be used without a port specifier
# (e.g. :80) if mod_ssl is being used, due to the nature of the
# SSL protocol.
#
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#
<VirtualHost *:80>
ServerAdmin webmaster#example.com
DocumentRoot /var/www/example.com/public_html
ServerName www.example.com
ServerAlias example.com
ErrorLog /var/www/example.com/error.log
CustomLog /var/www/example.com/requests.log
</VirtualHost>
Restart apache:
sudo service httpd restart

Check this documentation for Centos 7. They have a nice initial tutorial.
https://www.digitalocean.com/community/tutorials/an-introduction-to-selinux-on-centos-7-part-2-files-and-processes
First, I will recommend to you that check if you have the httpd service installed and active.
sudo service httpd status
if non active
sudo service httpd start
once active
Check the if the ports 80 and 443 (https are active)
sudo netstat -tulnap | grep :80
sudo netstat -tulnap | grep :443
if they are active, test the server. http://yourserverip or https://yourserverip
By default it should go to the apache webserver page.
Once you can see the page. Try to create the initial index.html page in
/var/www/html
vi /var/www.html/index.html
click i for insert
copy the following html
Test
Test web page
In the tutorial, they will explain the rest of the configuration.
#Moderator The tutorial provide a good long material for the reader, I got punish for answer correctly by the moderator. I think the website are long enough to clarify the question and I think copy again the tutorial here is not proper answer.
Also check the next documentation for changes between Apache 2.2 and 2.4
https://linode.com/docs/security/upgrading/updating-virtual-host-settings-from-apache-2-2-to-apache-2-4/
If you have any problems, comment here.

Related

Automatically create a sub-domain for laravel application using wild card dns

I am using laravel5.5 and I'm implementing the wild card dns giving each user their own sub-domain.
In my implementation, I am working on a laptop with windows 10 and a laragon server.
On laragon I setup like this
<VirtualHost *:80>
DocumentRoot "C:/laragon/www/tindahan/public/"
ServerName tindahan.local
ServerAlias *.tindahan.local
<Directory "C:/laragon/www/tindahan/public/">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
and on the host file
127.0.0.1 tindahan.local
127.0.0.1 fil.tindahan.local
127.0.0.1 liz.tindahan.local
On the route
Route::get('/', function () {
$url = parse_url(url()->current());
$domain = explode('.', $url['host']);
$subdomain = $domain[0];
dd($subdomain);
});
So when visiting the fil.tindahan.local or liz.tindahan.local, I got the result
fil and Liz
but if I visit joseph.tindahan.local I got this error
This site can’t be reached
I need to create another sub-domain on the host to make it work.
The question is, how can do it automatically?
when I enter any names as a sub-domain it should be automatically created so that I never do it manually?
As far as I know, the error will resolved in network layer, not from application layer (in this case laravel).
I think you need your own local DNS-Server.
I've used dnsmasq in Linux (ubuntu) and it worked fine.
steps:
apt install dnsmasq
open /etc/dnsmasq.conf with an editor.
add address=/your_domain.loc/127.0.0.1 (it's just an example so you'll need change domain and ip probably).
run sudo systemctl restart dnsmasq to restart the service.
Well, you can test any url from your_domain.loc in your browser and you will not get that error ;)
goodluck

Amazon Linux EC2 installing SSL (no connection)

I spent last 2 days trying to find the solution to my issue.
HTTP works fine http://jackrus.net, but HTTPS won't work.
1.I created an instance on Amazon Linux EC2.
2.Redirected my domain jackrus.net to my public IP
3. Opened listeners 443, 22, 80. (security groups)
4. Followed the instructions from aws documentation from here
5. Checked all permissions
6. apachectl -t - says syntax is fine.
7. Restarted the server. no problem here too.
Here is my ssl.conf
....
....
....
SSLCertificateFile /etc/pki/tls/certs/certificate.crt
SSLCertificateKeyFile /etc/pki/tls/private/private1.key
SSLCACertificateFile /etc/pki/tls/certs/intermediate.crt
...
...
...
The response i get here:
This site can’t be reached
jackrus.net refused to connect.
Try:
Checking the connection
Checking the proxy and the firewall
ERR_CONNECTION_REFUSED
You might need to add your virtual host to your http/config.d file
You can check what vhosts you have running like this:
apachectl -t -D DUMP_VHOSTS
Look up where your config could be
find /etc/httpd -name *.conf
then edit you config with vim or nano or whatever you prefer
vi /etc/httpd/conf/httpd.conf
Add your virtual host ( type i first to insert if in vim)
#Virtual Host added
<VirtualHost *:80>
DocumentRoot "/var/www/html"
ServerName "example.com"
ServerAlias "example"
RewriteEngine on
RewriteCond %{SERVER_NAME} =example
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
to save and exit:
:wq
then try restarting the server.
I also recommend the letsencrypt certbot-auto for a quick solution as it has a debug feature to tell you exactly what the error is. If you are using Letsencrypt then you sould look up the ACMEv1 to v2 upgrade or end of life cycle for ACMEv1

Apache on CentOS issue configuring routing to "Index.html" (uppercase"I")

I have a project being deployed such that an Apache instance is running on CentOS (DMZ) which is due to forward all requests to a TOMCAT instance running behind the firewall. For instance, a request:
www.Example.com
needs to be forwarded to:
HTTP://<servername behind the firewall>:<port number>/Blabla/Index.html
(Note that Index.html has a capital I).
I should note that the whole project required extensive review as it was developed under Windows (case insensitive filenames) but the running environment is Linux, and now all filenames and their references are fully synchronized.
The problem appears to be that it is not possible to configure within Apache to forward requests to Index.html and it converts it to index.html, which does not exist.
I can change all the file names to lowercase, but this will take quite some effort.
Is there any way to force Apache to use as-is what I define (i.e. if lowercase, use lowercase; if uppercase, use uppercase; if mixed, use mixed).
Thanks in advance.
You should be able to use mod_speling from Apache. In your configuration file, simply put:
CheckSpelling On
CheckCaseOnly On
And reload Apache using either:
/etc/init.d/httpd reload
Or if you're using CentOS 7:
systemctl reload httpd
This should now make all the files in your website directory insensitive.
If you're using virtualhosts, you may add this option into it:
DirectoryIndex Index.html
So your virtualhost should be like that :
<VirtualHost *:80>
ServerName website_name
DocumentRoot website_directory
DirectoryIndex Index.html
</VirtualHost>
You can paste it in /etc/httpd/conf.d/mywebsite.conf and reload apache with :
systemctl reload httpd
If you have CentOS/7. For older versions of CentOS use this command:
service httpd reload

PHP files are downloaded by browser instead of processed by apache2 after creating virtual hosts

I created a virtual host in apache2 (LAMP) as shown below and the php files are downloaded by the browser instead of processed by apache. I created an HTML file and it worked.
/var/www/myvirtualhost.com/public_html
ServerAdmin webmaster#localhost.com
DocumentRoot /var/www/myvirtualhost/public_html/
ServerName myvistualhost
Check this question out. It's for Apache on Ubuntu, and you don't specify what system you are on, but maybe you can get a tip from there.
Basically it describe how to install the PHP module for Apache, which is probably not installed if PHP-files are downloaded.

Apache virtual hosts - server ip directing to virtual host instead of /var/www/html

I have set up a linux box mainly for testing and I have got to a stage were apache, mysql and php are running. I followed tutorials on how to set up virtual hosts so I can point domains to it but something strange is happening.
This is my httpd-vhosts.conf file that I have included in my httpd.conf file:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName thedomain.co.uk
DocumentRoot /var/www/thedomain
</VirtualHost>
When I go to thedomain.co.uk it is pointing to the correct place as you'd expect. But when I go to my servers ip, internal or external it is going to the same directory as the virtual host. Could you guys think of any reason that is? I would expect it to go to /var/www/html by default? Oh and I'm running CentOS 6.3
Thanks in advance for any answers!
You have used wildcard to point everything at DocumentRoot /var/www/thedomain
You need to create second listing :
<VirtualHost myotherdomain.co.uk:80>
ServerName myotherdomain.co.uk
DocumentRoot /var/www/myotherdomain
</VirtualHost>
where your other domain is whatver ip and the document root, points to your choise.
The first vhost listing is also used as the default ... so if you were to use localhost it would resolve to whatever is first in list.

Resources