#部署LAMP环境#系统环境:OS:CentOS release 6.6HostName:server.example.comIP:192.168.1.100
#配置防火墙,允许80,3306端口iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPTiptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPTservice iptables save#配置SELinuxvim /etc/sysconfig/selinux SELINUX=permissivesetenforce 0
#安装Apacheyum -y install httpdservice httpd startchkconfig httpd on
#安装MySQLyum -y install mysql mysql-serverservice mysqld startchkconfig mysqld oncp /usr/share/mysql/my-medium.cnf /etc/my.cnf mysql_secure_installation #回车,根据提示输入Y,输入2次密码,设置MySQL密码,回车根据提示一路输入Y最后出现:Thanks for using MySQL!service mysqld restart
#安装PHPyum -y install php php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpcservice mysqld restart service httpd restart
#配置Apache服务vim /etc/httpd/conf/httpd.confServerTokens OS #44行修改为:ServerTokens Prod(出现错误页不显示操作系统名称)ServerSignature On #536行修改为:ServerSignature Off (错误页中不显示Apache的版本)Options Indexes FollowSymLinks #331行修改为:Options Includes ExecCGI FollowSymLinks(允许服务器执行CGI及SSI,禁止列出目录)#AddHandler cgi-script .cgi #796行修改为:AddHandler cgi-script .cgi .pl (取消注释允许扩展名为.pl的CGI脚本运行)AllowOverride None #338行修改为:AllowOverride All (允许.htaccess)AddDefaultCharset UTF-8 #759行 修改为:AddDefaultCharset GB2312(添加GB2312为默认编码)Options Indexes MultiViews FollowSymLinks #554行修改为 Options MultiViews FollowSymLinks(不在浏览器上显示树状目录结构)DirectoryIndex index.html index.html.var #402行修改为:DirectoryIndex index.html index.htm Default.html Default.htm index.php Default.php index.html.var(设置默认首页文件,增加index.php)KeepAlive Off #76行修改为:KeepAlive On (允许程序性联机)MaxKeepAliveRequests 100 #83行 改为:MaxKeepAliveRequests 1000 (增加同时连接数)service httpd restart
#配置PHP服务vim /etc/php.inidate.timezone = PRC #946行把前面的分号去掉修改为date.timezone = PRCdisable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname #386行列出PHP可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用expose_php = Off #438行禁止显示php版本的信息magic_quotes_gpc = On #751行打开magic_quotes_gpc来防止SQL注入short_open_tag = ON #229行支持php短标签open_basedir = .:/tmp/ #380行设置表示允许访问当前目录(即PHP脚本文件所在之目录)和/tmp/目录,可以防止php***跨
#重启服务service mysqld restartservice httpd restart
#写测试页面vim /var/www/html/index.php
#在浏览器地址栏输入LAMP服务器的ip地址或对应ip的域名即可看到测试页面;