php+mongodb开发环境搭建(linux+apache+mongodb+php)
一. 准备linux环境(关闭selinux,iptables,配置ip等初始化操作) 二. 准备软件: 1. apache:可以用yum来装,也可以下载源码编译。 2. mongodb:现在的linux没有集成,所以要下载。 我的环境是linux,位数64,下载http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.6.4.tgz,其他的在mongodb官网。 3. php,这里使用的是php5进行开发,所以下载源码编译。http://cn2.php.net/distributions/php-5.4.32.tar.gz 4. 因为php5要操作mongodb,且没有集成驱动,所以还得下载驱动(php扩展) http://pecl.php.net/get/mongo-1.5.5.tgz 三. 安装 就像安装lamp(linux+apache+mysql+php)一样的顺序。apache和mysql不管谁先安装都可以,但是php必须得在这两个后面。这里就采用标准的,lamp顺序。 1.安装apache:yuminstall httpd* –y 安装好后修改配置文件/etc/httpd/conf/httpd.conf ServerName 主机ip或主机名:监听端口 (格式,根据自己的实际情况配置) 2.安装mongodb: 先建立所需目录: # mkdir /data/mongodb/db –p # mkdir /data/mongodb/logs –p 然后安装mongodb:安装很简单,解压归档就可以了 # tar -xvf mongodb-linux-x86_64-1.6.4.tar.gz-C /usr/local/ 接着配置环境变量,使得使用命令的时候不需要带上路径 # cat .bash_profile# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin:/usr/local/mongodb-linux-x86_64-1.6.4/bin
export PATH 最后要source下才生效 # source .bash_profile 3.安装php5 # tar -xvf php-5.4.32.tar.gz # cd php-5.4.32 # ./configure --prefix=/usr/local/php--with-config-file-path=/etc --with-apxs2=/usr/sbin/apxs 这里--with-apxs2之后将会在 # ls /etc/httpd/modules/libphp5.so
/etc/httpd/modules/libphp5.so有这个提供给apache加载php使用 这里的--with-apxs2=/usr/sbin/apxs根据实际情况决定(apxs命令目录所在位置,如果apache是编译的话,就要去apache目录下找—这里也根据实际情况) # make && make install # cp php.ini-production /etc/php.ini 配置环境变量,使得php相关命令不需要带上路径 # cat .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin:/usr/local/mongodb-linux-x86_64-1.6.4/bin:/usr/local/php/bin export PATH 最后要source下才生效 # source .bash_profile 4.安装php扩展,对mongodb的支持 # tar -xvf mongo-1.5.5.tgz # cd mongo-1.5.5 # phpize(之后生成configuere文件) # ./configure --enable-mongo=share--with-php-config=php-config # make && make install 5.配置/etc/php.ini extension=mongo.so
register_globals=On 6.配置/etc/httpd/conf/httpd.conf LoadModule php5_module modules/libphp5.so PHPIniDir "/etc/php.ini”
AddType application/x-httpd-php .php AddType application/x-httpd-php .htm AddType application/x-httpd-php .html DirectoryIndex index.html index.html.var index.htmlindex.shtml index.cgi index.php index.phtml index.php3
页:
[1]