当前位置: 移动技术网 > IT编程>开发语言>PHP > Centos6.x下Apache-mysql-php优化

Centos6.x下Apache-mysql-php优化

2018年02月12日  | 移动技术网IT编程  | 我要评论

Centos6.x下Apache-mysql-php优化

1.php优化:
视情况而定:
有时需要mysql连接需要随开随关
有时需要保持连接


2.apache:

每个Apache配置对于每个部署都是唯一的。
禁用不必要的PHP扩展和微调内存使用和php.ini文件中的其他设置。

适当工作模式的切换:
三个模式

该preforkMPM使用多个子进程,不必穿线。每个进程一次处理一个连接,而不为每个进程创建单独的线程。在不涉及太多细节的情况下,我们可以说只有在调试使用或如果应用程序需要处理非线程安全模块(如mod_php)的应用程序时,才需要使用此MPM。 该workerMPM使用每个子进程,每个线程处理一次一个连接多个线程。这是高流量服务器的一个不错的选择,因为它允许使用比前一种情况更少的RAM来处理更多的并发连接。 最后,event对于版本2.4及更高版本,MPM是大多数Apache安装中的默认MPM。它类似于工人MPM,它也为每个子进程创建多个线程,但有一个优点:它导致KeepAlive或空闲连接(当它们保持在该状态)由单个线程处理,从而释放可以分配给其他线程。这个MPM不适合使用非线程安全模块,如mod_php,因此必须使用替换这样的PHP-FPM。

切换方法:
默认为prefork模式,主要是考虑到稳定性的原因。
要切换到worker模式,则需要登录到linux上,进行如下操作:

进入/usr/sbin目录 将当前的prefork模式启动文件改名,将worker模式的启动文件改名
cd /usr/sbin
mv httpd httpd.prefork
mv httpd.worker httpd
//修改配置文件vi /etc/httpd/conf/httpd.conf
//找到里边的如下一段,可适当修改负载等参数:

StartServers 2
MaxClients 150
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 0

重新启动服务

/etc/init.d/httpd restart
即可换成worker方式启动apache2

注意这里可能会遇到错误:

**1.Apache is running a threaded MPM, but your PHP Module is not
compiled to be threadsafe. You need to recompile PHP.
Pre-configuration failed!**

解决方法是将/etc/httpd/conf.d/php.conf文件中的LoadModule开头的那行代码注释掉。
2.can’t load libphp5-zts.so

解决办法:
You need to install php-zts package:

Name : php-zts
Version : 5.3.8
Release : 2.el5.art
Architecture: x86_64
Size : 4210728
Packager : None
Group : Development/Languages
URL :
Repository : atomic
Summary : Thread-safe PHP interpreter for use with the Apache HTTP Server
Description :
The php-zts package contains a module for use with the Apache HTTP
Server which can operate under a threaded server processing model.
and make sure that this extension exists in /etc/httpd/modules:

ls -l /etc/httpd/modules/libphp5-zts.so
-rwxr-xr-x 1 root root 4210728 Nov 1 05:29 /etc/httpd/modules/libphp5-zts.so


3.Mysql

1) 最大连接数的设置。
2) 索引的添加。!!! 百万条数据加上索引能够很快查找到想要的数据
alter table test add index(t_name);

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网