日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > php >内容正文

php

LNMP架构环境搭建之PHP、Nginx源码编译安装及其简单配置应用

發(fā)布時(shí)間:2025/3/19 php 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 LNMP架构环境搭建之PHP、Nginx源码编译安装及其简单配置应用 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

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

  • 編譯安裝

[root@server1 ~]# ls cmake-2.8.12.2-4.el6.x86_64.rpm libmcrypt-devel-2.5.8-9.el6.x86_64.rpm php-5.6.35.tar.bz2 gd-devel-2.0.35-11.el6.x86_64.rpm mysql-5.7.11 re2c-0.13.5-1.el6.x86_64.rpm libmcrypt-2.5.8-9.el6.x86_64.rpm mysql-boost-5.7.11.tar.gz [root@server1 ~]# tar jxf php-5.6.35.tar.bz2 ##解壓PHP源文件 [root@server1 ~]# ls cmake-2.8.12.2-4.el6.x86_64.rpm libmcrypt-devel-2.5.8-9.el6.x86_64.rpm php-5.6.35 gd-devel-2.0.35-11.el6.x86_64.rpm mysql-5.7.11 php-5.6.35.tar.bz2 libmcrypt-2.5.8-9.el6.x86_64.rpm mysql-boost-5.7.11.tar.gz re2c-0.13.5-1.el6.x86_64.rpm
  • 這里是我在編譯安裝過(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)單配置

[root@server1 php-5.6.35]# cd /usr/local/lnmp/php/etc [root@server1 etc]# ll total 28 -rw-r--r-- 1 root root 1288 Aug 5 12:47 pear.conf -rw-r--r-- 1 root root 23089 Aug 5 12:46 php-fpm.conf.default [root@server1 etc]# cp php-fpm.conf.default php-fpm.conf [root@server1 etc]# ls pear.conf php-fpm.conf php-fpm.conf.default [root@server1 etc]# cd - /root/php-5.6.35 [root@server1 php-5.6.35]# cp php.ini-production /usr/local/lnmp/php/etc/php.ini [root@server1 php-5.6.35]# vim /usr/local/lnmp/php/etc/php.ini 936 date.timezone = Asia/Shanghai ##取消注釋,并加上時(shí)區(qū) [root@server1 php-5.6.35]# vim /usr/local/lnmp/php/etc/php-fpm.conf25 pid = run/php-fpm.pid ##取消注釋##創(chuàng)建一個(gè)nginx用戶,可以方便將后面的nginx和php結(jié)合使用 [root@server1 php-5.6.35]# id nginx id: nginx: No such user [root@server1 php-5.6.35]# useradd -M -d /usr/local/lnmp/nginx -s /sbin/nologin nginx [root@server1 php-5.6.35]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm [root@server1 php-5.6.35]# chmod +x /etc/init.d/php-fpm ##測(cè)試腳本啟動(dòng) [root@server1 php-5.6.35]# /etc/init.d/php-fpm start Starting php-fpm done [root@server1 php-5.6.35]# /etc/init.d/php-fpm status php-fpm (pid 16106) is running... [root@server1 ~]# netstat -antlp | grep php Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 16106/php-fpm

三、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 ~]# ls cmake-2.8.12.2-4.el6.x86_64.rpm mysql-5.7.11 php-5.6.35 gd-devel-2.0.35-11.el6.x86_64.rpm mysql-boost-5.7.11.tar.gz php-5.6.35.tar.bz2 libmcrypt-2.5.8-9.el6.x86_64.rpm nginx-1.10.1.tar.gz re2c-0.13.5-1.el6.x86_64.rpm libmcrypt-devel-2.5.8-9.el6.x86_64.rpm nginx-sticky-module-ng.tar.gz [root@server1 ~]# tar zxf nginx-1.10.1.tar.gz [root@server1 ~]# tar zxf nginx-sticky-module-ng.tar.gz [root@server1 ~]# ls cmake-2.8.12.2-4.el6.x86_64.rpm mysql-boost-5.7.11.tar.gz php-5.6.35 gd-devel-2.0.35-11.el6.x86_64.rpm nginx-1.10.1 php-5.6.35.tar.bz2 libmcrypt-2.5.8-9.el6.x86_64.rpm nginx-1.10.1.tar.gz re2c-0.13.5-1.el6.x86_64.rpm libmcrypt-devel-2.5.8-9.el6.x86_64.rpm nginx-sticky-module-ng mysql-5.7.11 nginx-sticky-module-ng.tar.gz [root@server1 ~]# cd nginx-1.10.1 [root@server1 nginx-1.10.1]# vim src/core/nginx.h14 #define NGINX_VER "nginx" ##刪除版本號(hào) [root@server1 nginx-1.10.1]# vim auto/cc/gcc 178 # debug 179 #CFLAGS="$CFLAGS -g" ##加上注釋

