I have a VPS with apache2 installed and I would like to access some PHP projects without a domain name just with the IP address. For example:
http://162.243.93.216/projecta/index.php http://162.243.93.216/projectb/index.php
I have other projects with domain like example.com, in my directory /var/www/
/html/ info.php /projecta/ /projectb/ /example/
When I go to
http://162.243.93.216/info.php then /var/www/html/info.php is opened.
My file 000-default.conf
<VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www/html <Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
You sure can! It might or might not be as convenient but you surely can. You can spin up a local/remote web-server and deploy the website to that place. However if you want to put it to good use, a domain is pretty much a must; It's more of a marketing/usability thing then it's actually required.
There are two types of virtual hosts on Apache: IP-Based Virtual Hosting – every individual website on the Apache Server uses a different, unique IP address. Name-Based Virtual Hosts – enables you to add multiple domains using a single IP address.
" http://162.243.93.216/info.php then /var/www/html/info.php is opened "
I am assuming this already works (If not, uncomment the ServerAlias
line shown in the conf below)
You now want to map
http://162.243.93.216/projecta/
to /var/www/projecta
http://162.243.93.216/projectb/
to /var/www/projectb
For this you need to use the Apache Alias
directive.
000-default.conf
file to:<VirtualHost *:80> # ServerAlias 162.243.93.216 ServerAdmin webmaster@localhost DocumentRoot /var/www/html Alias /projecta /var/www/projecta Alias /projectb /var/www/projectb <Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With