Ubuntu httpserver installation Configuration

Source: Internet
Author: User
I. Installation

1. Open the terminal and enter "sudo apt-Get install apache2"

2. Verify apache2.0Whether the installation is complete. Open it in the browserHttp: // localhost/or http: // 127.0.0.1.If it works appears! That proves success;

3.Sudo apt-Get install PhP5

4.Sudo apt-Get install libapache2-mod-php5 (my machine installed this by default when installing PhP5, so the prompt has been installed)

5.Sudo/etc/init. d/apache2 restart", Press ENTER;(Restart Apache.) If successful, PHP and apache2 are successfully installed.

6.Sudo apt-Get install mysql-Server", Press ENTER;(This is MySQL installation)

7."Sudo apt-Get install libapache2-mod-auth-mysql", Press ENTER;(This enables Apache and PHP to support MySQL)

8.Enter"Sudo apt-Get install php5-mysql", Press enter (my prompt is as follows:

 
The following software packages have dependencies that are not met: PhP5-MySQL: Dependency: php5-common (=5.4.6-1ubuntu1)5.4.6-1ubuntu1.2Being installed e: the error cannot be corrected because you require some software packages to stay in the status quo, that is, they corrupt the dependency between software packages.

The possible cause is that I used the official Ubuntu source when installing MySQL, but changed it to the 163 source when installing PhP5, because the official website is too busy.

But it still doesn't work. Don't worry about it. Other things are very busy.

9.Enter "sudo/etc/init. d/apache2 restart" on the terminal and press Enter;

 

Ii. Configuration

1. apache2.conf is the main configuration file and the httpd. conf user configuration file.

2.VirtualThe directory is in httpd. conf.

[Plain] View plaincopy

    1. <Virtualhost *>
    2. DocumentRoot "path"
    3. Servername
    4. <Directory "path"> allow from all options + indexes </directory>
    5. </Virtualhost>
    6. <Virtualhost *: 80>
    7. Servername www.test.com
    8. DocumentRoot/home/test
    9. </Virtualhost>

3. Root settings (default main directory) in/etc/apache2/sites-available/Default

4. Restart commandSudo/etc/init. d/apache2 restart or CD/etc/init. d sudo apache2 restart

5. log files are stored in/var/log/apache2/

 

VI/etc/httpd/CONF/httpd. conf

In Windows, there is usually only one configuration file for Apache, that is, httpd. conf. However, after I installed apache2 with the apt-getinstall apache2 command in Ubuntu Linux, I found that its httpd. conf (in the/etc/apache2 directory) is empty! It is found that the configuration file of the Apache package in Ubuntu is not as simple as that in windows. It divides the configuration items into different configuration files. Strictly speaking, the configuration file of Apache In ubuntu (or Apache in Linux) is/etc/apache2/apache2.conf. Apache automatically reads the configuration information of this file at startup. Some other configuration files, such as httpd. conf, are included through the include command. Of course, you can put all the settings in apache2.conf, httpd. conf, or any configuration file. This classification of apache2 is just a good habit.

The most important thing after installing Apache is to know where the web document root directory is. For Ubuntu, the default value is/var/www. How do you know? There is no DocumentRoot entry in apache2.conf, and httpd. conf is empty, so it must be in other files. After searching, it is found that the content in/etc/apache2/sites-enabled/000-default contains the following content:

[Plain] View plaincopy

    1. Namevirtualhost *
    2. <Virtualhost *>
    3. Serveradmin webmaster @ localhost
    4. DocumentRoot/var/www/
    5. ......

This is a virtual host. A virtual host is a technology used to build multiple website services with different domain names or based on different IP addresses on the same machine. You can specify different IP addresses and ports for each website running on the same physical machine, or assign different domain names to multiple websites.For further configuration and use, you can refer to the Apache manual..

Let's take a look at the things in the/etc/apache2 directory. The sites-enabled directory was just found in apache2.conf, and there is a sites-available directory under/etc/apache2, which is the real configuration file, the sites-enabled directory stores only symbolic links to the files here. You can use LS-L/Etc/apache2/sites-enabled/to confirm. Therefore, if multipleVirtual Host. The configuration files of each virtual host are stored in sites-availabl.So it is very convenient to disable and enable a VM: it is enabled when a link pointing to a VM configuration file is established under sites-enabled; to shut down a VM, you only need to delete the corresponding link and do not need to modify the configuration file.

The following two directories are used to store the configuration files and links of the Apache function module. After I installed the PHP module with APT-Get installphp5, The php5.load, php5.conf, and links to the two files are available in these two directories. This directory result is very convenient for enabling or disabling an Apache module.

The last one is ports. conf, where the port used by Apache is set. To adjust the default port settings, we recommend that you edit this file. You can also remove the include/etc/apache2/ports. conf line in apache2.conf and set the Apache port in httpd. conf.

The default directory structure installed in Ubuntu is quite different. In ubuntu, the module and virtualhost configurations both have two directories: available, enabled, and available. The available Directory stores valid content but does not work, it takes effect only when Ln is connected to enabled. Debugging is easy to use, but if you do not know it beforehand, it will be a little troublesome to find it.

The/etc/apache2/sites-available file is configured with the link-to-enabled file but does not work. You must link the file to the sites-enabled directory.


Description of the configuration file httpd. conf

DocumentRoot "/var/www/html" --- Apache default server home directory

Directoryindex index.html index.htm index. php index.html. var --- default document. Multiple files are separated by spaces.
Listen 192.168.1.1: 80 sets the listening IP address to 192.168.1.1 and port to 80.
Listen 192.168.1.2: 8080 set the listening IP address to 192.168.1.2 and port to 8080.

Serverroot "/etc/httpd" sets the path relative to the root directory, usually refers to the place where the configuration files and log files are stored. The default value is/etc/httpd, which generally includes conf and logs subdirectories.

Errorlog logs/error_log Setting Error Log,Note: If the log file storage path does not start with "/", it means that the file is relative to the serverroot directory.
Customlog logs/access_log combined access log(Combined indicates the log format and common format.)

ServeradminC. Z. cz@ 163.com set the email address of the network administrator,When an error occurs on the client server, the server usually returns an error prompt page to the client. To solve the problem easily, this webpage usually has the Administrator's email address, you can use the serveradmin statement to set the Administrator's email address.

Servername www.cz.com: 80 sets the server host name (if there is a domain name, you can enter the domain name, if there is no domain name, you can enter the Server IP address)

Adddefaultcharset UTF-8 sets the default character set, which defines the default character set that the server returns to the client (because the Western European UTF-8 is the Apache default Character Set, garbled characters occur when accessing a Web page with Chinese characters, in this case, you only need to change the character set to gb2312, and then restart the apache service)

VirtualDirectory

Alias/down "/software/download" to create a virtual directory (create a virtual directory named down. Its physical path is/software/download)
Alias/ftp "/var/ftp" create a virtual directory (create a virtual directory named FTP with the corresponding physical path:/var/FTP)

<Directory "/var/www/html"> Set directory permissions (<directory "directory path"> statements for setting directory permissions for this write operation </directory>)
Options followsymlinks page: 116
AllowOverride none
</Directory>

Virtual Host details

Apache Virtual Host is a solution that allows running more than one website on the same machine. There are two types of virtual hosts: IP-based and name-based ). The existence of virtual hosts is transparent to users.

