-------------------------實驗:CentOS 7安裝LAMP(PHP-FPM模式)---------------------php
一、安裝PHP-FPMhtml
首先要卸載PHP: yum remove php mysql
yum install php-fpmlinux
二、 查看php-fpm所對應的配置文件sql
rpm -ql php-fpmapache
/usr/lib/systemd/system/php-fpm.servicevim
/etc/logrotate.d/php-fpmcentos
/etc/php-fpm.confapi
/etc/php-fpm.dsession
/etc/php-fpm.d/www.conf
/etc/sysconfig/php-fpm
/run/php-fpm
三、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存放位置
四、 啓動PHP-FPM
systemctl start php-fpm
五、 安裝httpd包
yum install httpd
六、查看Httpd mod_fcgi模塊是否加載
httpd -M | grep fcgi
proxy_fcgi_module (shared)
七、 添加FCGI的配置文件
DirectoryIndex index.php
ProxyRequests off //是否開啓正向代理
ProxyPassMatch ^/(.*\.php)$
fcgi://127.0.0.1:9000/var/www/html/$1 //開啓FCGI反向代理
//前面的/相對於後面的/var/www/html而言,後面的$1是指前面的/(.*\.php)
八、 重啓Httpd:systemctl start httpd
--------------------------實驗:CentOS7編譯安裝LAMP----------------------------
在centos7上編譯安裝LAMP:
一、
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
二、二進制安裝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
三、 編譯安裝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
四、編譯安裝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
五、編譯安裝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();
?>