centos 7 安装和配置apache

1、安装apache非常简单

 yum install httpd

2、配置参数

vi /etc/httpd/conf/httpd.conf

修改网站根目录路径

DocumentRoot "/home/wwwroot"
<Directory "/home/wwwroot">
    AllowOverride None
    # Allow open access:
    Require all granted
</Directory>

<Directory "/home/wwwroot">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride None

    #
    # Controls who can get stuff from this server.
    #
    Require all granted
</Directory>

3、启动apache服务

systemctl start httpd.service

4、禁止网站目录中某个文件夹的访问

让apache识别.htaccess文件

vi /etc/httpd/conf/httpd.conf
<Directory >
    AllowOverride All
    # Allow open access:
    Require all granted
</Directory>

在要禁止访问的目录上添加 .htaccess文件内容如下

order deny,allow
deny from ./
顺便提供一个在线生成.htaccess文件的网站:
http://www.babaw.com/htaccess/#a_access

重新启动apche服务,可生效 

systemctl restart httpd.service

5、禁止列出目录中文件列表

扫描二维码关注公众号,回复: 1009574 查看本文章
vi /etc/httpd/conf/httpd.conf
将  

Options Indexes FollowSymLinks


改成

 Options None

6、设置apache开机自动启动

chkconfig --levels 235 httpd on 

7、安装php7

复制代码
#更新yum源(默认yum源中无php7)
rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm  

#安装php及常用的拓展模块
yum -y install php70w php70w-mysql php70w-mbstring php70w-mcrypt php70w-gd php70w-imap php70w-ldap php70w-odbc php70w-pear php70w-xml php70w-xmlrpc php70w-pdo

#查看php安装了那些拓展模块
php -m

#安装其他你需要的拓展模块
yum -y install php70w-xxx


猜你喜欢

转载自blog.csdn.net/herobacking/article/details/80371343