Getting Started: Ubuntu makes Web server with Apache

Source: Internet
Author: User

First, install Apache

Ubuntu offers 3 apache2 packages, which are Apache2-mpm-worker, Apache2-mpm-prefork, Apache2-mpm-event, respectively. If you choose to install the lamp package when you install the Ubuntu OS "Getting Started: Ubuntu Server Installation Tutorial", then install the apache2-mpm-prefork. If you do not choose to install the lamp package, after installing the system, execute the following command to install APACHE2 This package, the installation is Apache2-mpm-worker:
sudo apt-get install apache2

Second, configure Apache
In Ubuntu, the Apache software package is maintained by the Ubuntu official Core Development group. When they compiled Apache, they compiled only a few modules. If you need additional modules, you need to add them manually. This also greatly enhances the customization and flexibility of Apache. You can use the Apache2-l command to find the module that is compiled into the apache2.

1. Apache Configuration file Description
Ubuntu and Debian have made a lot of customizations to the Apache2 package, and many configuration files have different layouts than the original apache2. The following is a description of each of the configuration files in the/etc/apache2 directory:

*apache2.conf--Global configuration file
*conf.d/--This directory holds some general configuration
*envvars--storage environment variables, generally do not need to modify
*httpd.conf--User Configuration Files
*mods-available/--in this directory are the available modules that are already installed
*mods-enabled/--in this directory is a module that is already enabled
Ports for *PORTS.CONF--HTTPD Services
*sites-available/--virtual hosts available in this directory
*sites-enabled/--The directory is a virtual host that is already enabled

which Apache2.conf is the master configuration file for apache2, which reads all the directories and files listed above (except for the sites-available directory, because Apache does not need to know which virtual hosts are available, it only needs to load those enabled virtual hosts. )

2. Apache Module
The newly installed Apache compiler loads a few modules, many modules to be manually installed or loaded. You can use A2enmod to view the available modules and use A2dismod to view the modules that have been enabled. If the module you are using is not yet installed, but you do not know the exact name of the module in Ubuntu, you can search with the Apt-get search libapache2-mod command First, find the correct package name, and then install it with the Apt-get installation.

3, the Apache Web page file default location
By default, Apache places the Web site files in the/etc/www directory. With the DocumentRoot keyword setting, you can specify any directory as the root of the Web page file. You can also create multiple Web page files in the directory, such as:
/var/www/www.aliwo.net
/var/www/bbs.aliwo.net
......
This means that each Web site has its own separate folder, which is more clearly managed. In addition, the/var partition needs to be larger because MySQL database files and log files, as well as Web site log files are saved here.

4. Apache Virtual machine settings
Apache supports both domain-based virtual hosts and IP-based virtual hosts.

Ubuntu's Apache2 is well-configured to provide virtual hosting support. If your server has only one website, basically do not need to modify the configuration, the virtual machine can be used, if there are multiple sites, you can copy the Defualt virtual host configuration file to modify, so that you can quickly build multiple sites.

Each Apache virtual host has a separate configuration file. The configuration files for these virtual hosts are placed in the/etc/apache2/sites-available directory. The default virtual host mentioned above is located in this directory. If you access the server's IP address in the browser, the page "It worker! "Indicates that the site is already serving.

4.1 Create a new virtual host
To create a new Web site, you need to create a new virtual host. Let's say I'm going to create a virtual host with a domain name of www.aliwo.net:
* First copy the default virtual host to be used to modify:
sudo cp default Www.aliwo.net

* Then edit www.aliwo.net
sudo nano www.aliwo.net

Www.aliwo.net content is as follows:

<virtualhost *:80>
ServerAdmin [email protected]
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 [email protected]
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
#日志
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
Also prohibit default (that is, disable IP access).
sudo a2dissite default

5, the establishment of the site Directory
#cd/var/www
#mkdir/var/www/www.aliwo.net
Then upload the Web file to the directory.

6, restart Apache2, effective website:
Sudo/etc/init.d/apache2 restart

Such a site is established, in the future to establish a new site, copy www.aliwo.net This virtual machine configuration file, modify the servername and Site directory path can be.

Source: http://blog.csdn.net/rookieding/article/details/7314054

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.