LAMP平台构成组件:Linux、Apache、MySQL、PHP 构建PHP运行环境 安装前工作: 确保没有rpm包PHP,且以源码包安装Apache、MySQL程序(详见搭建LAMP架构之Apache和MySQL) 安装GD库和GD库关联程序(gd库要是2.1版本以上) (使之支持加载.jpeg、.png等图片) yum-yinstall\ libjpeg-devel\ libpng-devel\ freetype-devel\ zlib-devel\ gettext-devel\ libXpm-devel\ libxml2-devel\ fontconfig-devel\ openssl-devel\ bzip2-devel (还有gcc、gcc-c++、make等开发工具系统中要已安装) 解压缩gd-2.1.0.tar.gz tarzxvfgd-2.1.0.tar.gz/usr/src 到gd源码包目录配置编译并安装 ./configure--prefix=/usr/local/gd make&&makeinstall 安装PHP 解压PHP-5.5.4源码包 tarzxvfphp-5.5.4.tar.gz2/usr/src 进入php源码包目录配置编译并安装 ./configure\ --prefix=/usr/local/php\ --with-apxs2=/usr/local/apache/bin/apxs\ --with-gd=/usr/local/gd\ --with-gd\ --with-mysql=/usr/local/mysql\ --with-config-file-path=/etc\ --enable-sqlite-utf8\ --with-zlib-dir\ --with-libxml-dir\ --with-freetype-dir\ --with-jpeg-dir\ --with-png-dir\ --with-ttf\ --with-iconv\ --with-openssl\ --with-gettext\ --enable-mbstring\ --enable-gd-native-ttf\ --enable-gd-jis-conv\ --enable-static\ --enable-zend-multibyte\ --enable-inline-optimization\ --enable-sockets\ --enable-soap\ --enable-ftp\ --disable-ipv6 配置中需注意: --with-apxs2=:指向Apache安装目录下的/bin/apxs --with-gd=:指向GD的安装目录 --with-gd:不能省略,不然编译时会出错 --with-mysql=:指向MySQL安装目录 --with-config-file-path=:指定PHP的配置文件放置目录 make&&makeinstall PHP不作为系统程序而存在,就相当于一个插件,协同Apache和MySQL工作。配置文件默认没有,可以把源码包目录下的模板拷过来就可以了(配置文件所在目录在源码包配置时--with-config-file-path=指定的目录,一般指向/etc) cp/usr/src/php-5.5.4/php.ini-production/etc/php.ini 重新配置Apache配置文件httpd.conf,使之支持PHP vi/usr/local/apache/conf/httpd.conf 添加 AddTypeapplication/x-httpd-php.php AddTypeapplication/x-httpd-php-source.phps 为了方便管理,一般把这两行插在AddType配置项一起 查看配置项中有没有下面一行配置项,如果没有则添加 LoadModulephp5_modulemodules/libphp5.so 配置DirectoryIndex首页配置,使Apache支持.php动态首页 DirectoryIndexindex.phpindex.html 重启Apache服务 servicehttpdrestart 测试PHP网页是否能正确显示 在Apache网站根目录添加Index.php动态首页, viindex.php 编辑内容 <?php phpinfo(); ?> 登录网站首页测试 测试PHP网页是否能访问MySQl数据库 编辑Index.php网页中内容为 <?php $link=mysql_connect('192.168.1.1','tom','123'); if(!$link)echo"Fail!!"; elseecho"Success!!"; mysql_close(); ?> (192.168.1.1为服务器的IP地址,在MySQL数据库中添加授权用户tom,密码为123) 如果能访问,显示为Success!!,反之则为Fail!!
|