[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)單配置

[root@server1 nginx-1.10.1]# cd [root@server1 ~]# vim /usr/local/lnmp/nginx/conf/nginx.conf13 worker_connections 65535;65 location ~ \.php$ {66 root html;67 fastcgi_pass 127.0.0.1:9000;68 fastcgi_index index.php;69 # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;70 include fastcgi.conf;71 } [root@server1 ~]# vim /etc/security/limits.conf 51 nginx - nofile 65536 [root@server1 ~]# vim .bash_profile 10 PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin:/usr/local/lnmp/nginx/sbin [root@server1 ~]# source .bash_profile [root@server1 ~]# nginx -t nginx: the configuration file /usr/local/lnmp/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/lnmp/nginx/conf/nginx.conf test is successful [root@server1 ~]# nginx [root@server1 ~]# netstat -antlp | grep nginx Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 19755/nginx [root@server1 ~]#

測(cè)試nginx

  • PHP與Nginx配合使用

[root@server1 ~]# vim /usr/local/lnmp/nginx/html/index.php [root@server1 ~]# cat /usr/local/lnmp/nginx/html/index.php <?php phpinfo() ?> [root@server1 ~]#

訪問(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 ~]# ls cmake-2.8.12.2-4.el6.x86_64.rpm mysql-5.7.11 nginx-sticky-module-ng.tar.gz Discuz_X3.2_SC_UTF8.zip mysql-boost-5.7.11.tar.gz php-5.6.35 gd-devel-2.0.35-11.el6.x86_64.rpm nginx-1.10.1 php-5.6.35.tar.bz2 libmcrypt-2.5.8-9.el6.x86_64.rpm nginx-1.10.1.tar.gz re2c-0.13.5-1.el6.x86_64.rpm libmcrypt-devel-2.5.8-9.el6.x86_64.rpm nginx-sticky-module-ng [root@server1 ~]# yum install -y unzip ##下載zip壓縮包的解壓工具 [root@server1 ~]# unzip Discuz_X3.2_SC_UTF8.zip -d /usr/local/lnmp/nginx/html/ [root@server1 ~]# ls /usr/local/lnmp/nginx/html/ 50x.html index.html index.php readme upload utility [root@server1 ~]# mv /usr/local/lnmp/nginx/html/upload/ /usr/local/lnmp/nginx/html/bbs ##更改一下目錄的名稱 [root@server1 ~]# ls /usr/local/lnmp/nginx/html/ 50x.html bbs index.html index.php readme utility [root@server1 ~]#


[root@server1 ~]# cd /usr/local/lnmp/nginx/html/bbs/ [root@server1 bbs]# chmod 777 config/ data/ uc_client/ uc_server/ -R [root@server1 bbs]#


##開(kāi)啟數(shù)據(jù)庫(kù) [root@server1 bbs]# mysql -p Enter password: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/usr/local/lnmp/mysql/data/mysql.sock' (111) [root@server1 bbs]# /etc/init.d/mysqld statusERROR! MySQL is not running, but PID file exists [root@server1 bbs]# /etc/init.d/mysqld start Starting MySQL SUCCESS! [root@server1 bbs]# mysql -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.11 Source distributionCopyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> quit Bye [root@server1 bbs]#


root@server1 bbs]# vim /usr/local/lnmp/php/etc/php.ini 1013 pdo_mysql.default_socket=/usr/local/lnmp/mysql/data/mysql.sock 1162 mysql.default_socket = /usr/local/lnmp/mysql/data/mysql.sock 1221 mysqli.default_socket = /usr/local/lnmp/mysql/data/mysql.sock [root@server1 bbs]# /etc/init.d/php-fpm reload Reload service php-fpm done [root@server1 bbs]#

[root@server1 bbs]# cd [root@server1 ~]# ll -d /usr/local/lnmp/mysql/data/ drwxr-x--- 5 mysql root 4096 Aug 5 15:26 data [root@server1 ~]# chmod 755 /usr/local/lnmp/mysql/data/ [root@server1 ~]# ll -d /usr/local/lnmp/mysql/data/ drwxr-xr-x 5 mysql root 4096 Aug 5 15:26 data [root@server1 ~]#





[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]#


[root@foundation54 lamp]# ab -c 10 -n 1000 http://172.25.54.9/index.php ##其他略掉 Requests per second: 428.55 [#/sec] (mean) [root@foundation54 lamp]# ab -c 10 -n 1000 http://172.25.54.9/example.php Requests per second: 1001.07 [#/sec] (mean) [root@foundation54 lamp]#

總結(jié)

以上是生活随笔為你收集整理的LNMP架构环境搭建之PHP、Nginx源码编译安装及其简单配置应用的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。