前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >手动编译安装php、nginx

手动编译安装php、nginx

作者头像
lukachen
发布2023-10-22 15:27:27
2970
发布2023-10-22 15:27:27
举报
文章被收录于专栏:LukaChen BlogLukaChen Blog

以往都是使用 lnmp 一键安装包,进行开发环境的搭建,这两天自己手动编译安装php、nginx使其能成功打印出 

代码语言:javascript
复制
hello world 

Let's go:

nginx 安装 (FYI)

1. vi /etc/yum.rep [nginx]name=nginx repobaseurl=http://nginx.org/packages/centos/releasever/basearch/gpgcheck=0enabled=1 3. yum -y install nginx

php 安装 (FYI官方安装)

0. yum install libpng-devel libjpeg-devel libcurl-devel freetype-devel libxml2-devel -y 1. 错误:configure: error: mcrypt.h not found. Please reinstall libmcrypt. 解决方法: wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz tar zxf libmcrypt-2.5.7.tar.gz cd libmcrypt-2.5.7 ./configure make && make install 2. 错误:checking for known struct flock definition... configure: error: Don't know how to define struct flock on this system, set --enable-opcache=no 解决办法: vim /etc/ld.so.conf.d/local.conf /usr/local/lib   :wq ldconfig -v 3. wget http://cn2.php.net/distributions/php-5.6.23.tar.bz2 4. tar -jxvf php-5.6.23.tar.bz2 5../configure  --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-fpm-user=www --with-fpm-group=www --enable-fpm --enable-opcache --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --disable-fileinfo --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-exif --enable-sysvsem --with-curl --enable-mbregex --enable-inline-optimization --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-ftp --with-gettext --enable-zip --enable-soap --disable-ipv6 --disable-debug 6.make && make install

编写Nginx和PHP-FPM的启动、重启、停止脚本 (FYI)

根据FYI步骤一步一步配就行了,注意其中需要在 php-fpm.conf 中开启 xxx.pid 配置

server 相关配置

代码语言:javascript
复制
server {
    listen       80;
    server_name  localhost;

    #charset utf-8;
    #access_log  /var/log/nginx/log/host.access.log  main;

    root   /vagrant/test;
    index  index.php;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }
    location ~ \.php$ {
        fastcgi_index  index.php;
        fastcgi_pass   127.0.0.1:9000;
        include        fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        #fastcgi_param  SCRIPT_NAME      $fastcgi_script_name;
    }
}

总结:

  • 通过自己编译配置开发环境,可以进一步理解 php 及其相关如 php-fpm、nginx 的工作流程
  • 强化 Linux 的使用,如 useradd、groupadd、sudo netstat -anp、ps -ef、groups [user]、tar 等等
  • 配置期间遇到一个 No input file specified. 的问题,经 google、baidu 后,主要是 server 配置的问题,需要把 root 和 index 那两行从 location / 中拿到外部出来就行正常使用,关于这个原因是为什么,我现在还是不太理解,我请求的是 127.0.0.1:80 理应能匹配到 location / ,为何会有问题呢?希望知情同学给予解答。

附录:

如何在编译好的PHP环境中安装PHP扩展模块

1、先进入php解压缩后的源码包中,找到要安装的扩展模块的目录。 [root@redhat5 sockets]# cd /home/soft/php-5.2.12/ext/sockets 在sockets目录下面以绝对路径运行phpize程序,这时会自动生成sockets的configure程序,在sockets目录下面可以看到。 [root@redhat5 sockets]# /home/webserver/php5.2.12/bin/phpize 2、进行编译安装 [root@redhat5 sockets]# ./configure --with-php-config=/home/webserver/php5.2.12/bin/php-config [root@redhat5 sockets]#make [root@redhat5 sockets]#make install 执行完make install屏幕上会提示sockets.so存放的路径,然后把它复制到php的extensions目录中,例如我的路径为 /home/webserver/php5.2.12/lib/php/extensions 3、修改php.ini文件 找到extension_dir = "./"  这行,修改为: extension_dir = "/home/webserver/php5.2.12/lib/php/extensions/" 然后再新增加一行: extension=sockets.so 4、重启web服务器(apache/nginx)即可生效。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2016-06-25,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Let's go:
    • nginx 安装 (FYI)
      • php 安装 (FYI官方安装)
        • 编写Nginx和PHP-FPM的启动、重启、停止脚本 (FYI)
          • server 相关配置
          领券
          问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档