Install and configure the LAMP server in yum in CentOS 6.4 (Apache + MySQL + PHP5)

Source: Internet
Author: User
Tags install php php script sql injection centos iptables

 

Preparation:

1. Configure the firewall and enable port 80 and Port 3306.

Vim/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.111cn.net

Change to ServerName www.111cn.net # set it as your 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-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.qianyunlai.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 client browser to view the configuration information!

 

Note: the default program directory of apache is/var/www/html.

Permission settings: chown apache. apache-R/var/www/html

 

Note: The PHP version is PHP5.3.3.

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.