Centos6和Centos7上安装LAMP(PHP-FPM模式、编译安装)

2021-05-15 13:01

阅读:549

标签:安装   centos6   lamp   

-------------------------实验:CentOS 7安装LAMP(PHP-FPM模式)---------------------

1、安装PHP-FPM

首先要卸载PHP: yum remove php

    yum install php-fpm

2、 查看php-fpm所对应的配置文件

rpm -ql php-fpm

    /usr/lib/systemd/system/php-fpm.service

    /etc/logrotate.d/php-fpm

    /etc/php-fpm.conf

    /etc/php-fpm.d

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

    /etc/sysconfig/php-fpm

    /run/php-fpm

3、PHP-FPM常见配置

vim /etc/php-fpm.d/www.conf

daemonize = no //是否将程序运行在后台

listen = 127.0.0.1:9000 //FPM 监听地址(php-fpm占用的是9000端口)

listen.backlog = -1 //等待队列的长度 -1表示无限制

listen.allowed_clients = 127.0.0.1 //仅允许哪些主机访问【可以用逗号隔开,添加多个地址】

pm = dynamic //PM开机进程是动态运行还是静态运行

//static 固定数量的子进程,pm.max_childen

//dynamic子进程数据以动态模式管理

pm.start_servers=数字         开机几个进程

pm.min_spare_servers=#   最少空闲几个进程

pm.max_spare_servers=#   最多空闲几个进程

pm.max_requests = 500   最多支持的并发请求

php_value[session.save_handler] = files

php_value[session.save_path] = /var/lib/php/session

//设置session存放位置

4、 启动PHP-FPM

    systemctl start php-fpm

5、 安装httpd包

    yum install httpd

6、查看Httpd mod_fcgi模块是否加载

    httpd -M | grep fcgi

    proxy_fcgi_module (shared)

7、 添加FCGI的配置文件

DirectoryIndex index.php

ProxyRequests off //是否开启正向代理

ProxyPassMatch ^/(.*\.php)$

fcgi://127.0.0.1:9000/var/www/html/$1 //开启FCGI反向代理

//前面的/相对于后面的/var/www/html而言,后面的$1是指前面的/(.*\.php)

8、 重启Httpd:systemctl start httpd

--------------------------实验:CentOS7编译安装LAMP----------------------------

在centos7上编译安装LAMP:

1、

mairadb:通用二进制格式,mariadb-5.5.56

httpd:编译安装,httpd-2.4.25

php5:编译安装,php-5.6.30

phpMyAdmin:安装phpMyAdmin-4.4.15.10-all-languages

Xcache:编译安装xcache-3.2.0

php5.4依赖于mariadb-devel包

顺序:mariadb-->httpd-->php

2、二进制安装mariadb

(1)ftp://172.16.0.1/pub/Source/7.x86_64/mariadb/mariadb-5.5-46-linux-x86_64.tar.gz

(2) tar xvf mariadb-5.5-46-linux-x86_64.tar.gz -C  /usr/local

(3)cd /usr/local

    ls -sv mariadb-5.5.46-linux-x86_64 mysql

