I recently upgraded to the latest version of PHP (before this everything was working) and had the following virtual host configuration file under /etc/apache2/sites-enabled/local.events
<VirtualHost *:80>
ServerName events.local
DocumentRoot "/home/john/development"
<Directory "/home/john/development">
AllowOverride All
</Directory>
</VirtualHost>
However instead of running my website located under /home/john/development when I go to http://local.event/ it runs the file located at /var/www/index.html. How do I fix this and also why is this the case after I only updated PHP using the following code:
sudo add-apt-repository ppa:ondrej/php5
sudo apt-get update
sudo apt-get upgrade
Change
<VirtualHost *:80>
ServerName events.local
ServerAleas events.local
DocumentRoot "/home/john/development"
<Directory "/home/john/development">
AllowOverride All
</Directory>
</VirtualHost>
2. Need add in /etc/hosts line (127.0.0.1 events.local)
Related
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?
i recently install ubuntu 22.04 and try to use LAMP on it.
but i have problem with VirtualHost.
i want use virtualhosts with a local domain like: test.local
i added this domain to /etc/hosts and add this configuration to my test.local.conf:
<VirtualHost *:80>
ServerName test.local
ServerAdmin webmaster#localhost
DocumentRoot /home/soroush/Sites/test
<Directory "/home/soroush/Sites/test" >
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
and then run: a2ensite test.local.conf
but when i open test.local in my browser, apache show me a 403 error.
Sites/test folder and files have 0777 permission and owner is my username.
what i should to do for fix this problem?
By default, Ubuntu does not allow access through the web browser to
any file apart of those located in /var/www, public_html directories
(when enabled) and /usr/share (for web applications). If your site is
using a web document root located elsewhere (such as in /srv) you may
need to whitelist your document root directory in
/etc/apache2/apache2.conf. The default Ubuntu document root is
/var/www/html. You can make your own virtual hosts under /var/www.
This is different to previous releases which provides better security
out of the box.
To solve the problem:
Move your source code to /var/www
Example: /var/www/site
2.Fix your Virtualhost
<VirtualHost *:80>
ServerName test.local
ServerAdmin webmaster#localhost
DocumentRoot /var/www/site
<Directory "/var/www/site" >
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
Add your user to the apache group then it's working fine
sudo usermod -g www-data <YOUR_USERNAME>
my soluttion was a downgrade to 20.04 ;) sorry if I can't give you a better solution.
I use homestead and Laravel 5.4 and I need to enable sub-domains, in my main windows 10 machine I added a hosts in (C:\WINDOWS\system32\drivers\etc\hosts) record :
192.168.10.10 myapp.dev
192.168.10.10 website.myapp.dev
so this works ok, when I navigate to website.myapp.dev it displays homepage as if I go to myapp.dev, and also my homestead server is apache2 not nginx
In this route when I go to website.myapp.dev I get the expected output (website.myapp.dev) in the log:
Route::get('/', function(Illuminate\Http\Request $request){
\Log::info($request->fullUrl()); // logs website.bikser.dev
});
however my this route is not firing up when I go to website.myapp.dev :
Route::domain('{account}.myapp.dev')->group(function () {
Route::get('/{account}', 'WebsiteController#view');
});
So I need this route to work so I could use sub-domains , I didn't change anything in .htaccess file coz I don't know if I should and also I tried to edit apache2.conf and add this lines:
<VirtualHost *:80>
ServerName myapp.dev
ServerAlias *.myapp.dev
</VirtualHost>
but still my {account}.myapp.dev route does not fire up , pls help
EDIT:
just added this code as was suggested by : #headmax, but when I navigate to myapp.dev it says
NotFoundHttpException , this is the code that I added :
<VirtualHost *:80>
ServerName myapp.dev
DocumentRoot home/vagrant/code/public
<Directory "home/vagrant/code/public/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
#Require local
Require all granted
</Directory>
</VirtualHost>
First change the right of your new doc root :
sudo chown -R $USER:$USER home/vagrant/code/public
Note: The default Apache configuration in Debian 8 requires that each
virtual host file end in .conf.
We copy the default vhost for your own site.conf 000-default.conf
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/myapp.dev.conf
You need to edit the file and add here your virtualhost paste
sudo nano /etc/apache2/sites-available/myapp.dev.conf
We need the simple way look like this :
<VirtualHost *:80>
ServerAdmin admin#myapp.dev
ServerName myapp.dev
ServerAlias www.myapp.dev
DocumentRoot /home/vagrant/code/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Now that we have created our virtual host files, we can enable.
sudo a2ensite myapp.dev.conf
Output: Enabling site myapp.dev. To activate the new configuration,
you need to run: service apache2 reload
Restart Apache
service apache2 reload //to reload configuration
sudo systemctl restart apache2 //to apply the configuration change
Now your are done test the site.
You need a root directory to tell apache where are stored you site files.
Here example myapp.dev is a folder and the public folder are (a child) where public files stored.
<VirtualHost *:80>
ServerName myapp.dev
DocumentRoot home/vagrant/code/public
<Directory "home/vagrant/code/public/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
#Require local
Require all granted
</Directory>
</VirtualHost>
I got a local directory, which will need a DocumentRoot.
When I go to serverip/nivon-zuidholland I must have a DocumentRoot of public.
How would I manage this in apache2 config?
I inserted this in my apache2.conf. I tried to put this into my sites-available/nivon-zuidholland.conf but this doesn't work as well.
I can't restart apache2 because it returns DocumentRoot not allowed here.
<Directory "/var/www/html/nivon-zuidholland">
AllowOverride All
DocumentRoot /var/www/html/nivon-zuidholland/public
</Directory>
In your /etc/hosts add this:
127.0.0.1 nivon-zuidholland.local
Create a directory: /var/www/nivon-zuidholland (set group to www-data)
Create a Virtual host file: /etc/apache2/sites-available/nivon-zuidholland.conf
<VirtualHost *:80>
ServerName nivon-zuidholland.local
ServerAdmin webmaster#nivon-zuidholland.local
DocumentRoot /var/www/nivon-zuidholland
ErrorLog ${APACHE_LOG_DIR}/nivon-zuidholland_error.log
CustomLog ${APACHE_LOG_DIR}/nivon-zuidholland.log combined
</VirtualHost>
Place a symbolic link to this vhost conf file in sites-enabled directory
ln -s /etc/apache2/sites-available/nivon-zuidholland.conf /etc/apache2/sites-enabled/nivon-zuidholland.conf
Restart Apache server: sudo service apache2 restart
You should be able to access the site by going to: http://nivon-zuidholland.local/
I am trying to setup a vhost in ubuntu, my file is like
/var/www/vhost/domain1.com/app
/var/www/vhost/domain1.com/public
/var/www/vhost/domain2.com/app
/var/www/vhost/domain2.com/public
the vhost in /etc/apache2/site-avalable/domain1.com.conf is :
<virtualhost *:80>
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
ServerAdmin webmaster#domain1.com
ServerName domain1.com
ServerAlias *.domain1.com
DirectoryIndex index.php
DocumentRoot /var/www/vhosts/domain1.com/public
LogLevel warn
ErrorLog /var/www/vhosts/domain1.com/log/error.log
CustomLog /var/www/vhosts/domain1.com/log/access.log combined
</virtualhost>
problem
the vhost folder and all the files after that (the children) are accessible in the web browser. I know I have to put some sort of htaccess but i don't know how and where I have to put it.
If you use apache 2.4 and you develop on a local machine:
Create a new configuration file for your website:
$ sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/domain1.com.conf
Edit the file like so:
<VirtualHost *:80>
ServerName domain1.com
ServerAlias *.domain1.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/vhost/domain1.com/public
ErrorLog /var/www/vhosts/domain1.com/log/error.log
CustomLog /var/www/vhosts/domain1.com/log/access.log combined
</VirtualHost>
Enable the website
$ sudo a2ensite domain1.com
Restart apache
$ sudo service apache2 restart
Add the following line to your /etc/hosts file
127.0.1.1 domain1.com
Now it should work, go to http://domain1.com and check it out.