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

Source: Internet
Author: User

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

Preparations: 1. configure the firewall, 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 through the firewall) Special prompt: many netizens 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. After adding the rule, the firewall rules are as follows: ######################################## ################# firewall configuration written by system-config-fir Ewall # 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-prohibitedcommit ##### ######################################## ###########/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 # added: WQ save and shut down shutdown-R now # restart the system for installation: 1. install Apache Yum I Nstall httpd # Enter y as prompted to install/etc/init. d/httpd start # start Apache Note: After Apache is started, an error will be prompted: httpd: cocould not reliably determine the server's fully qualif domain name, using :: 1 For servername solution: VI/etc/httpd/CONF/httpd. conf # edit and find # servername www.example.com: 80 and change it to servername localhost: 80: WQ! # Save and exit chkconfig httpd on # set to start/etc/init. d/httpd restart # restart Apache 2. Install mysql1. Install MySQL Yum install MySQL mysql-server to check whether installation is required. Enter y to install MySQL automatically until installation is complete/etc/init. d/mysqld start # Start MySQL chkconfig mysqld on # set to start CP/usr/share/MySQL/my-medium.cnf/etc/My. CNF # copy the configuration file (Note: if the/etc directory contains a my. CNF: overwrite it.) 2. Set the password mysql_secure_installation for the root account. Press enter. Enter y twice as prompted. Press enter. Enter y as prompted. Thanks for using MySQL appears! After setting the MySQL password, restart MYSQL:/etc/init. d/mysqld stop # Stop/etc/init. d/mysqld start # Start/etc/init. d/mysqld restart # restart 3. Install php51, install PhP5 Yum install PHP, and enter y as prompted until installation is complete. 2. Install the php component, 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 here for installation. Enter y and press enter/etc/init as prompted. d/mysqld restart # restart MySQL/etc/ini T. d/httpd restart # restart Apche configuration 1. Configure VI/etc/httpd/CONF/httpd in Apache. modify the ServerTokens OS file "ServerTokens Prod" in row 44 to "ServerTokens Prod" (the name of the server operating system is not displayed when an error page appears) "serversignature on" in row 44: serversignature off (the apache version is not displayed on the error page) Options indexes followsymlinks is changed to options between des execcgi followsymlinks on Line 1 (the server is allowed to execute CGI and SSI and the directory is not listed) # addhandler CGI-script. modify CGI to addhandler CGI-script in row 796. CGI. PL (allowed Extension. CGI foot of PL In this example, AllowOverride none is modified to AllowOverride all in row 338 (allowed. htaccess) adddefaultcharset UTF-8 on line 759 changed to: adddefadefacharset gb2312 (add gb2312 as the default encoding) Options indexes Multiviews followsymlinks on line 554 changed to options Multiviews followsymlinks (tree directory structure not displayed on the browser) directoryindex index.html. vaR is changed to directoryindex index.html index.htm default.html default.htm index in row 402. PHP default. PHP index.html. vaR (set the default homepage To: keepalive on (allow procedural online) maxkeepaliverequests 100 to: maxkeepaliverequests 1000 (increase concurrent connections): WQ! # Save and exit/etc/init. d/httpd restart Rm-F/etc/httpd/CONF. d/welcome. conf/var/www/error/noindex.html # delete default test page 2. Configure VI/etc/PHP in 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, alter, DL, openlog, syslog, readlink, symlink, delimiter, stream_socket_server, delimiter, DLL, popen, disk_free_space, checkdnsrr, checkdnsrr, getservbyname, getservbyport, disk_total_space, posix_ctermid, delimiter, posix_getcwd,
Signature, delimiter, posix_getgrnam, posix_getgroups, delimiter, delimiter, signature, posix_getpid, delimiter, posix_getpwnam, delimiter, delimiter, posix_getsid, posix_getuid, delimiter, posix_kill, posix_mkfifo, dispatch, posix_seteuid, posix_setgid,
Posix_setpgid, posix_setsid, posix_setuid, posix_strerror, posix_times, posix_ttyname, posix_uname # list functions that can be disabled by PHP in row 386. If some programs need this function, delete it and disable it. Expose_php = Off # disable the display of php version information in row 432 magic_quotes_gpc = On # enable magic_quotes_gpc in row 745 to prevent SQL Injection 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 cross-site: wq! # Save and exit/etc/init. d/mysqld restart # restart MySql/etc/init. d/httpd restart # restart Apche to test cd/var/www/htmlvi index. php # create an index. PHP file <? Phpphpinfo ();?> : Wq! Enter the Server IP address in the client browser to view the configuration information! Note: The default apache program directory is/var/www/html permission setting: chown apache. the apache-R/var/www/htmlMySQL database directory is/var/lib/mysql permission setting: chown mysql. mysql-R/var/lib/mysql

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.