个人折腾经历,非专业,不具有普适性,如果对你有帮助请点个赞。有什么错误欢迎指正,好的建议也请告诉我。

安装apache

yum install httpd httpd-devel

启动apache服务

systemctl start  httpd

设置httpd服务开机启动

systemctl enable  httpd

查看服务状态

systemctl status httpd

阿里云ECS要注意安全组开启80端口 如果有https还要开启443端口
检查下端口监听状态

netstat -tulp

安装数据库、PHP将php与mysql关联起来、 安装常用PHP模块

yum install mariadb mariadb-server mariadb-libs mariadb-devel
yum -y install php
yum install php-mysql
yum install -y php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel php-bcmath

很重要 后面就会发现

rpm -ql php-mysql

重启apache服务器

systemctl restart httpd

安装完成以后在修改apache最大连接数的时候我们发现
由于是通过yum安装的apache
vi /etc/httpd.conf
发现 没有相关配置项 但是有发现下面这行

加载conf.modules.d/下面的所有配置文件
然后发现有00-mpm-conf 
vi 00-mpm-conf

 可以看到 默认加载prefork模块 但是依旧没有相关配置

考虑到是通过yum安装
rpm -ql httpd
list httpd所有文件安装目录用mpm的关键词找到了这个文件
 
/usr/share/doc/httpd-2.4.6/httpd-mpm.conf
 
mpm_prefork.conf文件内容如下:按照需要进行修改即可

<IfModule mpm_prefork_module>
    StartServers         10         # 启动时进程数
    MinSpareServers      5          # 最小空闲进程数
    MaxSpareServers      10         # 最大空闲进程数
    MaxRequestWorkers    100        # 最大并发进程数
    MaxConnectionsPerChild   10000  # 最大连接数限制
</IfModule>

调整mysql数据库最大连接数
CentOS7调整数据库最大连接数和之前版本有些不同
 
查看mariadb数据库最大连接数,默认为151

MariaDB [(none)]> show variables like 'max_connections';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections |  151  |
+-----------------+-------+

 
配置/etc/my.cnf
[mysqld]新添加一行如下参数:
max_connections=1000
 
重启mariadb服务,再次查看mariadb数据库最大连接数,可以看到最大连接数是214,并非我们设置的1000。

MariaDB [(none)]> show variables like 'max_connections';
 Variable_name    Value 
 max_connections   214  

这是由于mariadb有默认打开文件数限制。可以通过配置/usr/lib/systemd/system/mariadb.service来调大打开文件数目。
 
配置/usr/lib/systemd/system/mariadb.service
[Service]新添加两行如下参数:
LimitNOFILE=10000
LimitNPROC=10000
 
重新加载系统服务,并重启mariadb服务
systemctl --system daemon-reload
systemctl restart mariadb.service
再次查看mariadb数据库最大连接数,可以看到最大连接数已经是1000

MariaDB [(none)]> show variables like 'max_connections';
 Variable_name    Value 
 max_connections  1000  

修改apache的最大连接数部分参考:
 
调整mysql数据库最大连接数部分参考:
@jim_hwg 的文章 原文:https://blog.csdn.net/hnhuangyiyang/article/details/51132141