首先该文件为公司服务器实体配置文档。
首先是安装CentOS6.4_86x64
安装软件为mini 最小化安装 安装勾选为:基础、java、prel 开发 默认设置未进去勾选
安装完成后,开始lamp环境搭建;选用yum安装5分钟搞定。php版本5.3.3
首先:开启防火墙端口:80 3306
[root@localhost ~]# cat /etc/sysconfig/iptables # 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
2关闭selinux
[root@localhost ~]# cat /etc/selinux/config # This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - No SELinux policy is loaded. #SELINUX=enforcing SELINUX=disabled # SELINUXTYPE= can take one of these two values: # targeted - Targeted processes are protected, # mls - Multi Level Security protection. #SELINUXTYPE=targeted 注释掉: #SELINUX=enforcing #SELINUXTYPE=targeted 修改为 SELINUX=disabled
3.查看是否已经存在httpd mysql php
rpm -qa | grep httpd rpm -qa | grep mysql rpm -qa | grep php
4保证环境是干净的以后开始安装,当然我的是最小化安装时不需要查看的
yum -y install httpd /etc/init.d/httpd start ##启动apache 备注:Apache启动之后会提示错误: 正在启动 httpd:httpd: Could not reliably determine the server's fully qualif domain name, using ::1 for ServerName 解决办法: vi /etc/httpd/conf/httpd.conf #编辑 找到 #ServerName www.example.com:80 修改为 ServerName localhost:80 #这里设置为你自己的域名,如果没有域名,可以设置为localhost :wq! #保存退出 chkconfig httpd on #设为开机启动 /etc/init.d/httpd restart #重启Apache
5安装mysql
yum -y install mysql mysql-server /etc/init.d/mysqld start #启动mysql chkconfig mysqld on #设置开机启动 cp /usr/share/mysql/my-medium.cnf /etc/my.cnf #拷贝配置文件(注意:如果/etc目录下面默认有一个my.cnf,直接覆盖即可) 2.为root用户设置密码 mysql_secure_installation ##运行 mysql_secure_installation 回车,根据提示输入Y 输入2次密码,回车 根据提示一路输入Y 注意!:Disallow root login remotely? [Y/n] (是否禁止root的远程登录)N 最后出现:Thanks for using MySQL! MySql密码设置完成,重新启动 MySQL: /etc/init.d/mysqld restart #重启 /etc/init.d/mysqld stop #停止 /etc/init.d/mysqld start #启动 用远程软件连接下mysql 如果连接不上可以用一下步骤: mysql -u root -p :password mysql>grant all on *.* to root@’%’ identified by ‘password′; mysql>quit /etc/init.d/mysqld restart
6安装php 和php的支持包
[root@localhost ~]# yum -y install php php-pdo php-ncurses php-bcmath php-odbc php-dba php-devel php-pear php-gd php-pgsql php-ldap php-soap php-mbstring php-xml php-mysql php-xmlrpc libjpeg* php-imap php-mcrypt php-bcmath php-mhash libmcrypt
重启下
/etc/init.d/mysqld restart #重启MySql
/etc/init.d/httpd restart #重启Apche
环境安装到此结束。
Apache 配置:
DirectoryIndex index.html 添加index.php Listen 80 ##下面增加 137 Listen 81 (137为行号) DocumentRoot "/opt/" 我的网站放在/opt/下 <Directory "/opt/"> 这里也设置下 NameVirtualHost *:80 开启虚拟主机 下面是放了两个基于端口的虚拟主机 <VirtualHost *:80> ServerAdmin webmaster@dummy-host.example.com DocumentRoot /opt/web/www/ ServerName dummy-host.example.com ErrorLog logs/dummy-host.example.com-error_log CustomLog logs/dummy-host.example.com-access_log common </VirtualHost> <VirtualHost *:81> ServerAdmin 1webmaster@dummy-host.example.com DocumentRoot /opt/web/www2/ ServerName dummy-host.example.com #ErrorLog logs/dummy-host.example.com-error_log #CustomLog logs/dummy-host.example.com-access_log common </VirtualHost>
KeepAlive Off 在76行 修改为:KeepAlive On (允许程序性联机) MaxKeepAliveRequests 100 在83行 修改为:MaxKeepAliveRequests 1000 (增加同时连接数) :wq! #保存退出 /etc/init.d/httpd restart #重启 rm -f /etc/httpd/conf.d/welcome.conf /var/www/error/noindex.html #删除默认测试页
配置php
vim /etc/php.ini
date.timezone = PRC #在946行 把前面的分号去掉,改为date.timezone = PRC 修改为中国时间 在386行 列出PHP可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用 expose_php = Off #在432行 禁止显示php版本的信息 magic_quotes_gpc = On #在745行 打开magic_quotes_gpc来防止SQL注入 short_open_tag = ON #在229行支持php短标签 :wq! #保存退出 /etc/init.d/mysqld restart #重启MySql /etc/init.d/httpd restart #重启Apche
网站更目录权限的设置:
权限设置:chown apache.apache -R /opt/web/
chmod -R 775 /opt/web/
lsof -i:80
netstat -apl | grep httpd
netstat -apl | grep mysqld
echo "<? phpinfo(); ?>" > /opt/web/index.php
重启apache 浏览器浏览 ip地址: