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.gz
tar -zxvf pcre2-10.20.tar.gz
mv ./pcre2-10.20.tar.gz ./pcre
cd pcre
./configure --prefix=/usr/local/pcre
make && make install

下载zlib源代码并安装

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

下载nginx源代码并安装

wget http://nginx.org/download/nginx-1.8.1.tar.gz
tar -zxvf nginx-1.8.1.tar.gz
cd nginx-1.8.1
./configure --prefix=/usr/local/nginx --with-pcre=/usr/local/pcre --with-zlib=/usr/local/zlib
make && 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 nginx
set -e
PATH=$PATH:/usr/local/nginx/sbin/
DESC="nginx daemon"
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
CONFIGFILE=/usr/local/nginx/conf/nginx.conf
PIDFILE=/var/run/nginx.pid
SCRIPTNAME=/etc/init.d/$NAME
# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0
d_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" in
start)
echo -n "Starting $DESC: $NAME"
d_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
d_stop
echo "."
;;
reload)
echo -n "Reloading $DESC configuration..."
d_reload
echo "reloaded."
;;
restart)
echo -n "Restarting $DESC: $NAME"
d_stop
sleep 1
d_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
exit 3
;;
esac
exit 0
chmod +x /etc/init.d/nginx
chkconfig --add nginx
chkconfig --level 2345 nginx on
service nginx start

源码编译安装php5.6

下载php源代码

cd /usr/local/src
wget http://cn2.php.net/get/php-5.6.24.tar.gz/from/this/mirror
mv mirror php-5.6.24.tar.gz
tar -zxvf php-5.6.24.tar.gz
cd 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 openssl
apt-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环境配置有所帮助。

(0)

相关推荐

  • Ubuntu+Nginx+Mysql+Php+Zend+eaccelerator安装配置文字版

    把我架设lnmp网站的过程写出来,希望对想架设网站的朋友有所帮助,如有更好的办法请提出来. 之所以用nginx没用apache,是因为nginx的效率更高一些,尤其是对一些低配置的服务器,比如我在单位256M内存的旧机器上架设的服务器. 1.安装ubuntu server 10.04或10.10,其中安装语言选的en,时区shanghai,服务只安装ssh,其他全部用默认就行. 提示:以上安装过程完成后,建议用其他计算机登录服务器,windows系统可以用putty,linux系统直接在终端用命

  • 基于Xen的VPS ubuntu+nginx+php安装教程

    因为对系统性能要求很低,所以选择了Link-1,2.5G硬盘.64M内存.100GB流量.1个独立ip.使用优惠码9DMM7R可以有10%的折扣,vpslink.com.当然也可以找更大折扣的优惠码,但是一般只限3个月内.在vpslink后台安装os,选择ubuntu9.04,一分钟后系统装完了,ssh登录root.工作1:配置web服务器为了调试程序,支持php的web服务器还是需要的.内存太小所以抛弃了一直以来的apache,改用nginx,并且通过fast-cgi来支持php.vpslin

  • 基于ubuntu下nginx+php+mysql安装配置的具体操作步骤

    1.更新 1 sudo apt-get update 2.安装nginx 1 sudo apt-get intsall nginx Ubuntu安装之后的文件结构大致为:* 所有的配置文件都在/etc/nginx下,并且每个虚拟主机已经安排在了/etc/nginx/sites-available下*程序文件在/usr/sbin/nginx * 日志放在了/var/log/nginx中*并已经在/etc/init.d/下创建了启动脚本nginx* 默认的虚拟主机的目录设置在了/var/www/ng

  • Ubuntu12下编译安装PHP5.3开发环境

    最近项目遇到一个坑爹的事情,一个源码必须使用PHP5.3,但是现在Ubuntu上自带的版本是5.4,降级之后会出各种奇怪的问题,最后没办法,只能一步步在Ubuntu12.04server上自己编译PHP5.3,比繁琐,共享之. 安装Apache2.2 复制代码 代码如下: sudo apt-get install apache2 -y 然后安装MySQL5.5 复制代码 代码如下: sudo apt-get install mysql-server-5.5 -y 接着就是编译依赖环境: 复制代码

  • 在 Ubuntu 16.04 为 Nginx 服务器安装 LEMP 环境(MariaDB,PHP 7 并支持 HTTP 2.0)

    LEMP 是个缩写,代表一组软件包(L:Linux OS,E:Nginx 网络服务器,M:MySQL/MariaDB 数据库和 P:PHP 服务端动态编程语言),它被用来搭建动态的网络应用和网页. (LCTT 译注:为何采用 LEMP 而不是 LNMP 的缩写?据 https://lemp.io/ 的解释:Nginx 的发音是 Engine-X,重要的发音而不是首字母,而且 LEMP 实际上是可读的,而 LNMP 看起来只是字母表.) 这篇教程会教你怎么在 Ubuntu 16.04 的服务器上安

  • Ubuntu下nginx编译安装参数配置

    安装依赖库: sudo apt-get install libgd2-xpm sudo apt-get install libgd2-xpm-dev sudo apt-get install libgeoip-dev sudo apt-get install libpcre3 sudo apt-get install libpcre3-dev sudo apt-get install libssl-dev sudo apt-get install openssl sudo apt-get ins

  • ubuntu下编译安装xcache for php5.3 的具体操作步骤

    wget http://xcache.lighttpd.net/pub/Releases/1.3.0/xcache-1.3.0.tar.gzsudo tar -xzvf  xcache-1.3.0.tar.gz cd  xcache-1.3.0 sudo /usr/local/php-5.3.3/bin/phpize sudo ./configure --with-php-config=/usr/local/php-5.3.3/bin/php-config sudo makesudo make

  • ubuntu14.04LTS安装nginx+mariaDB+php7+YAF的方法

    本文讲述了ubuntu14.04LTS安装nginx+mariaDB+php7+YAF的方法.分享给大家供大家参考,具体如下: ubuntu apt-get方式安装nginx 参考: http://nginx.org/en/linux_packages.html 首先 in order to authenticate the nginx repository signature and to eliminate warnings about missing PGP key during inst

  • Ubuntu安装PHP和PHP Nginx配置方法

    最近接手了一个 PHP 项目,之前没做过 PHP,于是从搭建PHP环境开始学习下,同时写篇 Ubuntu 安装 PHP 的教程. 一.删除遗留的PHP包 sudo apt-get purge `dpkg -l | grep php| awk '{print $2}' |tr "\n" " "` sudo apt autoremove 二.添加PPA sudo apt-get install -y language-pack-en-base sudo LC_ALL=e

  • Ubuntu 16.04源码编译安装PHP 5.6.29的教程

    1. 下载地址:http://www.php.net/downloads.php 2.解压 tar -zxvf PHP-5.6.29.tar.gz 3.配置 ./configure –prefix=/usr/local/php –with-apxs2=/usr/local/apache/bin/apxs 注意:这里的-with-apxs2=/usr/local/apache/bin/apxs选项,其中apxs是在安装Apache时产生的,路径根据实际情况设置.apxs是一个为Apache HTT

  • ubuntu 编译安装php 5.3.3+memcache的方法

    //编译安装php 5.3.3 由于php5.3.X已经自带了php-fpm所以不需要打补丁 # sudo ./configure --prefix=/usr/local/php-5.3.3 --with-mcrypt --with-gettext --with-mysql --with-gd --with-jpeg-dir --with-png-dir --with-curl --with-freetype-dir --enable-gd-native-ttf --enable-mbstrin

随机推荐