(4)cd mysql

    chown -R root.mysql ./*

(5)mkdir /mydata/data -p

    chown -R mysql.mysql /mydata/data

(6)mkdir /etc/mysql

    cp support-files/my-large.cnf /etc/mysql/my.cnf

    vim /etc/mysql/my.cnf

        [mysqld]加三行

        datadir =/mydata/data

        innodb_file_per_table = ON

        skip_name_resolve = ON

(7)bin/mysqld --help --verbose |less

(8)scripts/mysql_install_db --user=mysql --datadir=/mydata/data

(9)cp support-files/mysql.server /etc/rc.d/init.d/mysqld

(10)chkconfig --add mysqld

        service mysqld start

(11)测试

    /usr/local/mysql/bin/mysql 测试是否成功

    vim /etc/profile.d/mysql.sh

            export PATH=/usr/local/mysql/bin/:$PATH

3、 编译安装httpd-2.4

(1)yum install pcre-devel apr-devel apr-util-devel   openssl-devel

(2)./configure --prefix=/app/httpd24 --

sysconfdir=/etc/httpd24 --enable-so --enable-ssl --

enable-rewrite --with-zlib --with-pcre --withapr=/usr

--with-apr-util=/usr --enable-modules=most

--enable-mpms-shared=all --with-mpm=prefork

(3)make -j 4 && make install

4、编译安装php-5.6

相关包:

(1)libxml2-devel bzip2-devel libmcrypt-devel (epel)

(2)  ./configure --prefix=/app/php --withmysql=/usr/local/mysql

--with-openssl --withmysqli=/usr/local/mysql/bin/mysql_config

--enablembstring

--with-png-dir --with-jpeg-dir --withfreetype-dir

--with-zlib --with-libxml-dir=/usr --

enable-xml --enable-sockets --withapxs2=/app/httpd24/bin/apxs

--with-mcrypt --withconfig-file-path=/etc

--with-config-file-scandir=/etc/php.d

--with-bz2

(3) make -j 4 && make install

5、编译安装php-7.1.7

(1) ./configure --prefix=/app/php --enable-mysqlnd --

with-mysqli=mysqlnd --with-openssl --with-pdomysql=mysqlnd

--enable-mbstring --with-freetype-dir

--with-jpeg-dir --with-png-dir --with-zlib --withlibxml-dir=/usr

--enable-xml --enable-sockets --

with-apxs2=/app/httpd24/bin/apxs --with-mcrypt --

with-config-file-path=/etc --with-config-file-scandir=/etc/php.d

--enable-maintainer-zts --disablefileinfo

注意:php-7.0以上版本使用--enable-mysqlnd --withmysqli=mysqlnd,原--with-mysql不再支持。

(2)为php提供配置文件

cp php.ini-production /etc/php.ini

(3) 编辑apache配置文件httpd.conf,以使apache支持php

vim /etc/httpd24/conf/httpd.conf

a.加二行

AddType application/x-httpd-php .php

AddType application/x-httpd-php-source .phps

b.定位至DirectoryIndex index.html

修改为DirectoryIndex index.php index.html

(4) apachectl restart

----------------------centos6上编译安装LAMP------------------------------

mairadb:通用二进制格式,mariadb-5.5.56

httpd:编译安装,httpd-2.4.27

php5:编译安装,php-5.6.30

Wordpress: 安装wordpress-4.8-zh_CN.tar.gz

Xcache:编译安装xcache-3.2.0

php5.4依赖于mariadb-devel包

实现顺序:mariadb-->httpd-->php

(1)编译httpd和二进制安装mariadb

安装相关包

bzip2-devel libxml2-devel libmcrypt-devel(epel源)

(2)编译安装php

cd php-5.6.30/

./configure --prefix=/app/php5 --withmysql=/usr/local/mysql

--with-openssl --withmysqli=/usr/local/mysql/bin/mysql_config

--enablembstring

--with-freetype-dir --with-jpeg-dir --

with-png-dir --with-zlib --with-libxml-dir=/usr --

enable-xml --enable-sockets --enable-fpm --withmcrypt

--with-config-file-path=/etc/php5 --withconfig-file-scan-dir=/etc/php5.d

--with-bz2

(3) make -j 4 && make install

(4)实现php的配置文件和服务脚本

mkdir /etc/php5 /etc/php5.d/

cd php-5.6.30/

cp php.ini-production /etc/php5/php.ini

cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm

chmod +x /etc/rc.d/init.d/php-fpm

chkconfig --add php-fpm

chkconfig --list php-fpm

(5)编辑php配置文件

cd /app/php5/etc

cp php-fpm.conf.default php-fpm.conf

vim /app/php5/etc/php-fpm.conf

pm.max_children = 50

pm.start_servers = 5

pm.min_spare_servers = 2

pm.max_spare_servers = 5 和pm.start_servers一致

pid = /app/php5/var/run/php-fpm.pid

(6) service php-fpm restart

(7)修改httpd24的配置文件

vim /app/apache24/conf/httpd.conf

说明:启用httpd的相关模块

在Apache httpd 2.4以后已经专门有一个模块针对FastCGI的实现,此模块为mod_proxy_fcgi.so,它其实是作为mod_proxy.so模块的扩充,因此,这两个模块都要加载去掉下面两行注释

LoadModule proxy_module modules/mod_proxy.so

LoadModule proxy_fcgi_module

modules/mod_proxy_fcgi.so

(8)添加如下二行

AddType application/x-httpd-php .php

AddType application/x-httpd-php-source .phps

(9)定位至DirectoryIndex index.html修改为:

DirectoryIndex index.php index.html

加下面两行

ProxyRequests Off 关闭正向代理

ProxyPassMatch ^/(.*\.php)$

fcgi://127.0.0.1:9000/app/httpd24/htdocs/$1

service httpd24 restart

(10)测试

vim /app/httpd24/htdocs/index.php

如下:

$link =

mysql_connect(‘127.0.0.1‘,‘root‘,‘magedu‘);

if ($link)

echo "Success...";

else

echo "Failure...";

mysql_close();

phpinfo();

?>

本文出自 “linux文件系统” 博客,请务必保留此出处http://13250262.blog.51cto.com/13240262/1977182

Centos6和Centos7上安装LAMP(PHP-FPM模式、编译安装)

标签:安装   centos6   lamp   

原文地址:http://13250262.blog.51cto.com/13240262/1977182


评论


亲,登录后才可以留言!