1. install Apache
Ubuntu provides 3 apache2 software packages, which are apache2-mpm-worker, apache2-mpm-prefork, and apache2-mpm-event. If you choose to install the lamp package when installing the Ubuntu operating system entry: Ubuntu Server Installation tutorial, then the installation is apache2-mpm-prefork. If you do not choose to install the lamp package, after installing the system, execute the following command to install the apache2 package, the installation is apache2-mpm-worker:
Sudo apt-Get install apache2
Ii. Configure Apache
In ubuntu, Apache software packages are maintained by the official Ubuntu core development team. When compiling Apache, they only compiled a few modules. If you need other modules, You need to manually add them. This greatly enhances the customization and flexibility of Apache. You can use the apache2-l command to find the modules compiled into apache2.
1. Apache configuration file description
Ubuntu and Debian have made a lot of customization for The apache2 package. The layout of many configuration files is different from that of the original apache2. The configuration files in the/etc/apache2 directory are described as follows:
* Apache2.conf -- global configuration file
* Conf. d/-- this directory stores some general configurations.
* Envvars -- stores environment variables and does not need to be modified.
* Httpd. conf -- User Configuration File
* Mod-available/-- available modules installed in this directory
* Mod-enabled/-- this directory contains enabled modules.
* Ports. conf -- HTTPd service port
* Sites-available/-- available virtual hosts under this directory
* Sites-enabled/-- this directory contains enabled virtual hosts.
Apache2.conf is the main configuration file of apache2. It reads all the directories and files listed above (except the sites-available Directory, because Apache does not need to know which virtual hosts are available, it only needs to load the enabled virtual hosts .)
2. Apache module
Few newly installed modules are compiled and loaded by Apache. Many modules must be manually installed or loaded. You can use a2enmod to view available modules and a2dismod to view enabled modules. If the module you want to use has not been installed, but you do not know the exact name of this module in Ubuntu, You can first use the apt-Get search libapache2-mod command to search, find the correct package name, use apt-Get install for installation.
3. default location of Apache webpage files
By default, Apache stores website files in the/etc/WWW directory. By setting the DocumentRoot keyword, you can specify any directory as the root directory of the webpage file. You can also create directories for multiple webpage files, such:
/Var/www/www.aliwo.net
/Var/www/bbs.aliwo.net
......
That is to say, each website has its own folder, which makes the management clearer. In addition, the/var partition must be larger, because MySQL database files, log files, and website log files are stored here.
4. Apache Virtual Machine Settings
Apache supports both domain name-based virtual hosts and IP-based virtual hosts.
Apache2 of ubuntu makes good configuration for providing support for virtual hosts. If your server has only one website, you can use the virtual machine without modifying the configuration. If there are multiple websites, you can copy and modify the configuration file of the defualt virtual host, this allows you to quickly create multiple websites.
Each Apache Virtual Host has a separate configuration file. These VM configuration files are stored in the/etc/apache2/sites-available Directory. The default VM mentioned above is located in this directory. If you access the IP address of the server in the browser, the "IT worker!" page appears !", Indicates that the website is already providing services.
4.1 create a new VM
To create a new website, you need to create a new virtual host. Suppose I want to create a virtual host with the domain name www.aliwo.net:
* Copy the default VM to modify it:
Sudo CP default www.aliwo.net
* Edit www.aliwo.net
Sudo nano www.aliwo.net
The content of www.aliwo.net is as follows:
<Virtualhost *: 80>
Serveradmin webmaster @ localhost
DocumentRoot/var/WWW
<Directory/>
Fcgiwrapper/usr/bin/php5-cgi. php
Options execcgi symlinksifownermatch
AllowOverride none
</Directory>
<Directory/var/www/>
Options indexes followsymlinks Multiviews
AllowOverride none
Order allow, deny
Allow from all
</Directory>
ScriptAlias/cgi-bin // usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride none
Options + execcgi-Multiviews + symlinksifownermatch
Order allow, deny
Allow from all
</Directory>
Errorlog/var/log/apache2/error. Log
# Possible values include: Debug, info, notice, warn, error, crit,
# Alert, emerg.
Loglevel warn
Customlog/var/log/apache2/access. Log combined
Alias/doc/"/usr/share/doc /"
<Directory "/usr/share/doc/">
Options indexes Multiviews followsymlinks
AllowOverride none
Order deny, allow
Deny from all
Allow from 127.0.0.0/255.0.0.0: 1/128
</Directory>
</Virtualhost>
After modification:
<Virtualhost *: 80>
Serveradmin aliwo@qq.com
Servername www.aliwo.net
Serveralias aliwo.net
DocumentRoot/var/www/www.aliwo.com
<Directory/>
Fcgiwrapper/usr/bin/php5-cgi. php
Options execcgi symlinksifownermatch
AllowOverride none
</Directory>
<Directory/var/www/www.aliwo.com>
Options followsymlinks Multiviews
AllowOverride all
Order allow, deny
Allow from all
</Directory>
ScriptAlias/cgi-bin // usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride none
Options + execcgi-Multiviews + symlinksifownermatch
Order allow, deny
Allow from all
</Directory>
Errorlog/var/log/apache2/error. Log
# Possible values include: Debug, info, notice, warn, error, crit,
# Alert, emerg.
Loglevel warn
# Logs
Customlog/var/log/apache2/access. Log combined
Alias/doc/"/usr/share/doc /"
<Directory "/usr/share/doc/">
Options indexes Multiviews followsymlinks
AllowOverride none
Order deny, allow
Deny from all
Allow from 127.0.0.0/255.0.0.0: 1/128
</Directory>
</Virtualhost>
4.2 start www.aliwo.net
Sudo a2ensite www.aliwo.net
Disable default (prohibit access by IP addresses ).
Sudo a2dissite default
5. Create a website directory
# Cd/var/WWW
# Mkdir/var/www/www.aliwo.net
Upload the webpage file to the directory.
6. Restart apache2 to activate the website:
Sudo/etc/init. d/apache2 restart
If you want to create a new website, copy the configuration file of the Virtual Machine www.aliwo.net and modify the servername and website directory path.