1. 程式人生 > >Centos6和Centos7上安裝LAMP(PHP-FPM模式、編譯安裝)

Centos6和Centos7上安裝LAMP(PHP-FPM模式、編譯安裝)

安裝 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

如下:

<?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模式、編譯安裝)