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 1
2
| 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模块(默认开启),主配置文件: 1
| grep ^Include /etc/httpd/conf/httpd.conf
|
包含如下内容:
查看PHP支持模块配置文件: 1
| less /etc/httpd/conf.d/php.conf
|
包含如下内容: 1
2
3
4
5
6
7
8
9
10
11
| <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服务: 1
2
3
4
| /etc/init.d/httpd start
chkconfig httpd on
/etc/init.d/mysqld start
chkconfig mysqld on
|
注:关于MySQL的安全配置请运行,这里不再详述! 1
| mysql_secure_installation
|
2.3.3、step3 配置httpd服务 1)vim编辑/etc/httpd/conf/httpd.conf 启用并更改ServerName(去掉ServerName前面的#)
2)新建虚拟目录: 1
| mkdir /var/www/www.cmdschool.org
|
3)添加测试页面: 1
| echo '<?php phpinfo(); ?>' > /var/www/www.cmdschool.org/index.php
|
4)确保selinux是Enforcing状态:
5)恢复预设的selinux type: 1
| restorecon -RFvv /var/www/www.cmdschool.org/
|
显示如下: 1
| 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: 1
| ll -dZ /var/www/www.cmdschool.org/
|
7)设置虚拟目录: vim编辑/etc/httpd/conf.d/www.cmdschool.org.conf 1
2
3
4
5
6
7
8
9
| <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服务: 1
| /etc/init.d/httpd restart
|
2.3.4、step4 设置防火墙: vim编辑/etc/sysconfig/iptables 1
| -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
|
重启防火墙: 1
| /etc/init.d/iptables restart
|
2.4.5、step5 In client 测试服务器 1)vim编辑/etc/hosts
2)curl测试
|