ubuntu 编译安装php mysql_ubuntu15.04编译安装php apache mysql nginx

ubuntu15.04编译安装php apache mysql nginx

一、源码安装LAMP

网上有一堆关于介绍lamp的在这里我就不罗嗦了,直接上配置过程

1.apr包的安装

apr简介:

The mission of the Apache Portable Runtime (APR) project is to create and maintain software libraries that provide a predictable and consistent interface to underlying platform-specific implementations.

The primary goal is to provide an API to which software developers may code and be assured of predictable if not identical behaviour regardless of the platform on which their software is built, relieving them of the need to code special-case conditions to work around or take advantage of platform-specific deficiencies or features.

下载地址:

wget http://labs.mop.com/apache-mirror//apr/apr-1.4.6.tar.gz

wget http://labs.mop.com/apache-mirror//apr/apr-util-1.4.1.tar.gz

tar xvf apr-1.4.6.tar.gz

tar xvf apr-util-1.4.1.tar.gz

cd apr-1.4.6

./configure

make

make install

在编译时有可能会出现以下问题

cannot remove `libtoolT': No such file or directory

解决方法:

vim configure

把RM='$RM'改为RM='$RM  -f',在configure里面 RM='$RM  -f'   这里的$RM后面一定有一个空格。 如果后面没有空格,直接连接减号,就依然会报错。

cd apr-util-1.4.1

./configure –with-apr=/usr/local/apr

make

make install

如果使用的是apt-get 安装apr

apt-get install libaprutil1-dev libapr1-dev

在编译安装apache是会报错:

rotatelogs.c:(.text+0x603): undefined reference to `apr_file_link'

collect2: ld returned 1 exit status

make[2]: *** [rotatelogs] Error 1

make[2]: Leaving directory `/root/lamp/httpd-2.4.2/support'

make[1]: *** [install-recursive] Error 1

make[1]: Leaving directory `/root/lamp/httpd-2.4.2/support'

make: *** [install-recursive] Error 1

原因是apr的版本太低,解决办法:源码安装apr较新包

2.apache包的安装

下载地址:

wget http://mirror.bjtu.edu.cn/apache//httpd/httpd-2.4.3.tar.bz2

tar xvf httpd-2.4.3.tar.bz2

cd httpd-2.4.3

./configure –prefix=/usr/local/apache2 –enable-modules=shared –enable-so –enable-deflate –enable-expires –enable-headers –enable-rewrite –with-included-apr=/usr/local/apr –with-included-apr-util

make

make install

编译过程中可能遇到

checking for pcre-config… false

configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/

解决方法:apt-get install libpcre3-dev

checking for zlib location… not found

checking whether to enable mod_deflate… configure: error: mod_deflate has been requested but can not be built due to prerequisite failures

解决方法:apt-get install zlib1g-dev

启动、重启和停止

/usr/local/apache2/bin/apachectl -k start

/usr/local/apache2/bin/apachectl -k restart

/usr/local/apache2/bin/apachectl -k stop

每次启动都输入那么长的命令是不是很烦,解决方法:

a.软连接的PATH路径,

echo $PATH

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

