Initial installation and configuration of apache2 in Ubuntu

Source: Internet
Author: User

Install and configure Apache server in Linux. (For non-administrator commands, Gu adds: sudo before most commands)

First, try it and run the following command: sudo apt-Get install apache2. Go to the official website and say you can directly download the source code for compilation and installation. But I didn't try it here (because it has been installed with APT ~).

Apache installed with APT. By default, the configuration file is placed under/etc/apache2.

By default, HTTP pages are stored under/var/www.

Start and Stop the Script:/etc/init. d/apache2

Therefore:

The startup command is:

Sudo/etc/init. d/apache2 start

Stop command:

Sudo/etc/init. d/apache2 stop

Restart command:

Sudo/etc/init. d/apache2 restart

/************************************/

View the/etc/init. d/apache2 file. The following content is displayed:

Case $1 in
Start)
Log_daemon_msg "Starting web server" "apache2"
If $ apache2ctl start; then
If check_htcacheclean; then
Log_progress_msg htcacheclean
Start_htcacheclean | log_end_msg 1
Fi
Log_end_msg 0
Else
Log_end_msg 1
Fi
;;
Stop)
If check_htcacheclean; then
Log_daemon_msg "stopping Web server" "htcacheclean"
Stop_htcacheclean
Log_progress_msg "apache2"
Else
Log_daemon_msg "stopping Web server" "apache2"
Fi
If apache_wait_stop; then
Log_end_msg 0
Else
Log_end_msg 1
Fi
;;
Graceful-stop)
If check_htcacheclean; then
Log_daemon_msg "stopping Web server" "htcacheclean"
Stop_htcacheclean
Log_progress_msg "apache2"
Else
Log_daemon_msg "stopping Web server" "apache2"
Fi
If $ apache2ctl graceful-stop; then
Log_end_msg 0
Else
Log_end_msg 1
Fi
;;
Reload | force-Reload | graceful)
If! $ Apache2ctl configtest>/dev/null 2> & 1; then
$ Apache2ctl configtest | true
Log_end_msg 1
Exit 1
Fi
Log_daemon_msg "reloading Web Server config" "apache2"
If pidof_apache>/dev/NULL; then
If $ apache2ctl graceful $2; then
Log_end_msg 0
Else
Log_end_msg 1
Fi
Fi
;;
Restart)
If! $ Apache2ctl configtest>/dev/null 2> & 1; then
$ Apache2ctl configtest | true
Log_end_msg 1
Exit 1
Fi
If check_htcacheclean; then
Log_daemon_msg "Restarting web server" "htcacheclean"
Stop_htcacheclean
Log_progress_msg apache2
Else
Log_daemon_msg "Restarting web server" "apache2"
Fi
PID = $ (pidof_apache) | true
If! Apache_wait_stop; then
Log_end_msg 1 | true
Fi
If $ apache2ctl start; then
If check_htcacheclean; then
Start_htcacheclean | log_end_msg 1
Fi
Log_end_msg 0
Else
Log_end_msg 1
Fi
;;
Start-htcacheclean)
Log_daemon_msg "Starting htcacheclean"
Start_htcacheclean | log_end_msg 1
Log_end_msg 0
;;
Stop-htcacheclean)
Log_daemon_msg "Stopping htcacheclean"
Stop_htcacheclean
Log_end_msg 0
;;
Status)
PID = $ (pidof_apache) | true
If [-n "$ PID"]; then
Echo "apache2 $ dir_suffix is running (PID $ PID )."
Exit 0
Else
Echo "apache2 $ dir_suffix is not running ."
If [-e "$ pidfile"]; then
Exit 1
Else
Exit 3
Fi
Fi
;;
*)

/*************************************** */


Because Apache has the default configuration, you can directly run it with the default configuration after installation,

The configuration of this modification is mainly

DocumentRoot.

First, check/etc/Apache/apache2.conf. The configuration file of Apache of this version is known.

Use global configuration + default configuration + user configuration.

The/etc/apache2/apache2.conf mainly sets some global configurations,

The two files under/etc/apache2/sites-available/set some default configurations,

In/etc/apache2/httpd. conf, it is mainly used to set user configuration.

Copy the content from the two files under sites-available/to/etc/apache2/httpd. conf and modify the content.

The modified content here is:

DocumentRoot/var/WWW (Add the red part to the site directory you want to set. For example, set it to/home/xiaocc/STAT station.)
<Directory/>
Options followsymlinks
AllowOverride none
</Directory>
<Directory/var/www /(Same as above)>
Options indexes followsymlinks Multiviews
AllowOverride none
Order allow, deny
Allow from all
</Directory>

(You need to modify them everywhere. You can directly find and replace them .!!! Note: You must ensure that your site has a permission value of more than 400. Access only in 127.0.0.1 !!!)

Save and exit. Restart Apache.

To sum up, this Apache attack is too hasty. I did not follow the suggestions to go to the official website to carefully read the document. Other security issues are not considered...

I will summarize some Linux commands.

Command for modifying permissions:

Chmod permission value or permission ID + file/folder for which the permission needs to be modified. The read, write, and executable permissions are represented in three hexadecimal notation,

1 indicates executable, 2 indicates writable, and 4 indicates readable. Where, 3 characters (?) are used (?) Indicates the permissions of the three types of roles on this file (folder), such as chomd 457 demo. in Java, the number 4 indicates that the owner has only the read permission on the file (4 is expressed as 100 in binary format ), number 5 indicates that users in the same group have read and executable permissions on this file (5 is expressed in binary as 101). Number 7 indicates that users in different groups and non-file owners have read permissions on this file, write and execute permissions (number 7 is expressed as 111 in binary format ).

For readable and writable folders, the executable permissions are described as follows:

Executable indicates whether the folder can be accessed, and writable indicates whether the folder can be created. Readable indicates whether the content in the folder can be viewed. For example, a folder has executable, writable, and unreadable permissions for users of a certain type. That is, 3. Users of this type can enter this folder and create a file/folder under this folder, but cannot browse the files in the folder ...~~~ Linux strictly controls files. Okay, and so on .).

The default permission for the newly created folder is 775.

The default permission for the newly created file is 664.


~~~~~~~~~~~~~~~~~~~~~~~~~~~

As mentioned above, he summarized some things for fear that he would forget them. There are also some implicit, such as Linux permission detection algorithms, other permissions, and some useful I commands. I will summarize it tomorrow. It's late, sleep, and getting up early ~



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.