Environment: Ubuntu Server 14.04 Apache2.4
1. Virtual Host Configuration
In apache2.4, the directory of the virtual host is /etc/apache2/sites-available
configured through, by default, Apache has a default virtual host file called 000-default.conf. We will copy the contents of the 000-default.conf file into our new virtual host configuration file.
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/yiidemo.conf
Edit the configuration file to point to the directory you just set.
sudo vim /etc/apache2/sites-available/yiidemo.conf
The edited configuration is as follows (with additional comments removed):
<directory/home/hehongwei/wwwroot> options Indexes followsymlinks allowoverride None require all granted</directory> <virtualhost *:80> ServerName Www.yiidemo.local serveradmin [email protected] documentroot/home/hehongwei/wwwroot ErrorLog ${apache_log_dir}/error.log CustomLog ${apache_log_dir}/access.log combined</VirtualHost>
To restart the Apache server:
sudo service apache2 restart
After you modify the virtual host file, disable the default virtual host configuration (000.default.conf), and then enable the new virtual host configuration as shown below.
000-default.conf (**这一步不是必须的**)sudo a2ensite yiidemo.conf
In this step, the yiidemo.conf
configuration file is activated. His role is to produce a link /etc/apache2/sites-enabled/
to, why do it, because actually apache2 loads all the configuration files in that directory. a2dissite
and with a2ensite
These two actions, we can better manage our virtual hosting.
Restart the APACHE2 server:
sudo service apache2 restart
2. Load rewrite module [hide portal file]
sudo a2enmod rewrite//Open extension
And then modify something:
sudo vi/etc/apache2/sites-enabled/000-default
Modify all of the allowoverride None to allowoverride all.
Ubuntu Server 14.04 Apache2.4 Virtual Host configuration and module override configuration