Apache - Run site under sub directory (?) - apache

I'm sure it's been answered, but I'm failing to find the right search terms to find the solution.
I have a site (mysite.com) running in Apache, this is working great:
<VirtualHost mysite.com:80>
ServerName www.mysite.com
ServerAlias *.mysite.com
DocumentRoot /var/www/mysite
</VirtualHost>
I would like to run this site one level up in the url, something like this: mysite.com/past/2019
I can't get this to work by modifying the ServerName or ServerAlias values.

For this firstly you have to enable the apache2 rewrite module. You can enable this by running the command 'sudo a2enmod rewrite' after this add below line to your apache2 vhost
<Directory /var/www/mysite>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
Then restart your apache2 server by running command sudo service apache2 restart
Hope it works for you.

Related

Apache VHost not working but seems to be configured correctly: Mac Os Ventura

The Problem
I've been trying to setup apache on my mac. I installed apache using brew and everything seems to work except when I actually try to navigate the url with my browser.
Anytime I navigate to http://parenting.localhost/ I just get a 404 error. To make things even more odd, if I just go to http://localhost/ (not using the vhost) it still writes the logs to the vhost log files. Clearly something is wrong, I just can't figure it out. Any help would be appreciated.
My Environment
My /usr/local/etc/httpd/extra/httpd-vhosts.conf:
<VirtualHost *:80>
ServerName parenting.localhost
ServerAlias parenting.localhost.com
DocumentRoot "/Users/joshteam/PhpstormProjects/parenting/public"
<Directory /Users/joshteam/PhpstormProjects/parenting/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog /Users/joshteam/PhpstormProjects/parenting/storage/logs/error.log
CustomLog /Users/joshteam/PhpstormProjects/parenting/storage/logs/access.log combined
</VirtualHost>
My /etc/hosts:
127.0.0.1 parenting.localhost
127.0.0.1 parenting.localhost.com
I ensure the VHOST is enabled currently:
$ httpd -t -D DUMP_VHOSTS
VirtualHost configuration:
*:80 parenting.localhost (/usr/local/etc/httpd/extra/httpd-vhosts.conf:24)
What I'm Trying To Do
To navigate to http://parenting.localhost/ and for apache to execute the appropriate index.php within the vhost configuration. Instead I get a 404.

Setup vhost for application running on port 8000 from wsl2 ubuntu

I'm trying to setup a vhost for an application running on port 8000 from wsl2 ubuntu.
I went through the following steps.
cd /etc/apache2/sites-available
touch staging-admin.domain.test.conf
added the following configuration
<VirtualHost *:8000>
ServerAdmin admin#server.test
ServerName staging-admin.domain.test
ServerAlias staging-admin.domain.test
<Directory /home/user/env/php7.4/admin/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
DocumentRoot /home/user/env/php7.4/admin/public/
ErrorLog /var/www/html/project/error.log
CustomLog /var/www/html/project/access.log combined
</VirtualHost>
then
sudo a2ensite staging-admin.domain.test.conf
sudo service apache2 reload
sudo a2enmod rewrite
sudo service apache2 restart
and finaly added the following to /etc/hosts
127.0.0.1:8000 staging-admin.domain.test
when I try to open it in the browser
This site can’t be reached staging-admin.domain.test’s server IP address could not be found.
Did I miss something or do something wrong?

Apache 2 Test Page

I dont know why I see this Apache test page when I've configured my virtual host to point to my project?
Server settings
<VirtualHost *:80>
ServerName malltomobiledev.com
DocumentRoot /home/dcms/public/html/dcms/app/web
<Directory "/home/dcms/public/html/dcms/app/web">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
Apache restarted fine, so it was access the folders fine.
My host file
Ip malltomobiledev.com
Any ideas guys?
If you're using apache 2.2, make sure you have NameVirtualHost *:80 set in your main apache config file, otherwise apache will use the default virtual host, which points to the test page.
You can check the configured virtual hosts using apachectl -S

Virtual host & DNS on apacheserver

I was given a DNS-named called xxxx.hosterspace.com to my trial VPS-server located at 111.111.111.111. However, I am having some trouble having that DNS-name as default when I try to enter the server.
Whenever I enter xxxx.hosterspace.com, I end up at 111.111.111.111. I don't know how to fix this, I would like to keep xxxx.hosterspace.com in the addressfield.
This is my apache2.conf
<VirtualHost *:80>
ServerName xxxx.hosterspace.com
DocumentRoot /var/www/mediawiki/
<Directory /var/www/mediawiki>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>
This is my sites-enabled/000-default
<VirtualHost *:80>
ServerName xxxx.hosterspace.com
DocumentRoot /var/www/mediawiki/
<Directory /var/www/mediawiki>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>
Anyone who knows how to set this up? Don't really get any errors when I try to launch it. I have runned sudo service apache2 restart
Looking at the Apache configuration file(s) you've posted, I don't see how the redirect could be happening at the Apache level. It looks like you're running MediaWiki, so you may want to look at its configuration file(s) and ensure that MediaWiki isn't causing the redirect to the IP address.

Apache configuration for Symfony website with virtual hosts

I'm trying to configure my local Apache2 server to host several Symfony websites using virtual hosts, but I just can't make it to alias lib/vendor/symfony/data/web/sf directory as /sf. I see that using %1 and %2 in alias statement is the source of the problem, but I can't find the right solution. I added to /etc/hosts entry 127.0.0.1 jobeet.sandbox.sfdevel, I created in my home directory directory ~/Projekty/sandbox/jobeet. My Apache2 site configuration reads as follows:
<VirtualHost *:80>
ServerName localhost
ServerAlias *.sfdevel
VirtualDocumentRoot /home/alef/Projekty/%2/%1/web
<Directory /home/alef/Projekty/%2/%1/web>
AllowOverride All
Allow from All
</Directory>
Alias /sf /home/alef/Projekty/%2/%1/lib/vendor/symfony/data/web/sf
<Directory /home/alef/Projekty/%2/%1/lib/vendor/symfony/data/web/sf>
AllowOverride All
Allow from All
</Directory>
ErrorLog /var/log/apache2/sfdevel_error.log
LogLevel warn
CustomLog /var/log/apache2/sfdevel_access.log combined
</VirtualHost>
When I change /home/alef/Projekty/%2/%1/lib/vendor/symfony/data/web/sf to /home/alef/Projekty/sandbox/jobeet/lib/vendor/symfony/data/web/sf it works just fine, but I want to use several separate Symfony websites. What changes should I include in my Apache2 configuration?
I'm not sure if you can create aliases this way. There's nothing about it in the apache documentation.
I'd think about removing Alias from your virtualhost definition anyway. Symbolic link will work the same:
cd /home/alef/Projekty/sandbox/jobeet/web
ln -s ../lib/vendor/symfony/data/web/sf