ln -sv /usr/local/apache2/bin/* /usr/sbin  (或者/usr/bin、/usr/local/bin等)

然后就可以直接在终端用:

apachectl -k start

apachectl -k restart

apachectl -k stop

b.把/usr/local/apache2/bin/加入PATH路径

vim /etc/profile

#增加

PATH="$PATH:/usr/local/apache2/bin"

source /etc/profile

apache配置文件的修改:

vim /usr/local/apache2/conf/httpd.conf

找到:

AddType application/x-compress .Z

AddType application/x-gzip .gz .tgz

在后面添加:#p#分页标题#e#

AddType application/x-httpd-php .php

AddType application/x-httpd-php-source .phps

找到:

DirectoryIndex index.html

添加:

DirectoryIndex index.html index.php

找到:

#ServerName www.example.com:80

修改为:

ServerName yourhostip:80

重启apache:  apachectl -k restart

通过浏览器访问:http://yourhostip

应该显示:It works!

3.mysql的安装

请参考:

http://linuxme.blog.51cto.com/1850814/383742

初始化mysql数据库时可能会遇到:

./bin/mysqld: error while loading shared libraries: libstdc++.so.5: cannot open shared object file: No such file or directory

解决方法:apt-get install libstdc++5

4.php的安装

下载地址:

wget http://cn.php.net/get/php-5.4.6.tar.bz2/from/this/mirror

tar xvf php-5.4.6.tar.bz2

cd php-5.4.6

./configure –prefix=/usr/local/php –with-apxs2=/usr/local/apache2/bin/apxs –with-curl –with-mcrypt –enable-mbstring –enable-pdo –with-pdo-mysql=mysqlnd –with-mysqli=mysqlnd –with-openssl –with-imap-ssl –with-gd –with-jpeg-dir=/usr/lib/ –with-png-dir=/usr/lib/ –enable-exif –enable-zip –enable-dba=shared –with-mysql=/usr/local/mysql

这一步可能会遇到:

/usr/bin/ld: cannot find -liconv

collect2: ld returned 1 exit status

make: *** [sapi/cli/php] Error 1

解决办法:

apt-get install libglobus-libtool-dev

checking libxml2 install dir… no

checking for xml2-config path…

configure: error: xml2-config not found. Please check your libxml2 installation.

解决办法:apt-get install libxml2-dev

configure: error: Cannot find OpenSSL's

解决方法:apt-get install libssl-dev

checking if we should use cURL for url streams… no

checking for cURL in default path… not found

configure: error: Please reinstall the libcurl distribution –

easy.h should be in /include/curl/

解决方法:apt-get install libcurl4-openssl-dev

configure: error: jpeglib.h not found.

解决方法:apt-get install libjpeg62-dev

configure: error: png.h not found.

解决方法:apt-get install libpng-dev

configure: error: mcrypt.h not found. Please reinstall libmcrypt.

解决方法:apt-get install libmcrypt-dev

php 5.4.6 make 时在apprentice.c -o ext/fileinfo/libmagic/apprentice.lo 没反应了

在网上查了查是内存不足,这一步要编译过去至少要有1G内存,我只有300M的内存。

把该虚拟机内存调到1.2G,这一步就ok了

以上编译过程中产生的编译错误,当然如果你搭建过n边LAMP环境就可以直接以下操作,是不是省事很多

apt-get install -y curl libxml2 libxml2-dev libssl-dev sendmail libcurl4-openssl-dev libjpeg-dev libpng-dev libmcrypt-dev

不知道大家发现规律没有,一般在ubuntu下编译通过不了,根椐报错找到XXXX-dev的包安装即可。如果你人品差,apt-get 安装的包版本太低

那就需要下载更新的软件包编译安装了。

make

make test

make install

cp php.ini-production /usr/local/php/lib/php.ini

vim /etc/profile

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

source /etc/profile

验证一下php是否正确安装:

apachectl -k restart

cd /usr/local/apache2/htdocs

vim index.php

phpinfo();

?>

通过浏览器访问:http://yourhostip/index.php

如果能正确访问说明php安装ok了

测试php与mysql的链接性#p#分页标题#e#

设置mysql的权限:允许通过本机或同一网段的主机链接mysql server,同一网段(192.168.12.0)如:192.168.12.%

mysql -uroot -predhat

mysql>grant all privileges on *.* to 'root'@'yourhostip_in_network';

测试链接脚本:

vim /usr/local/apache2/htdocs/index.php

$link=mysql_connect('yourhostip','root','redhat');

if(!$link)

echo "connect mysql failing…";

else

echo "connect mysql successful…";

mysql_close();

?>

通过浏览器访问:http://yourhostip/index.php

提示:500错误,这样也看不出具体哪出错了

在终端下直接用php执行index.php

php index.php

提示:PHP Fatal error:  Call to undefined function mysql_connect()

google 了一下大部分说在php.ini中把,extension=msql.so 的注释去掉,改了之后还是不行而且还会有新的错误,有两种方法可以解决:

a.是在configure 时没有关联mysql导致的,在configure 后加 –with-mysql=/usr/local/mysql,重新编译安装php就行了

b.msql.so文件不存在,生成.so文件

cd php-5.4.6/ext/mysql

安装autoconf,因为phpize命令执行生成configure文件需要

apt-get install autoconf

执行命令

phpize

在当前目录下会生成configure文件

./configure –with-php-config=/usr/local/php/bin/php-config –with-mysql=/usr/local/mysql

make

make install

在/usr/local/php/lib/php/extensions/no-debug-zts-20100525/目录下自动生成mysql.so文件

修改配置文件:vim /usr/local/php/lib/php.ini

去掉注释并修改extension=mysql.so

为什么会出现上述的问题?原因很简单你在编译时没有让php包含进mysql的一些库函数,那样在php脚本中就不能用mysql的函数去操作数据库。要么我们重新编译,要么不重新编译生成扩展文件xxx.so.

开心洋葱 , 版权所有丨如未注明 , 均为原创丨未经授权请勿修改 , 转载请注明ubuntu15.04编译安装php apache mysql nginx!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值