Centos7搭建apache+php5.4环境以及apache性能优化

1.安装

  yum -y install httpd

2.开启apache服务

  systemctl start httpd.service

3.设置apache服务开机启动

  systemctl enable httpd.service

4.apache重启

  systemctl restart httpd

5.卸载

  yum erase httpd.x86_64


配置修改 /etc/httpd/conf/httpd.conf

  • AllowOverride None 讲None改为 All 在APACHE里面去配置 (注意其他地方的AllowOverride也统统设置为ALL)
    <Directory>
    AllowOverride ALL
    Options None
    Order allow,deny
    Allow from all
    </Directory>
  • 绑定 ServerName localhost:80

apache性能优化

配置修改 /etc/httpd/conf/httpd.conf

TraceEnable off
ServerTokens  Prod
ServerSignature  off

配置修改 /etc/httpd/conf.modules.d/00-mpm.conf

<IfModule mpm_prefork_module>
    StartServers 10
    MinSpareServers 10
    MaxSpareServers 20
    ServerLimit 2000
    MaxRequestWorkers 1500
    MaxConnectionsPerChild 10000
</IfModule>

配置修改 /etc/sysctl.conf

net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_fin_timeout = 30

php5.4安装

升级以下centos的软件仓库

#rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm

#rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

#yum -y install php

#yum -y install php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring

#yum -y install php-snmp php-soap curl curl-devel

#yum -y install epel-release //扩展包更新包

#yum -y update //更新yum源

#yum -y install gcc

#yum -y install tcl

#yum -y install php-mcrypt

安装php支持php-redis

  yum -y install php-redis

安装低版本php-redis

  yum -y install php-pecl-redis-2.2.8-1.el7.x86_64


ThinkPHP 去掉 public 和 index.php

保存到.htaccess文件下

<IfModule mod_rewrite.c>
 RewriteEngine on
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>

windows 统计连接80端口数

netstat -ano | find ":80" /c

linux 统计连接80端口数

netstat -nat|grep -i "80"|wc -l


标签:Centos7 apache php5.4 php-redis