Linux--Install and configure Apache2 under Ubuntu

Source: Internet
Author: User



Installing Apache in Ubuntu



  Installation Instructions : sudo apt-get install apache2



  start and stop Apache files are:/etc/init.d/apache2



Start command: sudo apache2ctl-k start (or Server apache2 start)



Stop command: sudo apache2ctl-k stop (or server apache2 stop)



Restart: sudo apache2ctl-k restart (or server apache2 restart)



Configuration file is present:/etc/apache2, it is necessary to note that the normal Apache distribution configuration file is:



httpd.conf



The main configuration file for the Ubuntu release is:



Apache2.conf



The following files are referenced in apache2.conf:



   # contains the configuration of the dynamic module:



Include/etc/apache2/mods-enabled/*.load



Include/etc/apache2/mods-enabled/*.conf



   # contains the user's own configuration:



Include/etc/apache2/httpd.conf



   # contains the configuration of the Port listener:



Include/etc/apache2/ports.conf



    # contains a generic configuration statement fragment:



include/etc/apache2/conf.d/



    # contains the configuration directives for the virtual host:



include/etc/apache2/sites-enabled/



   Modify Httpd.conf



Add the following content:



ServerName 127.0.0.1:80



Ubuntu apache2 Configuration


1.apache2.conf is the master profile, httpd.conf user profile
2. Virtual directory in httpd.conf
<virtualhost *>
DocumentRoot "Road "
ServerName name
<directory" path "> Allow from all Options +indexes </directory>
</virtual Host>
3. Root settings ( default home directory ) in  /etc/apache2/sites-available/ Default
4. Restart command
sudo/etc/init.d/apache2 restartor
cd/etc/init.d
sudo Apache2-k restart
Stop stop; start startup5. log file in/var/log/apache2/
<virtualhost *:80>
Servername&nbs  p;www.kimoqi.com
Documentroot/home/vsftpd/kimoqi
</virtualhost>
<virtualhost *:80>
servername www.arwenedu.com
Documentroot/home/vsftpd/wangguan/webapps
</virtualhost>
< VirtualHost *:80>
servername www.arwenedu.org.cn
Documentroot/home/vsftpd/wangguan/chem
</ Virtualhost>



Vi/etc/httpd/conf/httpd.conf



Under Windows, Apache usually has only one configuration file, which is httpd.conf. But after I installed the Apache2 with the Apt-get install apache2 command on Ubuntu Linux, I found that its httpd.conf (located in the/etc/apache2 directory) was empty (not even the httpd.conf file)! And then found that the Ubuntu Apache software package configuration file is not as simple as windows, it put the individual settings in different configuration files , look complex, but think carefully about the design is really reasonable.



Strictly speaking, Ubuntu Apache (or should say Linux under the Apache?) I am not sure that the configuration file for other distributions of the Apache package is that/etc/apache2/apache2.conf,apache automatically reads the configuration information for this file at startup. Some other configuration files, such as httpd.conf, are included through the include directive. These include lines can be found in apache2.conf:



Reference



 # contains the configuration of the dynamic module:



Include/etc/apache2/mods-enabled/*.load



Include/etc/apache2/mods-enabled/*.conf



 # contains the user's own configuration:



Include/etc/apache2/httpd.conf



 # contains the configuration of the Port listener:



Include/etc/apache2/ports.conf



 # contains a generic configuration statement fragment:



include/etc/apache2/conf.d/



 # contains the configuration directives for the virtual host:



include/etc/apache2/sites-enabled/



Combined with annotations, you can clearly see the general effect of each configuration file. Of course, all settings can be placed in apache2.conf or httpd.conf or any one of the configuration files. This division of Apache2 is only a good habit.



One of the most important things to do after installing Apache is to know where the Web document root directory is, and for Ubuntu, the default is/var/www. How do you know that? There is no documentroot in apache2.conf, httpd.conf is empty, so it must be in other files. After searching, found in the/etc/apache2/sites-enabled/000-default, there is such content:



Reference



Namevirtualhost *
<virtualhost *>
ServerAdmin [email protected]



documentroot/var/www/



......
This is setting up the virtual host, which means nothing to me. So I put the apache2.conf in the include/etc/apache2/sites-enabled/line commented out, and in httpd.conf set documentroot for my user directory under a directory, so as to facilitate the development.



Sites-enabled: Setting up a virtual host



Sites-enabled: Configuration file



And look at what's in the/etc/apache2 directory. Just found in the apache2.conf sites-enabled directory, and/etc/apache2 under a sites-available directory, what is put in it? In fact, this is the real configuration file, and the sites-enabled directory is just some of the files pointing to the symbolic link here, you can use ls/etc/apache2/sites-enabled/to confirm. Therefore, if more than one virtual host is configured on Apache, and the configuration file of each virtual host is placed under Sites-available, it is very convenient for the virtual host to be deactivated and enabled: When a link to a virtual host profile is established under sites-enabled , it is enabled, and if you want to turn off a virtual host, simply delete the link and not change the configuration file at all.



mods-available, mods-enabled , and the above-mentioned sites-available, sites-enabled, these two directories are the configuration files and links that store the Apache function module. When I installed the PHP module with apt-get install PHP5, there were php5.load, php5.conf, and links to the two files in both directories. This catalog result is very handy for enabling and deactivating an Apache module.



The last one to say is ports.conf, which sets the port that Apache uses. If you need to adjust the default port settings, it is recommended that you edit this file. Or if you think it is superfluous, you can first remove the include/etc/apache2/ports.conf line in the apache2.conf and set the Apache port in the httpd.conf.



The default installed directory structure in Ubuntu is a bit different. In Ubuntu, the module and virtual host configuration has two directories, one is available, one is the enabled,available directory is a valid content, but does not work, only with Ln Connected to Enabled in the past can only play a role . It is easy to use for debugging, but if you do not know beforehand, it is a bit troublesome to find it.



/etc/apache2/sites-available is in the VH configuration, but it does not work, to link the file to the sites-enabled directory.


  1. <virtualhost *>
  2. ServerName Domain Name
  3. DocumentRoot the public in the Rails project as the root directory
  4. <directory Public root directory >
  5. Options execcgi FollowSymLinks
  6. AllowOverride All
  7. Allow from all
  8. Order Allow,deny
  9. </Directory>
  10. errorlog/var/log/apache2/error-domain name. log
  11. </VirtualHost>


For further configuration and use, you can consult the Apache manual.






Apache configuration file httpd.conf Description

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




directoryindex index.html index.htm index.php index.html.var ---Default document, separated by spaces between multiple files

Listen 192.168.1.1:80 Setting the listening IP is 192.168.1.1 address and port is 80

Listen 192.168.1.2:8080 Setting the listening IP is 192.168.1.2 address and port is 8080



serverroot "/ETC/HTTPD" sets the path relative to the root directory, usually where the configuration and log files are stored. The default is:/ETC/HTTPD typically 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 format used by the log and common format)



ServerAdmin [email protected] set up the network administrator's email-when the client server error occurs, the server will usually return to the client Error prompt page, in order to facilitate the resolution of the error, this page usually has an administrator's email address, you can use the Serv Eradmin statement to set the administrator's email address



ServerName www.iigoogle.com:80 Set the server host name (if a domain name can be filled in the domain name, no domain name can be filled in the server IP address)



Adddefaultcharset GB2312 Sets the default character set and defines the default character set that the server returns to the client (since Western Europe UTF-8 is the Apache default character set, so garbled when accessing a Chinese-language web page, as long as the character set is changed to GB2 312, then restart Apache service)



alias/down "/software/download" creates a virtual directory (creates a virtual directory named down, which corresponds to a physical path of:/software/download)
Alias/ftp "/var/ftp" to create the virtual directory (create a virtual directory named FTP, which corresponds to the physical path is:/var/ftp)



<directory "/var/www/html" > set directory Permissions (<directory "directory path" > This write statement to set directory permissions </Directory>)
Options FollowSymLinks page:116
AllowOverride None
</Directory>



Domain-based virtual host
namevirtualhost 220.123.55.99---First use the namevirtualhost directive to specify which IP address is responsible for responding to requests to the virtual host
<virtualhostwww.iigoogle.com>
ServerNamewww.iigoogle.com:80
ServerAdmin[email protected]
Documentroot/www/docs/iigoogle
DirectoryIndex index.jsp
Errorlog Logs/www/iigoogle/error_log
Customlog Logs/www/iigoogle/access_log Common
</VirtualHost>
Another way of writing
Namevirtualhost 220.123.55.99:80
<virtualhost www.iigoogle.com:80>
ServerName www.iigoogle.com
ServerAdmin[email protected]
Documentroot/www/docs/iigoogle.com
Errorlog Logs/www/iigoogle/error_log
Customlog Logs/www/iigoogle/access_log Common
</VirtualHost>


Linux--Install and configure Apache2 under Ubuntu


Related Article

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.