IP-based VM

For IP-based virtual hosts, each virtual host must have a separate IP address. That is to say, your server must have multiple IP addresses. In this way, we can make an experiment locally for configuration. There are two ways to configure an IP-based VM:

One is to start Multiple Apache servers.ProgramEach instance uses a separate configuration file. Generally, two websites are set up on the same machine. The two websites do not want each other to access their own files, each Apache instance is started with a separate user name and group and put in different directories. In this way, you only need to configure different IP addresses for the listen command in the Apche configuration file;

Add listening port in ports. conf

[Plain] View plaincopy

    1. Namevirtualhost *: 80
    2. Listen 80
    3. Namevirtualhost*: 12340
    4. Listen 12340.

Add a new file in sites-available (you can copy the original default and rename it) to define a new site.

[Plain] View plaincopy

    1. <Virtualhost *: 12340>
    2. Serveradmin webmaster @ localhost
    3. Servername wwwtest
    4. DocumentRoot/var/wwwtest
    5. Errorlog/var/wwwtest/log/wwwtest_error.log
    6. Loglevel warn
    7. Customlog/var/wwwtest/log/wwwtest_access.log combined
    8. </Virtualhost>

Add a soft connection to sites-available in sites-enable.

[Plain] View plaincopy

    1. Ln-S/etc/apache2/sites-available/test/etc/apache2/sites-enabled/test

Restart the Apache server.

The second method is to start a single Apache process and use the virtualhost command to configure different values for different sites. In this way, we can perform a local test, because 127.0.0. * All IP addresses are directed to the local machine. Therefore, we can take two of them and configure Apache as follows. Then, in the hosts file, by binding a domain name to the configured IP address, you can run one configuration of multiple WP systems locally:

[Plain] View plaincopy

  1. <Virtualhost 127.0.0.1: 80>
  2. Serveradmin yourname@domain.com
  3. DocumentRoot "/usr/mysite/test1"
  4. Servername site1.com
  5. Serveralias www.site1.com
  6. Errorlog "logs/site1.com-error. log"
  7. Customlog "logs/site1.com-access. log" combined
  8. </Virtualhost>
  9. <Virtualhost 127.0.0.2: 80>
  10. Serveradmin yourname@domain.com
  11. DocumentRoot "/usr/mysite/Test2"
  12. Servername site2.com
  13. Serveralias www.site2.com
  14. Errorlog "logs/site2.com-error. log"
  15. Customlog "logs/site2.com-access. log" combined
  16. </Virtualhost>


Name-based VM
The name-based VM is simpler than the IP-based VM. It depends on the host field in the HTTP header sent by the client to determine which vm The server serves. Generally, this method is recommended for price comparison. Because IP resources are increasingly scarce, it is costly for general users to purchase multiple IP addresses for one server.

When using this configuration method, first use the namevirtualhost command to configure the IP address and port number of the Apache instance listener, and then use the virtualhost command to configure different virtual hosts, the configuration method is as follows (note that in this method, servername is a required field ):

[Plain] View plaincopy

    1. Namevirtualhost 127.0.0.1: 80
    2. Nbsp; <virtualhost *: 80>
    3. Serveradmin yourname@domain.com
    4. DocumentRoot "/usr/mysite/test1"
    5. Servername test1.com
    6. Serveralias www.test1.com
    7. Errorlog "logs/test1.com-error. log"
    8. Customlog "logs/test1.com-access. log" combined
    9. </Virtualhost>
    10. <Virtualhost *: 80>
    11. Serveradmin yourname@domain.com
    12. DocumentRoot "/usr/mysite/Test2"
    13. Servername test2.com
    14. Serveralias www.test2.com
    15. Errorlog "logs/test2.com-error. log"
    16. Customlog "logs/test2.com-access. log" combined
    17. </Virtualhost>

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.