Details on installing and configuring Apache2 under Ubuntu

  • 2020-05-14 05:48:15
  • OfStack

Install apache in Ubuntu

Installation instructions:


sudo apt-get install apache2

After installation:

Is the start and stop the file: / etc/init d/apache2

Activation:


sudo apache2ctl -k start

Stop:


sudo apache2ctl -k stop

Restart:


sudo apache2ctl -k restart

The configuration file is saved at: /etc/apache2

Note that the normal apache distribution configuration file is httpd.conf

The main configuration file for the Ubuntu distribution is: apache2.conf

The following files are referenced in apache2.conf:


#  Contains the configuration of dynamic modules :

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

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

#  Contains the user's own configuration :

Include /etc/apache2/httpd.conf

#  Configuration that includes port listening :

Include /etc/apache2/ports.conf

#  contains 1 Generic configuration statement fragments :

Include /etc/apache2/conf.d/

#  Contains configuration instructions for the virtual host :

Include /etc/apache2/sites-enabled/

Modify httpd conf

Add the following:


ServerName 127.0.0.1:80

ubuntu apache2 configuration

1.apache2.conf is the master profile and httpd.conf is the user profile

2. The virtual directory is in httpd.conf


<VirtualHost *>
 DocumentRoot " The path "
ServerName  The name of the 
<Directory " The path "> allow from all Options +Indexes </Directory>
 </VirtualHost>

3. The root setting (default home directory) is at /etc/apache2/ sites-available /default

4. Restart the command


sudo /etc/init.d/apache2 restart or 
cd /etc/init.d
sudo apache2 -k restart

stop stop; start startup 5. Log file at /var/log/apache2/


 <VirtualHost *:80>
 ServerName 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 profile, which is httpd.conf. But when I installed Apache2 on Ubuntu Linux with the apt-get install apache2 command, I found that its httpd.conf (located in the /etc/apache2 directory) was empty! Furthermore, it is found that the configuration file of Ubuntu Apache software package is not as simple as that of Windows. It divides various Settings into different configuration files, which looks complicated, but when you think about it, the design is indeed very reasonable.

Strictly speaking, Ubuntu is Apache (or should I say Apache under Linux? I don't know other distributions of apache package) configuration file is/etc apache2 / apache2 conf, Apache at startup configuration information automatically read this file. Other configuration files, such as httpd.conf, are included through the Include directive. These Include lines can be found in apache2.conf:

reference


sudo apache2ctl -k start
0

Combined with the comments, it is clear what each configuration file does in general. Of course, you can put all your Settings in either apache2.conf or httpd.conf or any one of the configuration files. This classification of Apache2 is just a good habit.

One of the most important things to do after installing Apache is to know where the Web document root is. For Ubuntu, the default is /var/www. How do you know that? There is no DocumentRoot entry in apache2.conf, and httpd.conf is empty again, so it must be in another file. After a search, found in/etc apache2 / sites enabled / 000 - default, there are:

reference


sudo apache2ctl -k start
1

This is for setting up the virtual host. It doesn't make any sense to me. In. So I took the apache2 conf Include etc/apache2 / sites enabled / 1 line commented out, and in httpd. Put a DocumentRoot conf users of a directory in the directory for me, so convenient development.

Look at the /etc/apache2 directory. I just found the sites-enabled directory in apache2.conf, and there is another sites-available directory under /etc/apache2. What's in it? In fact, it is the real configuration files, and sites - enabled directory for just 1 a symbolic link to the file here, you can use the ls/etc/apache2 / sites - enabled/l to confirm. Therefore, if multiple virtual hosts are configured on apache and the configuration files of each virtual host are placed under sites-available, it is very convenient to disable and enable the virtual host: when a link pointing to a virtual host configuration file is established under sites-enabled, it is enabled; If you want to shut down a virtual host, you can simply delete the corresponding link without changing the configuration file at all.

mods-available, mods-enabled are similar to the sites-available and sites-enabled mentioned above. These two directories hold configuration files and links for apache function modules. When I installed the PHP module with apt-get install php5, I had php5.load, php5.conf and links to these files in the two directories. This directory result is very convenient for enabling and deactivating an Apache module.

The last one is ports.conf, which sets the port used by Apache. If you need to adjust the default port Settings, you are advised to edit this file. Or you think it is much more than, also can put apache2. The Include conf/etc apache2 / ports conf1 line, in httpd. Put a Apache conf port.

The directory structure for the default installation in ubuntu is quite a bit different. In ubuntu, both module and virtual host configurations have two directories, one for available and one for enabled, and available is a directory that holds valid content, but does not work, and only works if ln is connected to enabled. Easy to use for debugging, but if you don't know in advance, it can be a bit of a hassle to find.

/ etc/apache2 / sites - put is VH available configuration, but doesn't work, the file link to sites - enabled catalog.


sudo apache2ctl -k start
2

For further configuration and use, you can refer to the APACHE manual

Description of Apache configuration file httpd.conf

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

DirectoryIndex html index htm php html var - default document, separated by Spaces between multiple files

Listen 192.168.1.1:80 Settings listening ip is 192.168.1.1 for the address and port of 80

Listen 192.168.1.2:8080 Settings listening ip is 192.168.1.2 for the address and port of 8080

ServerRoot "/etc/httpd" sets the path to the relative root directory, usually where configuration files and log files are stored. The default is: /etc/httpd 1, including conf and logs subdirectories

ErrorLog logs/error_log set error logging note: if the log file location path does not start with "/", it means that the file is relative to the ServerRoot directory

CustomLog logs/access_log combined access logs (combined indicates the format used for the logs, as well as common)

ServerAdmin lindenstar@163.com set the network administrator's Email - when an error occurs on the client server, the server will usually return an error message to the client. To facilitate the resolution of the error, the administrator's Email address is usually available on this page, and the administrator's EMail address can be set by using the ServerAdmin statement

ServerName www. iigoogle. com: 80 set up the server host name (if you have a domain name can fill in the domain name, no IP domain can fill in the server address)

AddDefaultCharset GB2312 sets the default character set, and defines the server to return to the client the default character set (because UTF-8 in Western Europe is the default character set of Apache, when visiting the web pages with Chinese characters, there will be some random codes, so just change the character set to GB2312, and then restart the Apache service)

Alias /down "/software /download" create a virtual directory (create a virtual directory named down, which corresponds to the physical path: /software /download)

Alias /ftp "/var/ftp" create a virtual directory (create a virtual directory named ftp, which corresponds to the physical path: /var/ftp)


<Directory "/var/www/html">     Set directory permissions ( <Directory " Directory path "> Write the statement that sets the directory permissions this time </Directory> ) 
   Options FollowSymLinks    page:116
    AllowOverride None
</Directory>

Virtual host based on domain name


sudo apache2ctl -k start
4

sudo apache2ctl -k start
5

Or another way to write it


sudo apache2ctl -k start
6

sudo apache2ctl -k start
7

Related articles: