Install and configure the lamp server in centos 6.4

Source: Internet
Author: User

Install and configure the lamp server in centos 6.4 (Apache + PhP5 + MySQL)

March 12, 2013? Lamp? 10 comments? Watched more than 14,290 times

Preparation:

1. configure the firewall and enable port 80 and port 3306.
VI/etc/sysconfig/iptables
-A input-M state -- state new-m tcp-p tcp -- dport 80-J accept # Allow port 80 to pass the Firewall
-A input-M state -- state new-m tcp-p tcp -- dport 3306-J accept # Allow port 3306 to pass the Firewall

Note: many users add these two rules to the last line of the firewall configuration, resulting in firewall startup failure,

The correct rule should be added to the default port 22.

As follows:
############################# The following figure shows the firewall rules after they are added ### ###########################
# Firewall configuration written by system-config-Firewall
# Manual customization of this file is not recommended.
* Filter
: Input accept [0: 0]
: Forward accept [0: 0]
: Output accept [0: 0]
-A input-M state -- State established, related-J accept
-A input-p icmp-J accept
-A input-I lo-J accept
-A input-M state -- state new-m tcp-p tcp -- dport 22-J accept
-A input-M state -- state new-m tcp-p tcp -- dport 80-J accept
-A input-M state -- state new-m tcp-p tcp -- dport 3306-J accept
-A input-J reject -- reject-with ICMP-host-prohibited
-A forward-J reject -- reject-with ICMP-host-prohibited
Commit
######################################## ######################################## ##################

/Etc/init. d/iptables restart # restart the firewall to make the configuration take effect.

2. Disable SELinux
VI/etc/SELinux/config
# SELinux = enforcing # comment out
# Selinuxtype = targeted # comment out
SELinux = disabled # Add
: WQ # Save, close
Shutdown-R now # restart the system

Installation:

1. install Apache
Yum install httpd # Enter y as prompted to install httpd.
/Etc/init. d/httpd start # start Apache

Note: An error is prompted after Apache is started:
Starting httpd: cocould not reliably determine the server's fully qualif domain name, using: 1 for servername
Solution:
VI/etc/httpd/CONF/httpd. conf # Edit
Find # servername www.example.com: 80
Modify it to servername www.osyunwei.com: 80 # Set it to your own domain name here. If there is no domain name, you can set it to localhost
: WQ! # Save and exit
Chkconfig httpd on # Set to boot
/Etc/init. d/httpd restart # restart Apache

Ii. Install MySQL

1. Install MySQL
Yum install MySQL mysql-server # ask if you want to install it. Enter y to install it automatically until the installation is complete.
/Etc/init. d/mysqld start # Start MySQL
Chkconfig mysqld on # Set to boot
CP/usr/share/MySQL/my-medium.cnf/etc/My. CNF # copy the configuration file (Note: if there is a my. CNF under the/etc directory by default, directly overwrite it)

2. Set a password for the root account
Mysql_secure_installation
Press enter and enter y as prompted.
Enter the password twice and press Enter.
Enter y as prompted
Thanks for using MySQL!
After setting the MySQL password, restart MYSQL:
/Etc/init. d/mysqld restart # restart
/Etc/init. d/mysqld stop # Stop
/Etc/init. d/mysqld start # Start

3. Install PhP5

1. Install PhP5
Yum install PHP
Enter y as prompted until installation is complete.

2. Install the php component to make PhP5 support MySQL
Yum install PHP-mysql PHP-Gd libjpeg * PHP-imap PHP-ldap php-odbc php-pear PHP-xml php-xmlrpc php-mbstring PHP-mcrypt PHP-bcmath PHP-mhash libmcrypt
Select the above installation package for installation.
Enter y and press enter as prompted.
/Etc/init. d/mysqld restart # restart MySQL
/Etc/init. d/httpd restart # restart Apche

Configuration

1. Apache configuration
VI/etc/httpd/CONF/httpd. conf # edit the file
ServerTokens OS is changed to ServerTokens prod in row 44 (the server operating system name is not displayed when an error page appears)
Serversignature on is changed to serversignature off on Line 1 (apache version is not displayed on the error page)
Modify options indexes followsymlinks to: Options shortdes execcgi followsymlinks on line 3 (allow the server to execute CGI and SSI, and disable Directory Listing)
# Modify addhandler CGI-script. cgi to addhandler CGI-script. cgi. pl in line 3 (run a CGI script with the extension of. pl)
AllowOverride none is changed to AllowOverride all (allow. htaccess) in row 338)
Adddefadefacharset UTF-8 in line 759 is changed to: adddefadefacharset gb2312 (add gb2312 as the default encoding)
Modify options indexes Multiviews followsymlinks to options Multiviews followsymlinks in row 554 (tree directory structure is not displayed in the browser)
Modify directoryindex index.html. var to directoryindex index.html index.htm default.html default.htm in row 402.

Index. php default. php index.html. var (set the default homepage file and add index. php)
Modify keepalive off to keepalive on (allow procedural connection) In line 76)
Modify maxkeepaliverequests 100 in line 83 to: maxkeepaliverequests 1000 (Increase the number of simultaneous connections)
: WQ! # Save and exit
/Etc/init. d/httpd restart # restart
Rm-F/etc/httpd/CONF. d/welcome. CONF/var/www/error/noindex.html # Delete the default test page

Ii. PHP configuration
VI/etc/PHP. ini # Edit
Date. timezone = PRC # Remove the semicolon in front of row 946 and change it to date. timezone = PRC.
Disable_functions = passthru, exec, system, chroot, scandir, chgrp, chown, shell_exec, proc_open, proc_get_status, ini_alter, ini_alter, disconnect, DL, openlog, syslog, readlink, symlink, release, delimiter, delimiter, DLL, popen, disk_free_space, checkdnsrr, checkdnsrr, getservbyname, getservbyport, delimiter, posix_getgrnam, posix_getgroups, posix_getlogin, delimiter, delimiter, posix_getpid, delimiter, delimiter, posix_getpwuid, delimiter, posix_getsid, posix_getuid, delimiter, posix_kill, posix_mkfifo, delimiter, posix_setsid, posix_setuid, posix_strerror, posix_times, posix_ttyname, posix_uname

# List the functions that PHP can disable in Row 3. If some programs need this function, delete it and disable it.
Expose_php = off # disable display of PHP version information in line 432
Magic_quotes_gpc = on # enable magic_quotes_gpc on Line 1 to prevent SQL Injection
Short_open_tag = on # PHP short labels are supported in line 229
Open_basedir =. :/tmp/# Set in row 380 to allow access to the current directory (that is, the directory where the PHP script file is located) And/tmp/directory, which can prevent PHP trojans from being cross-site, if there is a problem with the installation program after the change (for example, zhimeng Content Management System), you can log out of this line or directly write the program directory/data/www.osyunwei.com/:/tmp/
: WQ! # Save and exit
/Etc/init. d/mysqld restart # restart MySQL
/Etc/init. d/httpd restart # restart Apche

Test
CD/var/www/html
VI index. php # enter the following content
<? PHP
Phpinfo ();
?>
: WQ! # Save and exit
Enter the Server IP address in the browser of the client. The configuration information shown in is displayed!

Note: The default program directory of Apache is/var/www/html.

Permission settings: chown Apache. APACHE-r/var/www/html

So far, centos 6.4 installation and configuration of the lamp server (Apache + PhP5 + MySQL) tutorial is complete!


Install and configure the lamp server in centos 6.4

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.