Apache virtual hosts doesn't work - php

I would want to setup virtual hosts, on my apache.
sudo a2enmod vhost_alias -> Module vhost_alias already enabled
i have this 2 files:
/var/www/test/index.php and /var/www/test2/index.php
And i want to load them respectivly
http://test.local/ and http://www.test.local/
or
http://test2.local/ and http://www.test2.local/
my conf file: (/etc/apache2/sites-enabled/000-default.conf)
UseCanonicalName Off
<VirtualHost *:80>
ServerAlias *.local
VirtualDocumentRoot /var/www/%1+
</VirtualHost>
VirtualDocumentRoot /www/hosts/%0/docs
VirtualScriptAlias /www/hosts/%0/cgi-bin
I don't undestand what i'm doing wrong, help me please. I am googling for 2 days but nothing. I have readed http://httpd.apache.org/docs/2.0/vhosts/mass.html but it doesn't help me.
Could you tell me how i should config my files?

Did you add in your /etc/hosts file this lines ?
127.0.0.1 test.local
127.0.0.1 www.test.local
127.0.0.1 test2.local
127.0.0.1 www.test2.local
EDIT
Try with this config:
<VirtualHost *:80>
ServerName test.local
DocumentRoot /var/www/test
<Directory "/var/www/test/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
Until this works try just with one domain, then you will configure the aliases for the others one
Then save this file in /etc/apache2/sites-available/test.local.conf
Then
sudo a2ensite test.local.conf
sudo /etc/init.d/apache2 reload
go to http://test.local

Related

How do I customize an URL for Laravel?

Im on windows 10, trying to customize an url to use Laravel. I dont want to acess the url using public folder on it. Im using wamp and apache is running on port 8080. So I edit the file wamp\bin\apache\apache2.4.23\conf\extra\httpd-vhosts.conf like this:
<VirtualHost *:80>
DocumentRoot c:/wamp/www/
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot c:/wamp/www/laravel_test/blog/public
ServerName laravel_test.dev
</VirtualHost>
After that, I edit the file system32/drivers/etc/hosts with:
127.0.0.1 localhost
127.0.0.1 laravel_test.dev
And when I access the url laravel_test.dev it doesnt work. I tried to use this too on httpd-vhosts.conf:
<VirtualHost *:8080>
And it doesnt work either. I always restart the service on wamp, and nothing changes.
I couldnt install and configure the homestead properly, so im trying to use wamp now. Can somebody help me?
In your httpd.conf file you need to uncomment the virtual Hosts section
Then,
Your vhost needs to listen on port 8080
<VirtualHost *:8080>
ServerName laraveltest.dev
ServerAlias www.laraveltest.dev
DocumentRoot c:/wamp/www/laravel_test/blog/public
<Directory "c:/wamp/www/laravel_test/blog/public">
AllowOverride All
Options Indexes MultiViews FollowSymLinks
Require all granted
</Directory>
</VirtualHost>
For your hosts file
127.0.0.1 laraveltest.dev www.laraveltest.dev

Virtual host redirecting to the xampp folder, but only getting This site can’t be reached

I know I'm probably missing something simple, but I've exhausted all resources trying to get this working.
I'm running my Apache on Port:5000 and trying to direct to lsapp.dev instead of http://localhost:5000/lsapp/public/ with:
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/lsapp/public"
ServerName lsapp.dev
</VirtualHost>
I have tried VirtualHost *:5000 but still can't get it work?
you can use this on command line in your project root
php artisan serve --port=your_port_number
or do this:
edit httpd-vhosts.conf that is located in C:\xampp\apache\conf\extra\httpd-vhosts.conf and add following lines at the end of the file:
# VirtualHost for LSAPP.DEV
<VirtualHost lsapp.dev:80>
DocumentRoot "C:\xampp\htdocs\lsapp\public"
ServerAdmin lsapp.dev
<Directory "C:\xampp\htdocs\lsapp">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
our apache is listening to lsapp.dev connections, but we have to configure our hosts file that allows to redirect lsapp.dev to the localhost that is located in C:\Windows\System32\drivers\etc
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.1 lsapp.dev
Set your Virtual host file like this.
<VirtualHost *:80>
DocumentRoot "D:\laravel Task\laravel\blog" //here set your project storage path
ServerName localhost.test.com // set your url for your project
<Directory "D:\laravel Task\laravel\blog"> // again set your project storage path
AllowOverride All
Order allow,deny
Allow from all
Require all granted
set your hosts file like this
127.0.0.1 localhost.test.com
Now you can Run your project
localhost.test.com
//OR//
If you dont want to use virtual host, then you can run your project like this
goto your project folder=>
command line in your project root=>php artisan serve
your project will run in
http://127.0.0.1:8000/

apache2 multiple virtualhost but only first one works

