Linux Server Apache configuration details

Source: Internet
Author: User
Tags apache log
To implement a web server (www) on linux, the Apache server software is required. However, Apache only provides the most basic static website data. To implement a dynamic website, it is better to support PHP and MySQL, so we will introduce LAMP (linux + Apache + MySQL + PHP) as the installation and setting. Software and

Apache is required to implement web server (www) on linux, but Apache can only provide the most basic static website data. To implement dynamic websites, it is bestPHPAnd MySQL support, so we will use LAMP (linux + Apache + MySQL + PHP) as an introduction to installation and setup.

Software and structure required by LAMP

HttpdMysql-ServerPhpPhp-devel php-mysql
You can install it using an rpm package or directly using yum.
# Yum install httpd mysql-server php-devel php-mysql
First, let's take a look at the structure of apache 2.0, so that we can know how to process our webpage data.
/Etc/httpd/conf/httpd. conf: The most important configuration file, but many other disTrIbution splits the file into several small files to manage different parameters. However, the main configuration file is based on the file name.
/Etc/httpd/conf. d /*. conf: One of the characteristics of CentOS, if you do not want to modify the original configuration file httpd. conf, you can separate your own extra parameters. When apache is started, this file will be read into the main configuration file.
/Usr/lib/httpd/moDuLes: apache supports many modules, so the modules you want to use are stored in this directory by default.
/Var/www/html: the default "Homepage" Directory of CentOS.
/Var/www/error: if the host is set incorrectly or the data requested by the browser is incorrect, the error message displayed on the browser is the default information of this directory.
/Var/www/icons: provides some small icons of apache.
/Var/www/cgi-bin: directory for some executable CGI programs by default
/Var/log/httpd: by default, apache log files are stored here. For websites with high traffic, this directory should be very careful, because this file is easily changed to a large one, you need enough space.
/Usr/sbin/Apachectl: This is the main execution file of Apache. The execution file is actually a shell script, which can actively detect some settings on the system to make it easier to start Apache.
/Usr/sbin/httpd: This is the main apache binary file.
/Usr/bin/htPasswd: To log on to some web pages, enter your account and password. Apache itself provides the most basic password protection method. The password is generated through thisCommandImplemented
For MySQL, You Need To Know several important directories and files as follows:
/Etc/my. cnf: This is the Mysql configuration file, which can be used to optimize the mysql database or specify some additional parameters for mysql.
/Usr/lib/mysql: the directory where the MySQL database is stored. When starting any MySQL server, remember to back up the directory completely during Backup.


In addition, you should know the following files in PHP.
/Usr/lib/httpd/modules/libphp4.so: the module provided by PHP for apache. Can we design the most important php program language file on the apache webpage?
/Etc/httpd/conf. d/php. conf: Do you want to manually write this module into Httpd. conf? No, because the system has actively written the php setting parameters to this file, and this file will be read when apache restarts.
/Etc/php. ini: This is the main configuration file of PHP, including whether PHP can allow users to upload files and some low-security labels, which are all set in this configuration file.
/Etc/php. d/mysql. ini/usr/lib/php4/mysql. so: Can PHP support the MySQL interface. These two files are provided by the php-mysql software.
/Usr/bin/phpize/usr/INcLude/php: If you want to install a PHP accelerator later to speed up browsing, this file and directory will need to exist. Otherwise, the accelerator software will not work.
Httpd. conf Basic settings
First, you need to have a complete host name in/etc/hosts. Otherwise, you will be prompted that the complete host name cannot be found when you restart the apache service.
The basic settings of httpd. conf are as follows:
<设置项目>
Related Parameters in the project
....

For example, if you want to provide additional functions for the homepage/var/www/html, you can perform the following settings:

Options Ind ExEs
......


Set items for the host environment
# Vi/etc/httpd/conf/httpd. conf
ServerTokens OS
# This Project tells the client about the WWW server version and operating system and does not need to be adapted.
# If you do not want to tell too much host information, change the OS of this project to Minor.


ServerRoot "/etc/httpd"
# This is the top-level directory of the setting file, which usually uses absolute paths. When some of the following data settings use relative paths
# It is the lower-level directory related to the directory setting value and does not need to be changed.
ServerRoot
Set the absolute path for Apache installation
TimeOut
Sets the maximum wait time for the server to receive the message.
KeepAlive
Set whether the server enables the continuous request function. Generally, the real server must enable the function.
Port
Set the default port of the http service.
User/Group
Set the executor and Group of the server program, which is generally apache
Below we will do a few experiments on Apache

1: We tested to change the default website directory to the root directory.
Create/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 DocumentRoot "/var/www/html" // apache
Change the/var/www/html directory to/root/website.
Find // Define the apache/var/www/html Region
Change/var/www/html to/root/website
In this way, we can change the default path of apahce.
Then restart the service.
# Service httpd restart
// When you restart the service, an error may be reported, indicating that the directory cannot be found, which is mainly caused by selinux.
How can this problem be solved? There are two ways to disable selinux
# SetEnforce 0
Or change The selinux attribute of the/root/website file to match the requirements of the httpd server.
How to change it? We can copy the selinux attribute of the/var/www/html directory.
# Chcon-R -- reference/var/www/html/root/website
Then, after restarting the service, you will see that there is no error.
But when you access localhost, you will find that the access is denied. Why? The main reason is that your/root permission is 750, and the ahache user has no access permission. You need to change the permission.
# Chmod-R 755/root
Then, access and find that it is normal.

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.