How to install and configure Apache in CentOS

Source: Internet
Author: User
Tags apache log file download zend php online apache log

Install the HTTP (Apache) server and related components

Install Apache server and related components
[Root @ sample ~] # Yum-y install httpd \ * install httpd online

To enable the server to run an interactive program written in PHP after activating the HTTP service
[Root @ sample ~] # Yum-y install php \ * install PHP online

To greatly improve the execution efficiency of PHP applications, Zend must be installed.
[Root @ sample ~] # Wgethttp: // downloads.zend.com/optimizer/3.0.1/ZendOptimizer-3.0.1-linux-glibc21-i386.tar.gz unzip download Zend source code
[Root @ sample ~] # Tar zxvf ZendOptimizer-3.0.1-linux-glibc21-i386.tar.gz unzip expand compressed source code
[Root @ sample ~] # Cd ZendOptimizer * enter the Zend source code directory
[Root @ sample ZendOptimizer-3.0.1-linux-glibc21-i386] #./install. sh uninstall run the installation script

Configure the HTTP (Apache) Server

Next, make some necessary changes to the default settings to make the server safer and more compliant with actual requirements. Especially in some details, the less server information is disclosed to the outside world, the more secure the server is.
[Root @ sample ~] # Vi etc/httpd/conf/httpd. conf configure edit Apache configuration file
Find this line in ServerTokens OS kernel and change "OS" to "Prod" (the name of the server operating system is not displayed when an error page appears)
Bytes
ServerTokens Prod restart changes to this status
ServerSignature On login find this line and change "On" to "Off"
Bytes
ServerSignature Off warn does not display Apache version on the error page
ServerAdminroot @ localhost Ghost set the Administrator's mailbox as a common mailbox
Bytes
ServerAdminyourname@yourserver.com renewal modify default settings as needed
# ServerName new. host. name: 80 modify the host name
Bytes
ServerNamewww.centospub.com: 80 slave is modified according to the actual situation, and the default port number is 80.
Options Indexes FollowSymLinks found this line, delete "Indexes", and add "des" and "ExecCGI"
Bytes
Options shortdes ExecCGI FollowSymLinks allow the server to execute CGI and SSI
# AddHandler cgi-script. cgi locate this line, remove "#" at the beginning of the line, and add ". pl" at the end of the line"
Bytes
AddHandler cgi-script. cgi. pl extension allows CGI scripts with the. pl extension to run.
AllowOverride None found this line and changed "None" to "All"
Bytes
AllowOverride All allow changes to this status, allow. htaccess
LogFormat "% h % l % u % t \" % r \ "%> s % B \" % {Referer} I \ "% {User-Agent} I \ "" combined locate this line
Bytes
LogFormat "% h % l % u % t \" %! 414r \ "%> s % B \" % {Referer} I \ "% {User-Agent} I \" "combined failed changed to this status (add"! 414 "to the rule, for too long logs are not recorded)
AddDefaultCharset UTF-8 found this line, add '#' at the beginning of the line
Bytes
# Adddefacharcharset UTF-8 ← do not use the UTF-8 as the default code for the web page
Adddefacharcharset GB2312 encode and add this line (add GB2312 as the default encoding)
<Directory "/var/www/icons"> locate this tag and change the corresponding options in the tag.
Options Indexes MultiViews locate this line and delete "Indexes"
Bytes
Options MultiViews changes to this status (the tree directory structure is not displayed on the browser)
[Root @ sample ~] # Rm-f/etc/httpd/conf. d/welcome. conf/var/www/error/noindex.html ← Delete the test page

Start HTTP service
[Root @ sample ~] # Chkconfig httpd on startup
[Root @ sample ~] # Chkconfig-list httpd
Httpd 0: off 1: off 2: on 3: on 4: on 5: on 6: off success check if 2-5 is on
[Root @ sample ~] #/Etc/rc. d/init. d/httpd start restart start the HTTP service
Starting httpd: [OK] If the slave node is successfully started, OK will appear.
If the startup fails, an error message is displayed. The cause may be an error occurred while editing the httpd. conf file. Check httpd. conf.

Perform simple tests on HTTP Services
[Root @ sample ~] # Echo hello>/var/www/html/index.html ← create a test page

Delete the created test page
[Root @ sample ~] # Rm-f/var/www/html/index.html ← Delete the test page

Perform a comprehensive test on the HTTP service

[1] test the correct display of HTML webpage
[Root @ sample ~] # Vi/var/www/html/index.html prepare:
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = GB2312">
<Title> Hello, World! </Title>
<Body>
Hello, World!
</Body>
</Html>
Enter "http: // server IP Address" or "http: // your domain name" in the browser. If "Hello, World!" appears !", And if the browser reads the code in simplified Chinese, it will be OK.

[2] Testing CGI support
[Root @ sample ~] # Vi/var/www/html/test. cgi testing:
#! /Usr/bin/perl
Print "Content-Type: text/html \ n ";
Print "Print "Hello, World! CGI is working! <Br> ";
Print "</body> [Root @ sample ~] # Chmod 755/var/www/html/test. cgi plugin and set the CGI test file attribute to 755
Enter "http: // server IP Address/test. cgi" or "http: // your domain name/test. cgi" in the browser. If "Hello, World!" is displayed correctly! CGI is working !", It indicates that there is no problem with CGI support.

[3] Testing PHP support
[Root @ sample html] # vi/var/www/html/test. php Plugin:
<? Php
Phpinfo ();
?>
Enter "http: // server IP Address/test. php or http: // your domain name/test. php ", the detailed information about PHP on the server is displayed correctly, indicating correct support for PHP.

[4] SSI Testing
[Root @ sample ~] # Vi/var/www/html/test.shtml build the SSI test page with the following content:
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = GB2312">
<Title> Hello, World! </Title>
<Body>
TEST SSI
<! -# Config timefmt = "% Y/% m/% d % H: % M: % S"->
<! -# Echo var = "DATE_LOCAL"->
</Body>
</Html>
Enter "http: // server IP Address/test.shtml" or "http: // your domain name/test.shtml" in the browser. If the current date and time are correctly displayed, it indicates that the SSI support is correct.

[5] test. htaccess support
[Root @ sample ~] # Vi/var/www/html/index.shtml labels create a. htaccess test page with the following content:
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = GB2312">
<Title> Hello, World! </Title>
<Body>
The name of the file is <! -# Echo var = "DOCUMENT_NAME"->
</Body>
</Html>
Enter "http: // server IP Address" or "http: // your domain name" in the browser. If "Forbidden" is displayed, it means. htaccess is normal.

[6] Create A. htaccess file and define the corresponding rules as follows:
[Root @ sample html] # vi/var/www/html/. htaccess creating a. htaccess file with the following content:

DirectoryIndex index.shtml
Enter "http: // server IP Address" or "http: // your domain name" in The browser. If "the name of The file is index.shtml" is displayed correctly, the description is as follows. the rule in htaccess takes effect. OK.
Apache Log File
[Root @ sample html] # vi/var/log/httpd/error_log prepare Apache log File

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.