LNMP架构环境搭建之PHP、Nginx源码编译安装及其简单配置应用
LNMP架構(gòu)中的Mysql見(jiàn)上一篇博文“LNMP架構(gòu)環(huán)境搭建之mysql源碼編譯安裝”
一、PHP簡(jiǎn)介
PHP(外文名:PHP: Hypertext Preprocessor,中文名:“超文本預(yù)處理器”)是一種通用開(kāi)源腳本語(yǔ)言。語(yǔ)法吸收了C語(yǔ)言、Java和Perl的特點(diǎn),利于學(xué)習(xí),使用廣泛,主要適用于Web開(kāi)發(fā)領(lǐng)域。PHP 獨(dú)特的語(yǔ)法混合了C、Java、Perl以及PHP自創(chuàng)的語(yǔ)法。它可以比CGI或者Perl更快速地執(zhí)行動(dòng)態(tài)網(wǎng)頁(yè)。用PHP做出的動(dòng)態(tài)頁(yè)面與其他的編程語(yǔ)言相比,PHP是將程序嵌入到HTML(標(biāo)準(zhǔn)通用標(biāo)記語(yǔ)言下的一個(gè)應(yīng)用)文檔中去執(zhí)行,執(zhí)行效率比完全生成HTML標(biāo)記的CGI要高許多;PHP還可以執(zhí)行編譯后代碼,編譯可以達(dá)到加密和優(yōu)化代碼運(yùn)行,使代碼運(yùn)行更快。
二、PHP的源碼安裝
這里源碼安裝的PHP版本為5.6.35,使用./configure編譯安裝,PHP源碼安裝所需安裝包有php-5.6.35.tar.bz2,gd-devel-2.0.35-11.el6.x86_64.rpm,re2c-0.13.5-1.el6.x86_64.rpm,libmcrypt-2.5.8-9.el6.x86_64.rpm,libmcrypt-devel-2.5.8-9.el6.x86_64.rpm,下載鏈接是(點(diǎn)擊下載):PHP
編譯安裝
這里是我在編譯安裝過(guò)程中需要解決的依賴性
[root@server1 ~]# yum install -y libxml2-devel openssl-devel curl-devel gd-devel-2.0.35-11.el6.x86_64.rpm gmp-devel libmcrypt-2.5.8-9.el6.x86_64.rpm libmcrypt-devel-2.5.8-9.el6.x86_64.rpm net-snmp-devel
[root@server1 ~]# rpm -ivh re2c-0.13.5-1.el6.x86_64.rpm編譯(添加參數(shù) ./configure –help查看)
[root@server1 ~]# cd php-5.6.35
[root@server1 php-5.6.35]# ./configure --prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc --with-mysql=mysqlnd --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir --with-png-dir --with-jpeg-dir --with-freetype-dir --with-pear --with-gettext --with-gmp --enable-inline-optimization --enable-soap --enable-ftp --enable-sockets --enable-mbstring --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-mcrypt --with-mhash
[root@server1 php-5.6.35]# make && make install
PHP簡(jiǎn)單配置
三、Nginx的源碼安裝
nginx 是一個(gè)高性能的web服務(wù)器,其主要的特點(diǎn)在于能夠解決超高并發(fā)訪問(wèn)的問(wèn)題,同時(shí)nginx也擁有負(fù)載均衡和反向代理的能力。這也是我們搭建lnmp的核心軟件之一。
這里源碼安裝的Nginx版本為1.10.1,使用./configure編譯安裝,Nginx源碼安裝所需安裝包有nginx-1.10.1.tar.gz,nginx-sticky-module-ng.tar.gz,下載鏈接是(點(diǎn)擊下載):Nginx
配置編譯安裝
[root@server1 nginx-1.10.1]# ./configure --prefix=/usr/local/lnmp/nginx --with-http_ssl_module --with-http_stub_status_module --user=nginx --group=nginx --with-file-aio --with-threads
問(wèn)題
解決
[root@server1 nginx-1.10.1]# ./configure --prefix=/usr/local/lnmp/nginx --with-http_ssl_module --with-http_stub_status_module --user=nginx --group=nginx --with-file-aio --with-threads
[root@server1 nginx-1.10.1]# make && make install
簡(jiǎn)單配置
測(cè)試nginx
PHP與Nginx配合使用
訪問(wèn)172.25.54.9/index.php
[root@server1 ~]# vim /usr/local/lnmp/nginx/conf/nginx.conf ##改變默認(rèn)發(fā)布文檔43 location / {44 root html;45 index index.php index.html index.htm;46 } [root@server1 ~]# nginx -s reload [root@server1 ~]#訪問(wèn)172.25.54.9
應(yīng)用——論壇搭建管理
首先下載論壇的壓縮文件Discuz_X3.2_SC_UTF8.zip,下載地址:Discuz
然后我們就開(kāi)始吧
[root@server1 ~]# rm -f /usr/local/lnmp/nginx/html/bbs/install/index.php
PHP擴(kuò)展——mencache緩存模塊
首先下載memcache的壓縮文件memcache-2.2.5.tgz,下載地址:Memcache
[root@server1 ~]# tar zxf memcache-2.2.5.tgz [root@server1 ~]# ls cmake-2.8.12.2-4.el6.x86_64.rpm memcache-2.2.5.tgz nginx-sticky-module-ng.tar.gz Discuz_X3.2_SC_UTF8.zip mysql-5.7.11 package.xml gd-devel-2.0.35-11.el6.x86_64.rpm mysql-boost-5.7.11.tar.gz php-5.6.35 libmcrypt-2.5.8-9.el6.x86_64.rpm nginx-1.10.1 php-5.6.35.tar.bz2 libmcrypt-devel-2.5.8-9.el6.x86_64.rpm nginx-1.10.1.tar.gz re2c-0.13.5-1.el6.x86_64.rpm memcache-2.2.5 nginx-sticky-module-ng [root@server1 ~]# cd memcache-2.2.5 [root@server1 memcache-2.2.5]# ls config9.m4 CREDITS memcache_consistent_hash.c memcache_queue.c memcache_standard_hash.c config.m4 example.php memcache.dsp memcache_queue.h php_memcache.h config.w32 memcache.c memcache.php memcache_session.c README [root@server1 memcache-2.2.5]# vim ~/.bash_profile 10 PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin:/usr/local/lnmp/nginx/sbin:/usr/local/lnmp/php/bin [root@server1 memcache-2.2.5]# source ~/.bash_profile [root@server1 memcache-2.2.5]# phpize ##phpize是用來(lái)擴(kuò)展php擴(kuò)展模塊的,通過(guò)phpize可以建立php的外掛模塊 Configuring for: PHP Api Version: 20131106 Zend Module Api No: 20131226 Zend Extension Api No: 220131226 [root@server1 memcache-2.2.5]# ls acinclude.m4 config.h.in CREDITS memcache_consistent_hash.c memcache_standard_hash.c aclocal.m4 config.m4 example.php memcache.dsp missing autom4te.cache config.sub install-sh memcache.php mkinstalldirs build configure ltmain.sh memcache_queue.c php_memcache.h config9.m4 configure.in Makefile.global memcache_queue.h README config.guess config.w32 memcache.c memcache_session.c run-tests.php [root@server1 memcache-2.2.5]# ./configure [root@server1 memcache-2.2.5]# make && make install [root@server1 memcache-2.2.5]# cd /usr/local/lnmp/php/lib/php/extensions/no-debug-non-zts-20131226/ [root@server1 no-debug-non-zts-20131226]# ls memcache.so opcache.a opcache.so [root@server1 no-debug-non-zts-20131226]# pwd /usr/local/lnmp/php/lib/php/extensions/no-debug-non-zts-20131226 [root@server1 no-debug-non-zts-20131226]# php -m | grep memcache [root@server1 no-debug-non-zts-20131226]# vim /usr/local/lnmp/php/etc/php.ini 873 extension=memcache.so [root@server1 no-debug-non-zts-20131226]# /etc/init.d/php-fpm reload Reload service php-fpm done [root@server1 no-debug-non-zts-20131226]# php -m | grep memcache memcache [root@server1 no-debug-non-zts-20131226]# cd [root@server1 ~]# yum install -y memcached [root@server1 ~]# /etc/init.d/memcached start Starting memcached: [ OK ] [root@server1 ~]# netstat -antlp | grep memcached tcp 0 0 0.0.0.0:11211 0.0.0.0:* LISTEN 22636/memcached tcp 0 0 :::11211 :::* LISTEN 22636/memcached [root@server1 ~]# cp memcache-2.2.5/memcache.php /usr/local/lnmp/nginx/html/ [root@server1 ~]# cp memcache-2.2.5/example.php /usr/local/lnmp/nginx/html/ [root@server1 ~]# vim /usr/local/lnmp/nginx/html/memcache.php 23 define('ADMIN_PASSWORD','redhat'); // Admin Password28 $MEMCACHE_SERVERS[] = 'localhost:11211'; // add more as an array29 #$MEMCACHE_SERVERS[] = 'mymemcache-server2:11211'; // add more as an array
Openresty與Nginx簡(jiǎn)單配置
首先下載openresty的壓縮文件openresty-1.13.6.1.tar.gz,下載地址:Openresty
[root@server1 ~]# nginx -s stop ##將先前開(kāi)啟的nginx停掉 [root@server1 ~]# tar zxf openresty-1.13.6.1.tar.gz [root@server1 ~]# ls cmake-2.8.12.2-4.el6.x86_64.rpm mysql-5.7.11 openresty-1.13.6.1.tar.gz Discuz_X3.2_SC_UTF8.zip mysql-boost-5.7.11.tar.gz package.xml gd-devel-2.0.35-11.el6.x86_64.rpm nginx-1.10.1 php-5.6.35 libmcrypt-2.5.8-9.el6.x86_64.rpm nginx-1.10.1.tar.gz php-5.6.35.tar.bz2 libmcrypt-devel-2.5.8-9.el6.x86_64.rpm nginx-sticky-module-ng re2c-0.13.5-1.el6.x86_64.rpm memcache-2.2.5 nginx-sticky-module-ng.tar.gz memcache-2.2.5.tgz openresty-1.13.6.1 [root@server1 ~]# cd openresty-1.13.6.1 [root@server1 openresty-1.13.6.1]# ./configure --prefix=/usr/local/lnmp/openresty --with-http_ssl_module --with-http_stub_status_module --user=nginx --group=nginx --with-file-aio --with-threads [root@server1 openresty-1.13.6.1]# gmake && gmake install [root@server1 openresty-1.13.6.1]# cd /usr/local/lnmp/openresty/nginx/ [root@server1 nginx]# ls conf html logs sbin [root@server1 nginx]# vim conf/nginx.conf [root@server1 nginx]#19 upstream memcache {20 server localhost:11211;21 keepalive 512;22 }49 location / {50 root html;51 index index.php index.html index.htm;52 }53 location /memc {54 internal;55 memc_connect_timeout 100ms;56 memc_send_timeout 100ms;57 memc_read_timeout 100ms;58 set $memc_key $query_string;59 set $memc_exptime 300;60 memc_pass memcache;61 }80 location ~ \.php$ {81 root html;82 fastcgi_pass 127.0.0.1:9000;83 fastcgi_index index.php;84 #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;85 include fastcgi.conf;86 } [root@server1 nginx]# /usr/local/lnmp/openresty/nginx/sbin/nginx -t nginx: the configuration file /usr/local/lnmp/openresty/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/lnmp/openresty/nginx/conf/nginx.conf test is successful [root@server1 nginx]# /usr/local/lnmp/openresty/nginx/sbin/nginx [root@server1 nginx]# [root@server1 nginx]# cd html/ [root@server1 html]# pwd /usr/local/lnmp/openresty/nginx/html [root@server1 html]# cp /usr/local/lnmp/nginx/html/example.php . [root@server1 html]# cp /usr/local/lnmp/nginx/html/index.php . [root@server1 html]#
總結(jié)
以上是生活随笔為你收集整理的LNMP架构环境搭建之PHP、Nginx源码编译安装及其简单配置应用的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: LNMP架构环境搭建之mysql源码编译
- 下一篇: php中0与NULL,False,“0”