php源码编译

本文将详细探讨PHP的源码编译步骤,从下载源码到配置选项,再到编译和安装,逐一解析关键过程。通过理解这一过程,开发者可以更好地定制PHP环境,了解PHP内部工作原理。
摘要由CSDN通过智能技术生成
[root@server1 ~]# vim /usr/local/lnmp/nginx/conf/nginx.conf
[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 -s reload



 54 
 55         location ~.*\.(gif|jpg|png)$ {
 56                 expires 365d;
 57 }






[root@foundation4 ~]# curl -I 172.25.4.1/download/123.png
HTTP/1.1 200 OK
Server: nginx/1.18.0
Date: Wed, 12 Aug 2020 02:03:11 GMT
Content-Type: image/png
Content-Length: 24016
Last-Modified: Tue, 11 Aug 2020 09:51:58 GMT
Connection: keep-alive
ETag: "5f326a3e-5dd0"
Expires: Thu, 12 Aug 2021 02:03:11 GMT         #缓存一年
Cache-Control: max-age=31536000
Accept-Ranges: bytes



 55         location ~.*\.(gif|jpg|png)$ {
 56                 expires 365d;
 57                 access_log off;
 58 }
 59 
 60         location /download/ {
 61 #               limit_conn      addr 1;
 62                 #limit_rate     50k;
 63 }




[root@server1 ~]# cat /usr/local/lnmp/nginx/logs/access.log    #成功日志不再更新

172.25.4.250 - - [12/Aug/2020:10:02:29 +0800] "HEAD /download/123.jpg HTTP/1.1" 404 0 "-" "curl/7.61.1"
172.25.4.250 - - [12/Aug/2020:10:03:11 +0800] "HEAD /download/123.png HTTP/1.1" 200 0 "-" "curl/7.61.1"




[root@server1 ~]# cd /usr/local/lnmp/nginx/html/download/
[root@server1 download]# vim script.sh
[root@server1 download]# cat script.sh 
#!/bin/bash
echo "hello world!"
[root@server1 download]# chmod +x script.sh 




 60         location ~^/download/.*\.(sh|php)$ {
 61         deny all;
 62         }


[root@server1 download]# vim /usr/local/lnmp/nginx/conf/nginx.conf
[root@server1 download]# 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 download]# nginx -s reload


网页测试




 69         location /status {
 70             stub_status;
 71             access_log off;
 72             error_log /dev/null;
 73             allow 172.25.4.250;
 74             deny all;
 75         }


[root@server1 download]# vim /usr/local/lnmp/nginx/conf/nginx.conf
[root@server1 download]# 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 download]# nginx -s reload


网页测试:
172.25.4.1/status



[root@server1 download]# curl 172.25.4.1/status
<html>
<head><title>403 Forbidden</title></head>
<body>
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx/1.18.0</center>
</body>
</html>





 69         location /status {
 70             stub_status;
 71             access_log off;
 72             error_log /dev/null;
 73             allow 172.25.4.0/24;
 74             deny all;
 75         }
 76 


[root@server1 download]# vim /usr/local/lnmp/nginx/conf/nginx.conf
[root@server1 download]# 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 download]# nginx -s reload


[root@server1 download]# curl 172.25.4.1/status
Active connections: 1 
server accepts handled requests
 11 11 43 
Reading: 0 Writing: 1 Waiting: 0 




 64         location /download/ {
 65                 autoindex on;
 66 #               limit_conn      addr 1;
 67                 #limit_rate     50k;
 68 }


[root@server1 download]# vim /usr/local/lnmp/nginx/conf/nginx.conf
[root@server1 download]# 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 download]# nginx -s reload




 49         location / {
 50         root html;
 51         index index.html index.htm;
 52 #       limit_req zone=one;
 53         if ($remote_addr = 172.25.4.250) {
 54                 return 403;
 55 }




 49         location / {
 50         root html;
 51         index index.html index.htm;
 52 #       limit_req zone=one;
 53 #       if ($remote_addr = 172.25.4.250) {
 54 #               return 403;
 55 #}




nginx重定向
防止域名恶意解析到服务器ip


 41     server {
 42         listen       80;
 43         server_name _;
 44         return 500;

网页测试:
172.25.4.1
显示500


[root@server1 nginx]# vim conf/nginx.conf
[root@server1 nginx]# 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]# nginx -s reload


 15 events {
 16     use epoll;
 17     multi_accept on;
 18     worker_connections  65535;
 19 }

[root@server1 nginx]# vim conf/nginx.conf
[root@server1 nginx]# 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]# nginx -s reload


[root@server1 nginx]# curl -I localhost
HTTP/1.1 500 Internal Server Error
Server: nginx/1.18.0
Date: Wed, 12 Aug 2020 03:35:12 GMT
Content-Type: text/html
Content-Length: 177
Connection: close





nginx重定向
80重定向443
[root@server1 nginx]# vim conf/nginx.conf



120     server {
121         listen       80;
122     #    listen       somename:8080;
123     #    server_name  somename  alias  another.alias;
124         server_name www.westos.org;
125         rewrite ^(.*) https://www.westos.org permanent;
126 
127        # location / {
128        #     root   html;
129        #     index  index.html index.htm;
130        # }
131     }
132 
133 
134     #HTTPS server
135 
136     server {
137         listen       443 ssl;
138         server_name  www.westos.org;



[root@server1 nginx]# 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]# nginx -s reload

[root@foundation4 ~]# vim /etc/hosts


172.25.4.1      www.westos.org bbs.westos.org


网页测试:
www.westos.org
重定向 https://www.westos.org/



[root@foundation4 ~]# curl -I www.westos.org
HTTP/1.1 301 Moved Permanently
Server: nginx/1.18.0
Date: Wed, 12 Aug 2020 04:49:51 GMT
Content-Type: text/html
Content-Length: 169
Connection: keep-alive
Location: https://www.westos.org




[root@server1 nginx]# vim conf/nginx.conf
[root@server1 nginx]# cd html/
[root@server1 html]# ls
50x.html  download  index.html
[root@server1 html]# vim test.html

<html>
<body>
<br>盗链图片</br>
<img src="http://www.westos.org/123.png">
</body>
</html>


[root@server1 html]# cp download/123.png .
网页测试:

https://www.westos.org/123.png








www.westos.org/bbs 重定向 bbs.westos.org


可以多注册几个域名,用户访问的时候引到一个主站上
 43     server {
 44         listen       80;
 45         #server_name _;
 46         #return 500;




149         #location / {
150         #    root   html;
151         #    index  index.html index.htm;
152         #}
153     }
154 
155         server {
156         listen 80;
157         server_name bbs.westos.org;
158 
159         location / {
160             root   /bbs;
161             index  index.html;
162         }
163         }
164 
165 }
                                          


[root@server1 nginx]# mkdir /bbs
[root@server1 nginx]# cd /bbs/
[root@server1 bbs]# echo bbs > index.html


[root@foundation4 ~]# curl bbs.westos.org
bbs


[root@server1 bbs]# vim /usr/local/lnmp/nginx/conf/nginx.conf

120     server {
121         listen       80;
122     #    listen       somename:8080;
123     #    server_name  somename  alias  another.alias;
124         server_name www.westos.org;
125 #       rewrite ^(.*) https://www.westos.org permanent;
126         rewrite ^/bbs$ http://bbs.westos.org permanent;





152         #location / {
153         #    root   html;
154         #    index  index.html index.htm;
155         #}
156     }
157 
158         #server {
159         #listen 80;
160         #server_name bbs.westos.org;
161 
162         #location / {
163         #    root   /bbs;
164         #    index  index.html;
165         #}
166         #}




[root@server1 bbs]# 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 bbs]# nginx -s reload





[root@foundation4 ~]# curl -I www.westos.org/bbs
HTTP/1.1 301 Moved Permanently
Server: nginx/1.18.0
Date: Wed, 12 Aug 2020 05:40:14 GMT
Content-Type: text/html
Content-Length: 169
Connection: keep-alive
Location: http://bbs.westos.org

[root@foundation4 ~]# curl -I www.westos.org/bbs/index.html
HTTP/1.1 404 Not Found
Server: nginx/1.18.0
Date: Wed, 12 Aug 2020 05:40:24 GMT
Content-Type: text/html
Content-Length: 153
Connection: keep-alive



125 #       rewrite ^(.*) https://www.westos.org permanent;
126         rewrite ^/bbs$ http://bbs.westos.org permanent;
127         rewrite ^/bbs/(.*)$ http://bbs.westos.org/$1 permanent;


[root@server1 bbs]# 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 bbs]# nginx -s reload



[root@foundation4 ~]# curl -I www.westos.org/bbs
HTTP/1.1 301 Moved Permanently
Server: nginx/1.18.0
Date: Wed, 12 Aug 2020 05:44:30 GMT
Content-Type: text/html
Content-Length: 169
Connection: keep-alive
Location: http://bbs.westos.org

[root@foundation4 ~]# curl -I www.westos.org/bbs/index.html
HTTP/1.1 301 Moved Permanently
Server: nginx/1.18.0
Date: Wed, 12 Aug 2020 05:44:35 GMT
Content-Type: text/html
Content-Length: 169
Connection: keep-alive
Location: http://bbs.westos.org/index.html












动态语言需要解析



==================================================

[root@server1 ~]# ls
nginx-1.18.0  nginx-1.18.0.tar.gz  nginx-1.19.1  nginx-1.19.1.tar.gz  php-7.4.6.tar.bz2
[root@server1 ~]# yum install bzip2 -y


[root@server1 ~]# tar jxf php-7.4.6.tar.bz2 
[root@server1 ~]# ls
nginx-1.18.0         nginx-1.19.1         php-7.4.6
nginx-1.18.0.tar.gz  nginx-1.19.1.tar.gz  php-7.4.6.tar.bz2
[root@server1 ~]# cd php-7.4.6
[root@server1 php-7.4.6]# ls
appveyor             configure.ac     pear                 tests
azure                CONTRIBUTING.md  php.ini-development  travis
azure-pipelines.yml  docs             php.ini-production   TSRM
build                ext              README.md            UPGRADING
buildconf            EXTENSIONS       README.REDIST.BINS   UPGRADING.INTERNALS
buildconf.bat        LICENSE          run-tests.php        win32
CODING_STANDARDS.md  main             sapi                 Zend
configure            NEWS             scripts




[root@server1 php-7.4.6]# ./configure --prefix=/usr/local/php --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx  --with-curl --with-iconv --with-mhash --with-zlib --with-openssl --enable-mysqlnd --with-mysqli --with-pdo-mysql --disable-debug --enable-sockets --enable-soap --enable-inline-optimization --enable-xml --enable-ftp --enable-gd --enable-exif --enable-mbstring  --enable-bcmath --with-fpm-system


No package 'libxml-2.0' found

[root@server1 php-7.4.6]# yum install libxml2-devel -y


No package 'sqlite3' found


[root@server1 php-7.4.6]# yum install sqlite-devel -y


No package 'libcurl' found
[root@server1 php-7.4.6]# yum install -y libcurl-devel

No package 'libpng' found


[root@server1 php-7.4.6]# yum install -y libpng-devel


No package 'oniguruma' found

[root@server1 php-7.4.6]# cd
[root@server1 ~]# ls
nginx-1.18.0         nginx-1.19.1.tar.gz                     php-7.4.6
nginx-1.18.0.tar.gz  oniguruma-6.8.2-1.el7.x86_64.rpm        php-7.4.6.tar.bz2
nginx-1.19.1         oniguruma-devel-6.8.2-1.el7.x86_64.rpm
[root@server1 ~]# yum install -y oniguruma-6.8.2-1.el7.x86_64.rpm oniguruma-devel-6.8.2-1.el7.x86_64.rpm





No package 'libsystemd' found

[root@server1 php-7.4.6]# yum install -y systemd-devel




[root@server1 php-7.4.6]# ./configure --prefix=/usr/local/lnmp/php --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx  --with-curl --with-iconv --with-mhash --with-zlib --with-openssl --enable-mysqlnd --with-mysqli --with-pdo-mysql --disable-debug --enable-sockets --enable-soap --enable-inline-optimization --enable-xml --enable-ftp --enable-gd --enable-exif --enable-mbstring  --enable-bcmath --with-fpm-systemd



+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE. By continuing this installation  |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+

Thank you for using PHP.

[root@server1 ~]# cd php-7.4.6
[root@server1 php-7.4.6]# ls
appveyor             config.log       ext         Makefile             php.ini-production  travis
azure                config.nice      EXTENSIONS  Makefile.fragments   README.md           TSRM
azure-pipelines.yml  config.status    include     Makefile.objects     README.REDIST.BINS  UPGRADING
build                configure        libs        modules              run-tests.php       UPGRADING.INTERNALS
buildconf            configure.ac     libtool     NEWS                 sapi                win32
buildconf.bat        CONTRIBUTING.md  LICENSE     pear                 scripts             Zend
CODING_STANDARDS.md  docs             main        php.ini-development  tests


[root@server1 ~]# cd php-7.4.6
[root@server1 php-7.4.6]# cp php.ini-production /usr/local/php/lib/php.ini
[root@server1 php-7.4.6]# cd sapi/fpm/
[root@server1 fpm]# cd /usr/local/php/etc/
[root@server1 etc]# cp php-fpm.conf.default php-fpm.conf
[root@server1 etc]# cd php-fpm.d/
[root@server1 php-fpm.d]# ls
www.conf.default
[root@server1 php-fpm.d]# cp www.conf.default www.conf
[root@server1 php-fpm.d]# ls
www.conf  www.conf.default
[root@server1 php-fpm.d]# cd /usr/local/php
[root@server1 php]# ls
bin  etc  include  lib  php  sbin  var
[root@server1 php]# cd sbin
[root@server1 sbin]# cd
[root@server1 ~]# vim .bash_profile


PATH=$PATH:$HOME/bin:/usr/local/php/bin


[root@server1 ~]# source .bash_profile
[root@server1 ~]# /etc/init.d/php-fpm start        # 开启php服务
Starting php-fpm  done
[root@server1 ~]# ps ax |grep php
31069 ?        Ss     0:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
31070 ?        S      0:00 php-fpm: pool www
31071 ?        S      0:00 php-fpm: pool www
31073 pts/0    R+     0:00 grep --color=auto php








[root@server1 php-fpm.d]# vim /usr/local/lnmp/nginx/conf/nginx.conf

 52         location / {
 53         root html;
 54         index index.html index.htm;
 55 #       limit_req zone=one;
 56 #       if ($remote_addr = 172.25.4.250) {
 57 #               return 403;
 58 #               }
 59         }
 60 
 61 
 62         location ~ \.php$ {
 63             root           html;
 64             fastcgi_pass   127.0.0.1:9000;
 65             fastcgi_index  index.php;
 66             #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
 67             include        fastcgi.conf;
 68         }
 69 


[root@server1 html]# 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 html]# nginx -s reload


[root@server1 php-fpm.d]# vim /usr/local/lnmp/nginx/conf/nginx.conf
[root@server1 php-fpm.d]# 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 php-fpm.d]# nginx 
[root@server1 php-fpm.d]# nginx -s reload
[root@server1 php-fpm.d]# cd /usr/local/lnmp/nginx/html/
[root@server1 html]# vim index.php

<?php
phpinfo()
?>



网页测试:

http://172.25.4.1/index.php


=======================================================


[root@server1 ~]# ls
memcache-4.0.5.2.tgz  nginx-1.19.1                      oniguruma-devel-6.8.2-1.el7.x86_64.rpm
nginx-1.18.0          nginx-1.19.1.tar.gz               php-7.4.6
nginx-1.18.0.tar.gz   oniguruma-6.8.2-1.el7.x86_64.rpm  php-7.4.6.tar.bz2
[root@server1 ~]# tar zxf memcache-4.0.5.2.tgz 
[root@server1 ~]# cd memcache-4.0.5.2
[root@server1 memcache-4.0.5.2]# phpize 
Configuring for:
PHP Api Version:         20190902
Zend Module Api No:      20190902
Zend Extension Api No:   320190902
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.

[root@server1 memcache-4.0.5.2]# yum install -y autoconf




[root@server1 memcache-4.0.5.2]# /usr/local/php/bin/phpize 
Configuring for:
PHP Api Version:         20190902
Zend Module Api No:      20190902
Zend Extension Api No:   320190902

[root@server1 memcache-4.0.5.2]# ./configure 
[root@server1 memcache-4.0.5.2]# make && make install













[root@server1 memcache-4.0.5.2]# cd /usr/local/php/lib/php/extensions/no-debug-non-zts-20190902/
[root@server1 no-debug-non-zts-20190902]# ls
memcache.so  opcache.a  opcache.so
[root@server1 php-7.4.6]# cd /usr/local/php/lib/
[root@server1 lib]# ls
php  php.ini



[root@server1 lib]# vim php.ini 


 913 extension=memcache.so


[root@server1 lib]# /etc/init.d/php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm  done



[root@server1 lib]# php -m |grep memcache
memcache
[root@server1 lib]# cd
[root@server1 ~]# cd memcache-4.0.5.2/
[root@server1 memcache-4.0.5.2]# ls
autom4te.cache   config.h     config.nice    config.w32  example.php  Makefile            memcache.php  run-tests.php
build            config.h.in  config.status  CREDITS     include      Makefile.fragments  modules       tests
cloudbuild.yaml  config.log   configure      docker      libtool      Makefile.objects    php7
config9.m4       config.m4    configure.ac   Dockerfile  LICENSE      memcache.la         README

[root@server1 memcache-4.0.5.2]# yum install -y memcached telnet
[root@server1 memcache-4.0.5.2]# systemctl start memcached
[root@server1 memcache-4.0.5.2]# systemctl status memcached
● memcached.service - Memcached
   Loaded: loaded (/usr/lib/systemd/system/memcached.service; disabled; vendor preset: disabled)
   Active: active (running) since Thu 2020-08-13 10:40:15 CST; 5s ago
 Main PID: 5967 (memcached)
   CGroup: /system.slice/memcached.service
           └─5967 /usr/bin/memcached -u memcached -p 11211 -m 64 -c 1024

Aug 13 10:40:15 server1 systemd[1]: Started Memcached.
[root@server1 memcache-4.0.5.2]# telnet 127.0.0.1 11211
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.


[root@server1 memcache-4.0.5.2]# cp example.php  memcache.php /usr/local/lnmp/nginx/html/
[root@server1 memcache-4.0.5.2]# cd /usr/local/lnmp/nginx/html/
[root@server1 html]# ls
123.png   download     index.html  memcache.php
50x.html  example.php  index.php   test.html
[root@server1 html]# vim memcache.php 


 28 $MEMCACHE_SERVERS[] = '172.0.0.1:11211'; // add more as an array
 29 #$MEMCACHE_SERVERS[] = 'mymemcache-server2:11211'; // add more as an array


[root@server1 html]# netstat -antlp | grep :11211
tcp        0      0 0.0.0.0:11211           0.0.0.0:*               LISTEN      5967/memcached      
tcp6       0      0 :::11211                :::*                    LISTEN      5967/memcached      
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值