CentOS Apache Configuration Detailed Text description _linux

Source: Internet
Author: User
Tags php programming php programming language apache log password protection

lamp required software and its structure
httpd mysql mysql-server php php-devel php-mysql
can be installed with the RPM package, or directly with the Yum installation
# Yum install httpd mysql-server php php-devel php-mysql
First look at the structure of the Apache 2.0 version so you know how to process our Web page data
/etc/httpd/ Conf/httpd.conf: The most important configuration file, but many other distribution have split the file into several small files, managing different parameters separately. But the most important profile is the file name.
/etc/httpd/conf.d/*.conf: One of the CentOS features of this thing, If you do not want to modify the original configuration file httpd.conf, you can separate your own additional parameters, and when you start Apache, the file will be read into the main configuration file.
/usr/lib/httpd/modules:apache supports a lot of modules, so the modules you want to use are placed by default in this directory
/var/www/html: This is the CentOS default "home" directory.
/var/www/error: The error message that appears on the browser is based on the default information for this directory, if the host is set up incorrectly or the data that is required by the browser side is wrong.
/var/www/icons: Provides some small icons for Apache
/var/www/cgi-bin: Default to some executable CGI programs placed in the directory
/VAR/LOG/HTTPD: The default Apache log files are placed here , for large traffic sites, this directory to be very careful, because this file is very easy to change a lot, you need enough space Oh
/usr/sbin/apachectl: This is Apache's main execution file, this execution file is actually shell script, It can proactively detect some of the settings on the system so that it's simpler when you start Apache
/usr/sbin/httpd: This is the main Apache binaries
/usr/bin/htpasswd: When you want to log on to some Web pages, You need to enter your account and password. So Apache itself provides the most basic way to password protection. The password is generated by using this command to implement the

For MySQL, you need to know several important directories and files that have the following:
/etc/my.cnf: This is the MySQL profile, including the MySQL database you want to optimize, or to MySQL for some additional parameters specified, Can be implemented in this file
/usr/lib/mysql: This directory is the location of the MySQL database, when starting any MySQL server, please be sure to remember the backup, the full backup of this directory.

In addition, you should be aware of the following files in PHP. The
/usr/lib/httpd/modules/libphp4.so:php provides a module for Apache that can be used to design the most important file for PHP programming language on the Apache Web page
/etc/httpd/ Conf.d/php.conf: Do you want to manually write the module into the httpd.conf? No, because the system has actively written the PHP settings parameter to this file, which will be read when Apache restarts.
/etc/php.ini: This is the main configuration file for PHP, including PHP can not allow users to upload files, can not allow some of the low security of the logo, etc., are set in this profile.
/etc/php.d/mysql.ini/usr/lib/php4/mysql.so:php can support the MySQL interface by looking at these two files. These two files are provided by the Php-mysql software
/usr/bin/phpize/usr/include/php: If you later want to install similar PHP accelerators to speed up the browsing, then this file and directory need to exist, Otherwise the accelerator software won't work.

Basic settings for

httpd.conf
First, you need to have a full hostname within/etc/hosts, otherwise you will be prompted to not find the full hostname when you restart the Apache service. The basic settings for the
httpd.conf are as follows:
< set project
      time related parameters in Project
       .....
</Setup Project
For example, if you want to provide additional functionality for the home/var/www/html, you can set the following settings:
<directory "/var/www/html"
    Options Indexes
   ...
</directory>

Setup Project for Host environment
#vi/etc/httpd/conf/httpd.conf
Servertokens OS
# This project tells the client the version and operating system of the WWW server, does not need to adapt it
#如果你不想告诉太多的主机信息, change the OS of this project to minor

ServerRoot "/etc/httpd"
# This is the top-level directory of the settings file, usually using an absolute path, some of the following data settings use a relative path when the
#就是与这个目录设置值有关的下层目录, do not need to change it
ServerRoot
Set absolute path for Apache installation
timeout
Settings The maximum wait time that the server receives to complete
keepalive
Set the server to turn on the continuous request function, the real server will normally open
Port
Sets the default ports for HTTP services.
User/group
Sets the performer and group of the server program, which is typically Apache

Here's how we do some experiments on Apache.
1: We test to change the default site directory to the root directory
New/root/website Directory
#mkdir-P/root/website
#echo "website page" >>/root/website/index.html
#vi/etc/httpd/conf/httpd.conf
Find the root directory of the//apache section of DocumentRoot "/var/www/html"
Change the/var/www/html directory to/root/website.
In Find <directory "/var/www/html" >//define apache/var/www/html this area
Change the/var/www/html into/root/website
So we can get rid of APAHCE's default path.
and restart the service.
#service httpd Restart
Here, when you restart the service, you may have an error, said the directory could not be found, which is mainly due to SELinux
So how do we solve it? There are 2 ways to turn off SELinux.
#setenforce 0
or change the SELinux attribute of/root/website This file to match the requirements of httpd this server
How to change? We can copy the SELinux attribute of/var/www/html this directory
#chcon-R--reference/var/www/html/root/website
And then restart the service, and then you'll see that it's not an error.
But when you go to visit the localhost, you will find the access denied. Mainly because of your/root permission is 750,ahache This user does not have the privilege to access, you need to change the permission, can like this
#chmod-R 755/root
And then went to the interview and found normal.

2: Name-based virtual host
Requires two domain name resolution to your server, the corresponding relationship is
/var/www/server server.example.com
/var/www/client client.example.com
When you visit these two domain names, you can display the contents of the home page in different files.
#echo "Server Page" >>/var/www/server/index.html
#echo "Client page" >>/var/www/client/index.html
Then we edit a configuration file
#vi/etc/httpd/conf.d/virtual.conf//Remember that the contents of CONF.D are also Apache configuration files.
Add the following:
Namevirtualhost 192.168.76.133:80

<virtualhost 192.168.76.133:80>
ServerName service.example.com
Documentroot/var/www/server
</VirtualHost>

<virtualhost 192.168.76.133:80>
ServerName client.example.com
Documentroot/var/www/client
</VirtualHost>
#service httpd Restart
So the name based virtual host is configured
If you do not have DNS you can then add the Hosts file to your machine to record Linux in/etc/hosts this file windows in C:\windows\system32\drivers\etc\hosts file
Plus these two lines
192.168.76.133 server.example.com
192.168.76.133 client.example.com
This way you are going to test, you will find that access to different domain names display different content, so the name of the virtual host is configured!

3: Virtual host based on IP address
Add a temporary network card first
#ifconfig eth0:0 192.168.76.132//temporary use, after reboot will disappear
Then convenient virtual.conf file
#vi/etc/httpd/conf.d/virtual.conf
Amend the content to
#NameVirtualHost 192.168.76.133:80

<virtualhost 192.168.76.133:80>
ServerName service.example.com
Documentroot/var/www/server
</VirtualHost>

<virtualhost 192.168.76.132:80>
ServerName client.example.com
Documentroot/var/www/client
</VirtualHost>
Let you use IP access, found also can display different content, or you edit Hosts file, with domain name access also no problem
This is based on the IP address of the virtual host has also been successful!

4: Alias
Join in the/etc/httpd/conf/httpd.conf.
Alias/test "/root/website/"//alias so you can use 192.168.76.133/test access will also show 192.168.76.133 page
The place to pay attention to is/test or/test/this is to use the difference you use/test then you can only use 192.168.76.133/test access when you visit if you use/test/so 192.168.76.133/test/access, and/ Test will not let you visit
Forget about this. You first put the/ETC/HTTPD/CONF.D directory just set up the virtual directory to comment out or not access, because the virtual directory, and httpd.conf inside the settings can not be accessed of course, with localhost to visit, other visits are not

5: The realization of the Web page resources download
Add alias First
#vi/etc/httpd/conf/httpd.conf
Join after Alias/test "/root/website/"
Alias/down "/var/ftp/pub"
To set parameters for the/var/ftp/pub region
<directory "/var/ftp/pub" >
Options Indexes MultiViews
AllowOverride None
Order Allow,deny
Allow from all
</Directory>
Automatically list catalog documents when options join MultiViews//No Index
Then restart the service, so http://192.168.76.133/down/inside can be listed/var/ftp/pub inside the file, try to click a save as, whether can download? Hehe success!

The realization of 6:.HTPASSWD
#vi/etc/httpd/conf/httpd.conf
We're doing this for the/var/ftp/pub we just made.
Add the following information
Alias/down "/var/ftp/pub/"
<directory "/var/ftp/pub" >
Options Indexes MultiViews
AllowOverride authconfig
Order Allow,deny
Allow from all
</Directory>
<directory "/var/ftp/pub" >
AuthType Basic
AuthName "This is test"
authuserfile/etc/httpd/htpasswd
Require User Test
</Directory>
Then restart the httpd service,
Let's generate the. htpasswd User Password
Htpasswd-c/ETC/HTTPD/HTPASSWD Test
192.168.76.133/down will need a password to access the post.
That's how it works.

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.