I am running Apache/2.4.12 on Ubuntu and I added 2 .conf files in the /etc/apache2/sites-available/ folder, and enabled them. Both sites are using the same Symfony PHP files.
aaa.conf
Listen 8080
<VirtualHost *:8080>
ServerName local.aaa.com
ServerAlias www.local.aaa.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/aaa/web
<Directory "/var/www/html/aaa/web">
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/aaa_error.log
CustomLog ${APACHE_LOG_DIR}/aaa_access.log combined
</VirtualHost>
bbb.conf
Listen 8081
<VirtualHost *:8081>
ServerName local.bbb.com
ServerAlias www.local.bbb.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/bbb/web
<Directory "/var/www/html/bbb/web">
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/bbb_error.log
CustomLog ${APACHE_LOG_DIR}/bbb_access.log combined
</VirtualHost>
The problem I am having is that after a service apache2 reload only the first site that I open works. So for example:
1st scenario
- I do the reload
- I open local.aaa.com:8080 it works
- I open local.bbb.com:8081 it doesn't work, I get a PHP Fatal error: Class 'AppBundle\\AppBundle' not found
2nd scenario
- I do the reload
- I open local.bbb.com:8081 it works
- I open local.aaa.com:8080 it doesn't work, I get a PHP Fatal error: Class 'AppBundle\\AppBundle' not found
EDIT
#Ryan Vincent:
netstat -a shows both sites runnnig
All your Listen directives should be in the main apache configuration file provided by Ubuntu(/etc/apache2/apache2.conf).
The sites-enabled folder must only contain the proper symbolic links generated with a2ensite to sites-available, which is where you have to place your virtualhost configurations.
Once you moved them there, enable every virtualhost and reload apache.
sudo a2ensite aaa.conf
sudo a2ensite bbb.conf
sudo service apache2 reload
I had the same problem.
It has been solved by adding a rule on my firewall (UFW).
The ports i use are 18180 and 18181.
Connexion on port 18180 was OK, but not with 18181.
I tried with UFW disabled, but it didn't work, so i decided to add the rules "allow 18181/tcp" and "allow 18181/udp" and the problem is solved.
It's weird it didn't work with UFW disabled, but it's like that lol
I hope this will help

Virtual Host won't run Symfony2

I have Apache2 installed and I have this setup up on my virtual host pointing out to my symfony project.
<VirtualHost *:80>
ServerName topbesterp
ServerAlias www.topbesterp.tld
DocumentRoot /var/www/topbesterp/web/
<Directory /var/www/topbesterp/web/>
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
<Directory /var/www/topbesterp/web/>
Options FollowSymlinks
</Directory>
ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined
</VirtualHost>
I have added the codes up at the end of the apache2.conf.
And these are the things i added for hosts file
127.0.0.1 localhost
127.0.0.1 topbesterp
Whenever I run http://topbesterp on my browser, I receive a blank page.
But whenever I change the Directory of the virtual host to a project that is non-symfony based, it runs okay. Why?
Assuming that you're on LAMP environment so follow the steps below. If MAC then this.
1.
sudo nano /etc/apache2/sites-available/topbesterp.local.conf
<VirtualHost *:80>
ServerName topbesterp.local
ServerAlias www.topbesterp.local
ServerAdmin admin#topbesterp.local
DocumentRoot /var/www/topbesterp/web
<Directory /var/www/topbesterp/web/>
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/topbesterp.local.error.log
CustomLog ${APACHE_LOG_DIR}/topbesterp.local.access.log combined
</VirtualHost>
2.
sudo a2ensite topbesterp.local.conf
sudo service apache2 restart
3.
sudo nano /etc/hosts
127.0.0.1 topbesterp.local www.topbesterp.local
replace /var/www/topbesterp/web/
for
/var/www/topbesterp/web/app_dev.php
or
/var/www/topbesterp/web/app_dev.php
In fact, you don't specify a directory index in your virtual host, try this to get symfony2 first page (app_dev.php is used in development/app.php in production) :
<VirtualHost *:80>
ServerName topbesterp
ServerAlias www.topbesterp.tld
DocumentRoot /var/www/topbesterp/web
<Directory /var/www/topbesterp/web>
DirectoryIndex app_dev.php
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
<Directory /var/www/topbesterp/web/>
Options FollowSymlinks
</Directory>
ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined
</VirtualHost>
As per my comment, you would need to check app/logs/dev.log or app/logs/prod.logdepending on what environment you are running your application.
If you see some writing errors in the cache/logs folder, you'd need to set up the proper permissions to the app/cache/* and the app/logs/* folders.
Alternatively, you can add umask(0000); at the beginning of the following files:
app/console
web/app_dev.php
web/app.php
And you'd be good to go.

Installation of zf2 on LAMP in kali linux?

I tried a lot to run directly through zend.localhost and and got frustrated
I am using xammp in kali linux
but it shows as in pic
I had added this in my httpd-vhost.conf
<VirtualHost *:80>
ServerName zend.localhost
DocumentRoot /opt/lampp/htdocs/zend/public
<Directory /opt/lampp/htdocs/zend/public>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
We will need a little more explanation on your error to help you ...
Did you mapped zend.localhost to 127.0.0.1 (or your ip address) in your /etc/hosts ?

Categories