Centos 7 安装LAMP并配置event MPM和FastCGI

 •  Filed under centos, centos7, apache

安装工具软件

sudo yum install nano wget -y
sudo yum update -y
安装Apache
sudo yum install httpd -y
配置MPM
sudo nano /etc/httpd/conf.modules.d/00-mpm.conf

注释掉prefork MPM并取消event MPM的注释,完成后是这样的(注释已删除)

#LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
#LoadModule mpm_worker_module modules/mod_mpm_worker.so
LoadModule mpm_event_module modules/mod_mpm_event.so
启动apache
sudo systemctl start httpd
sudo systemctl enable httpd

访问 http://服务器IP 应该可以看到Apache测试页面

安装PHP-FPM 7.0

PHP5.6使用Remi's RPM源安装

sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm yum-utils -y
sudo yum-config-manager --enable remi-php70
sudo yum update
sudo yum install php-cli php-fpm -y
配置php
sudo nano /etc/php.ini

找到expose_php = On替换为expose_php = Off
配置php-fpm

sudo nano /etc/php-fpm.d/www.conf

替换listen = 127.0.0.1:9000listen = /var/run/php-fpm/php-fpm.sock
替换

;listen.owner = nobody
;listen.group = nobody

listen.owner = apache
listen.group = apache
启动php-fpm
sudo systemctl start php-fpm
sudo systemctl enable php-fpm
配置Apache使用mod_proxy_fcgi

删除原本的mod_php相关(如果有)

yum remove php -y

添加fcgi handler

sudo nano /etc/httpd/conf.d/php.conf

内容如下

AddType text/html .php
DirectoryIndex index.php
<IfModule mod_proxy_fcgi.c>
    <Proxy "unix:/var/run/php-fpm/php-fpm.sock|fcgi://localhost">
        ProxySet timeout=3600 connectiontimeout=3600
    </Proxy>

    <FilesMatch \.php$>
        SetHandler "proxy:fcgi://localhost"
    </FilesMatch>
</IfModule>
重启Apache
sudo systemctl restart httpd
测试
sudo sh -c "echo '<?php phpinfo();?>' > /var/www/html/info.php"
curl http://127.0.0.1/info.php
安装MariaDB(MySQL)
sudo yum install mariadb mariadb-server -y
启动数据库
sudo systemctl start mariadb
sudo systemctl enable mariadb
初始化MySQL数据库
sudo mysql_secure_installation

按需求回应,初始root密码为空,其它保持默认就可以。

安装php-mysqlnd
sudo yum install php-mysqlnd

重启php-fpm

sudo systemctl restart php-fpm