-------------------------实验:CentOS 7安装LAMP(PHP-FPM模式)---------------------
1、安装PHP-FPM
yum install 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)
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
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不再支持。
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
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
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
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
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
如下:
<?PHP
$link =
MysqL_connect('127.0.0.1','root','magedu');
if ($link)
echo "Success...";
else
echo "Failure...";
MysqL_close();
PHPinfo();
?>
原文链接:https://www.f2er.com/centos/375399.html