最近购买了阿里云服务器,系统CentOS 7.2,研究了搭建lamp环境和绑定多个网站 具体步骤如下:
首先搭建lamp环境: 1.关闭默认的firewall防火墙,配置iptables防火墙。
/* 停止firewall */ systemctl stop firewalld.service
/* 禁止firewall开机启动 */ systemctl disable firewalld.service
/* 安装iptables */ yum install iptables-services
/* 编辑文件 */ vi /etc/sysconfig/iptables
添加红框里的代码
/* ctrl+c :wq! 保存退出 */
/* 重启iptables */ systemctl restart iptables.service
/* 设置开机启动 */ systemctl enable iptables.service
/* 关闭seinux */ vi /etc/selinux/config
增加红框内的一行
/* 配置生效 */ setenforce 0
/* 安装apache */ yum install httpd
wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum install mysql-community-server
/* 重启mysql */ systemctl restarat mysqld.service
/* 设置数据库密码 eg:333333*/ mysql> set password for ‘root’@’localhost’ =password(‘333333’);
/* 远程连接设置 */ mysql> grant all privileges on . to root@’%’identified by ‘333333’;
yum install php
/* php组件 */ yum install php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash
/* 重启服务 */ service httpd restart service mysqld restart
/* 测试成果 */ cd /var/www/html vi index.php
/* 输入 */
<?php phpinfo(); ?>/* 访问 */ 浏览器中输入你的服务器ip地址,若能看到phpinfo的信息页面,说明配置成功了
/* 建立放网站的目录 */ cd /var/www mkdir site
/* 目录中分别放入测试文件 */ vi /var/www/html/index.php vi /var/www/site/index.php
/* 输入*/
html/index.php
<?php echo "this is site1"; ?>site/index.php
<?php echo "this is site2"; ?>:wq! 保存退出
/* 修改httpd.conf文件 */ cd /etc/httpd/conf vi httpd.conf
/* 开始访问 */ 若你的域名都绑定了服务器的ip并且成功解析,在浏览器中访问会有分别访问site 和 html中的index.php