
1 理论部分
LAMP 是Linux Apache MySQL PHP的简写,其实就是把Apache, MySQL以及PHP安装在Linux系统上,组成一个环境来运行php的脚本语言。
本文是测试Apache与PHP结合和创,搭建方法采用非常标准手法(开启SELinux),初学者可以直接使用。
2 实践部分
2.1 实践环境
lampSer:
hostname=lamp
ipaddress=10.168.0.170
client:
hostnmae=client
ipaddress=10.168.0.8
2.2 yum源的安装
In lampSer
yum -y install httpd php mysql mysql-server php-mysql yum -y install policycoreutils-python
2.3 配置部分
In lampSer
2.3.1 step1
注:如果你不想了解php的加载方式本步骤请直接跳过
检查是否引入php模块(默认开启),主配置文件:
grep ^Include /etc/httpd/conf/httpd.conf
包含如下内容:
Include conf.d/*.conf
查看PHP支持模块配置文件:
less /etc/httpd/conf.d/php.conf
包含如下内容:
<IfModule prefork.c> LoadModule php5_module modules/libphp5.so </IfModule> <IfModule worker.c> LoadModule php5_module modules/libphp5-zts.so </IfModule> AddHandler php5-script .php AddType text/html .php DirectoryIndex index.php
2.3.2 step2
启动httpd&mysqld服务:
/etc/init.d/httpd start chkconfig httpd on /etc/init.d/mysqld start chkconfig mysqld on
注:关于MySQL的安全配置请运行,这里不再详述!
mysql_secure_installation
2.3.3 step3
1)配置httpd服务
vim /etc/httpd/conf/httpd.conf
修改如下参数:
ServerName www.cmdschool.org:80 NameVirtualHost *:80
2)新建虚拟目录:
mkdir /var/www/www.cmdschool.org
3)添加测试页面:
echo '<?php phpinfo(); ?>' > /var/www/www.cmdschool.org/index.php
4)确保selinux是Enforcing状态:
getenforce
5)恢复预设的selinux type:
restorecon -RFvv /var/www/www.cmdschool.org/
显示如下:
restorecon reset /var/www/www.cmdschool.org/index.php context unconfined_u:object_r:httpd_sys_content_t:s0->system_u:object_r:httpd_sys_content_t:s0
6)检查当前的selinux type:
ll -dZ /var/www/www.cmdschool.org/
7)设置虚拟目录:
vim /etc/httpd/conf.d/www.cmdschool.org.conf
加入如下配置:
<VirtualHost *:80> DocumentRoot /var/www/www.cmdschool.org ServerName www.cmdschool.org </VirtualHost> <Directory /var/www/www.cmdschool.org> Options All AllowOverride all </Directory>
8)重启httpd服务:
/etc/init.d/httpd restart
2.3.4 step4
设置防火墙:
vim /etc/sysconfig/iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
重启防火墙:
/etc/init.d/iptables restart
2.4.5、step5
In client
1)测试服务器
vim /etc/hosts
确保包含www.cmdschool.org的指向10.168.0.170的唯一值:
10.168.0.170 www.cmdschool.org
2)curl测试
curl www.cmdschool.org
参阅资料:
——————————–
官方参阅资料
http://www.php.net/manual/zh/
http://php.net/manual/zh/install.unix.apache2.php
http://linux.vbird.org/linux_basic/0440processcontrol.php#semanage
没有评论