在VM下安装了centos7体验一下,首先安装一下LAMP环境,如下:
安装LAMP环境:
1、apache2
# yum install -y httpd
# systemctl start httpd.service 启动
# systemctl enable httpd.service 开机自动启动
# vi /etc/httpd/conf/httpd.conf 默认配置文件
# systemctl restart httpd.service 重启
2、mysql
# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
centOS最小安装,wget没有安装
# yum install -y wget
# rpm -ivh mysql-community-release-el7-5.noarch.rpm
# yum install mysql-community-server
成功安装之后重启mysql服务
# service mysqld restart
3、php5.6
# yum install --enablerepo=remi --enablerepo=remi-php56 php php-opcache php-pecl-apcu php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug php-pecl-xhprof php-pdo php-pear php-fpm php-cli php-xml php-bcmath php-process php-gd php-common
php-opcache及php-pecl-apcu会有效的提高php执行速度。
# php -v
PHP 5.6.19 (cli) (built: Mar 3 2016 07:57:20)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
with Xdebug v2.4.0, Copyright (c) 2002-2016, by Derick Rethans
注意要点:
1、Apache2.4目录权限有变更:
Order Deny,Allow
Allow from All
换成
Require all granted
2、安装成功后要去掉目录预览页
cd /etc/httpd/conf.d
touch welcome.conf welcome #不去掉的话,访问总是apache提示页
3、Vhost
NameVirtualHost *:80 #虚拟主机,新的2.4版本,这个指令不需要
4、虚拟主机设置,命令如下
<VirtualHost *:80>
DirectoryIndex index.php
ServerAdmin 123456@qq.com
DocumentRoot /www/lockcom
ServerName lock.com
ServerAlias lock.com
<Directory /www/lockcom>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
5、要注意iptables/firewall,如果iptables启用了,要加一个指令,以便80端口可以访问
iptables:
/usr/sbin/iptables -I INPUT -p TCP --dport 80 -j ACCEPT
firewall:
firewall-cmd --zone=public --add-port=80/tcp --permanent
命令含义:
--zone #作用域
--add-port=80/tcp #添加端口,格式为:端口/通讯协议
--permanent #永久生效,没有此参数重启后失效
firewall-cmd --reload #重启防火墙
6、selinux
如果启用了必须要关掉,否则访问虚拟主机域名时,会出现这个错误
forbidden you don't have permission to access / on this serve
这个错误查看apache错误日志才发现的,原来是selinux启用导致的。花了我很长时间找错误。长时间的不弄服务器,许多要点都忘记了
检测是否启用selinux
getenforce
如果显示“Enforcing”,则要关闭,命令如下:
setenforce 0
vi /etc/selinux/config,找到SELINUX 行修改成为:SELINUX=disabled:
# 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=disabled
# SELINUXTYPE= can take one of these two values:
# targeted - Only targeted network daemons are protected.
# strict - Full SELinux protection.
SELINUXTYPE=targeted
重启系统。
Centos还提供了实时改变SELinux工作模式的工具,前提是SELinux没有被disabled掉的时候
/usr/sbin/setenforce 0 #使SELinux工作模式变成permissive模式
/usr/sbin/setenforce 1 #使SELinux工作模式变成enforcing模式
7、开机启动
#vi /etc/rc.local
/bin/systemctl start httpd.service
/bin/systemctl start nginx.service
#chmod +x /etc/rc.d/rc.local
必须加可执行权限,不然开机不能启动
最后预祝各位同学顺利安装成功,下一篇会说apache加nginx做反向代理~