Ubuntu环境如何编译安装PHP和Nginx
发表于:2026-10-31 作者:千家信息网编辑
千家信息网最后更新 2026年10月31日,这篇文章将为大家详细讲解有关Ubuntu环境如何编译安装PHP和Nginx,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。本文实例讲述了Ubuntu环境编译安装PHP
千家信息网最后更新 2026年10月31日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 0chmod +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安全错误
数据库的锁怎样保障安全
互联网加科技
互联网金融 金融科技
互联网科技革命
碳银互联网科技
互联网科技排名
汇久创客互联网科技
长亮科技 互联网金融
山东吉时兔互联网科技有限公司
创业天下互联网科技有限公司
厦门比较好的科技互联网公司
晓花互联网科技有限公司网址
互联网科技扶贫时间
深圳育鹏互联网科技有限公司招聘
天津腾达互联网科技有限公司
中和天地互联网科技有限公司
沐思想互联网科技有限公司
锡山区互联网智能科技产品供应
湖北辰鑫科技互联网
易租星互联网科技有限公司
深圳互联网科技园地址
新华互联网科技学校
关于新基建和互联网科技
互联网金融 科技
广州凡科互联网科技
互联网汽车科技小镇
恒银科技与互联网金融
南通创西澳互联网科技有限公司
深圳无忧互联网科技
互联网科技大会大佬
杭州科技互联网公司有哪些