centOS7 LAMP安装及注意要点

在VM下安装了centos7体验一下,首先安装一下LAMP环境,以下:php

安装LAMP环境:mysql

一、apache2linux

# yum install -y httpd
# systemctl start httpd.service 启动
# systemctl enable httpd.service 开机自动启动
# vi /etc/httpd/conf/httpd.conf 默认配置文件
# systemctl restart httpd.service  重启

二、mysqlnginx

# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm

centOS最小安装,wget没有安装sql

# yum install -y wget
# rpm -ivh mysql-community-release-el7-5.noarch.rpm
# yum install mysql-community-server

成功安装以后重启mysql服务apache

# service mysqld restart

三、php5.6ubuntu

# 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执行速度。centos

# 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


注意要点:bash

一、Apache2.4目录权限有变动:服务器

Order Deny,Allow
Allow from All

换成

Require all granted

二、安装成功后要去掉目录预览页

cd /etc/httpd/conf.d
touch welcome.conf welcome #不去掉的话,访问老是apache提示页

三、Vhost

NameVirtualHost *:80 #虚拟主机,新的2.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>

五、要注意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  #重启防火墙

六、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模式

七、开机启动

#vi /etc/rc.local

/bin/systemctl start  httpd.service
/bin/systemctl start  nginx.service


#chmod +x /etc/rc.d/rc.local
必须加可执行权限,否则开机不能启动

 

最后预祝各位同窗顺利安装成功,下一篇会说apache加nginx作反向代理~

nginx与apache一块儿私奔-反向代理

相关文章
相关标签/搜索