千家信息网

Ubuntu环境如何编译安装PHP和Nginx

发表于:2025-12-01 作者:千家信息网编辑
千家信息网最后更新 2025年12月01日,这篇文章将为大家详细讲解有关Ubuntu环境如何编译安装PHP和Nginx,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。本文实例讲述了Ubuntu环境编译安装PHP
千家信息网最后更新 2025年12月01日Ubuntu环境如何编译安装PHP和Nginx

这篇文章将为大家详细讲解有关Ubuntu环境如何编译安装PHP和Nginx,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

本文实例讲述了Ubuntu环境编译安装PHP和Nginx的方法。分享给大家供大家参考,具体如下:

编译安装nginx

切换目录到工作文件夹:

cd /usr/local/src

下载pcre源代码并安装

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre2-10.20.tar.gztar -zxvf pcre2-10.20.tar.gzmv ./pcre2-10.20.tar.gz ./pcre cd pcre./configure --prefix=/usr/local/pcremake && make install

下载zlib源代码并安装

wget http://tenet.dl.sourceforge.net/project/libpng/zlib/1.2.8/zlib-1.2.8.tar.gztar -zxvf zlib-1.2.8.tar.gzmv ./zlib-1.2.8.tar.gz ./zlibcd zlib./configure --prefix=/usr/local/zlibmake && make install

下载nginx源代码并安装

wget http://nginx.org/download/nginx-1.8.1.tar.gztar -zxvf nginx-1.8.1.tar.gzcd nginx-1.8.1./configure --prefix=/usr/local/nginx --with-pcre=/usr/local/pcre --with-zlib=/usr/local/zlibmake && make install

开机启动nginx

添加/ect/init.d/nginx,并写入脚本

#! /bin/bash# Description: Startup script for webserver on CentOS. cp it in /etc/init.d and# chkconfig --add nginx && chkconfig nginx on# then you can use server command control nginx## chkconfig: 2345 08 99# description: Starts, stops nginxset -ePATH=$PATH:/usr/local/nginx/sbin/DESC="nginx daemon"NAME=nginxDAEMON=/usr/local/nginx/sbin/$NAMECONFIGFILE=/usr/local/nginx/conf/nginx.confPIDFILE=/var/run/nginx.pidSCRIPTNAME=/etc/init.d/$NAME# Gracefully exit if the package has been removed.test -x $DAEMON || exit 0d_start() {$DAEMON -c $CONFIGFILE || echo -n " already running"}d_stop() {kill -QUIT `cat $PIDFILE` || echo -n " not running"}d_reload() {kill -HUP `cat $PIDFILE` || echo -n " can't reload"}case "$1" instart)echo -n "Starting $DESC: $NAME"d_startecho ".";;stop)echo -n "Stopping $DESC: $NAME"d_stopecho ".";;reload)echo -n "Reloading $DESC configuration..."d_reloadecho "reloaded.";;restart)echo -n "Restarting $DESC: $NAME"d_stopsleep 1d_startecho ".";;*)echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2exit 3;;esacexit 0
chmod +x /etc/init.d/nginxchkconfig --add nginxchkconfig --level 2345 nginx onservice nginx start

源码编译安装php5.6

下载php源代码

cd /usr/local/srcwget http://cn2.php.net/get/php-5.6.24.tar.gz/from/this/mirrormv mirror php-5.6.24.tar.gztar -zxvf php-5.6.24.tar.gzcd php-5.6.24

安装依赖的组件

xml扩展

apt-get install libxml2-dev

png扩展

apt-get install libpng12-dev

freetype扩展

apt-get -y install libfreetype6-dev

openssl扩展

apt-get install opensslapt-get install libcurl3-openssl-dev

jpeg扩展

apt-get install libjpeg-dev

编译语句

生成配置文件

./configure --prefix=/opt/php --with-config-file-path=/opt/php/lib --enable-mbstring --enable-ftp --with-gd --with-jpeg-dir=/usr --with-png-dir=/usr --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-openssl-dir=/usr --with-openssl --with-pdo-mysql=mysqlnd --with-pear --enable-sockets --with-freetype-dir=/usr --enable-gd-native-ttf --with-zlib --with-libxml-dir=/usr --with-xmlrpc --enable-zip --enable-fpm --enable-fpm --enable-xml --enable-sockets --with-gd --with-zlib --with-iconv --enable-zip --with-freetype-dir=/usr/lib/ --enable-soap --enable-pcntl --enable-cli

安装了依赖的组件以后,应该就不会报错,如果报错请安装缺少的组件,然后重新生成配置文件。

编译&安装

make && make install

查看php服务器配置

当我们迁移服务器的时候,上述生成配置文件的代码需要与原php服务器的一直,我们可以使用php-config --configure-options查看。

php-config的位置在 php/bin/php-config

没有发现php.ini?

直接编译安装php之后,是没有php.ini的,我们可以从解压缩后的目录copy到/opt/php/lib,然后进行配置生效。

/opt/php/lib是在./configure中配置的路径

关于"Ubuntu环境如何编译安装PHP和Nginx"这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

编译 配置 文件 源代码 环境 服务器 篇文章 组件 服务 生成 更多 目录 参考 不错 实用 代码 位置 内容 实例 文件夹 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 网络安全类专业主要学什么 南宁手机棋牌软件开发公司 数据库安全性的不足之处 宿迁智能化联想服务器服务商 网易我的世界古代战争服务器 喷泉模型进行软件开发的特点 服务器不支持常用的ssl协议 子弹上的数据库是什么意思 数据库和接口是什么意思 使用u盘上传文件到服务器 网络安全手抄报该写什么 苹果为什么会连接不了服务器 前端游戏软件开发 哪里的服务器在张家口 如何防范网络安全隐患问题 欧盟 5G网络安全建议 厂家网络安全期 南京神州网络技术 个税申报显示执行数据库操作失败 数据库插入数据例题 数据库细粒度访问控制 利用网络管理平台建立专业数据库 学校网络安全自己查整改报告 云服务器数据库怎么保存 对网络安全的几点认识 媒体服务器耗电量大 英语作文网络安全建议信 网络安全知识宣传周活动 软件开发必要流程 上海信英网络技术有限公司
0