试验要求: 在一台CentOS 6.5服务器上安装Apache、Nginx、PHP、Mysql服务。Apache处理动态PHP页面,Nginx作为前端服务器处理静态页面,并实现Nginx反向代理。 |
1、在安装前我们需要检查这些包安装没有,如何安装了我就卸载掉,并关闭防火墙。保证一台干净的服务器。
[root@localhost ~]#service iptables stop [root@localhost ~]#chkconfig iptables off [root@localhost ~]#vim /etc/sysconfig/selinux 修改此内容:SELINUX=disabled [root@localhost ~]#rpm -qa httpd [root@localhost ~]#rpm -qa php [root@localhost ~]#rpm -qa nginx [root@localhost ~]#rpm -qa mysql [root@localhost ~]#yum -y remove httpd {此处卸载只限于yum安装过的程序} [root@localhost ~]#yum -y remove php [root@localhost ~]#yum -y remove nginx [root@localhost ~]#yum -y remove mysql
|
2、这儿我们采用第三方源,因为在虚拟机里默认是没有Nginx的安装包的。
[root@localhost ~]#cd /etc/yum.repos.d/ [root@localhost ~]#wget http://www.atomicorp.com/installers/atomic [root@localhost ~]#sh ./atomic [root@localhost ~]#yum check-update |
3、安装Apache并修改端口为:8080 >>{因为Nginx会占用80端口}
[root@localhost ~]#yum install httpd 找到:Listen 80 修改为:Listen 8080 ServerName www.example.com:80 #注解去掉,改为相应的端口和域名 >>{访问WEB可以直接使用域名} [root@localhost ~]#service httpd start [root@localhost ~]#chkconfig httpd on 安装Apache扩展库 [root@localhost ~]#yum -y install httpd-manual mod_ssl mod_perl mod_auth_mysql |
4、安装PHP
[root@localhost ~]#yum install php php-devel php-mysql gd php-gd gd-devel php-common php-mbstring php-mcrypt php-ldap php-pear php-xml php-xmlrpc php-imap php-curl [root@localhost ~]#vim /etc/php.ini >>{编辑修改增加内容} cgi.fix_pathinfo =1 #将注释去掉,开启PHP的pathinfo功能,伪静态要用到。 max_execution_time = 0 #脚本运行的最长时间,默认30秒 |
5、安装Mysql
[root@localhost ~]#yum install mysql mysql-server mysql-devel [root@localhost ~]#service mysqld start [root@localhost ~]#chkconfig mysqld on [root@localhost ~]#mysql -u root 安装好的Mysql数据库默认是没有密码的,为了安全我们可以设置一个密码 [root@localhost ~]#mysqladmin -u root password 123456 >>{密码是123456 回车即可} [root@localhost ~]#mysql -u root -p {回车输入密码即可,或者mysql -u root -p123456} |
6、安装nginx
[root@localhost ~]#yum install nginx [root@localhost ~]#service nginx start [root@localhost ~]#chkconfig nginx on 修改配置文件,实现反向代理 [root@localhost ~]#vim /etc/nginx/conf.d/default.conf #修改location / 为以下内容,让其根目录与Apache的目录相同。 添加以下内容 location ~ \.php$ { proxy_pass http://127.0.0.1:8080;} |