t434111 发表于 2015-8-5 09:17:37

源码安装LAMP环境

之前在网上找的一些大牛们的源码安装lamp环境的文章,总是达不到他们实现的效果,于是决定自己总结一篇源码安装LAMP环境的文章,以供自己以后作为参考资料以及帮助像我这样的linux系统小白学习分享,大神看了请轻喷,谢谢!操作系统环境:CentOS6.6 X86_X64 FINAL
源码安装LAMP环境首先上传源码包到/usr/local/src/lamp目录下,版本是httpd-2.2.16.tar.gz        mysql-5.1.40-linux-x86_64-icc-glibc23.tar.gz        php-5.3.28.tar.gz然后使用tar -xzvf 解压源码包tar -xzvf httpd-2.2.16.tar.gztar -xzvf mysql-5.1.40-linux-x86_64-icc-glibc23.tar.gztar -xzvf php-5.3.28.tar.gz

开始安装mysql
下载:wget http://syslab.comsenz.com/downloads/linux/mysql-5.1.40-linux-i686-icc-glibc23.tar.gz把解压完的数据移动到/usr/local/mysql# mv mysql-5.1.40-linux-x86_64-icc-glibc23 /usr/local/mysql建立mysql用户# useradd -s /sbin/nologin mysql初始化数据库# cd /usr/local/mysql# mkdir -p /data/mysql ; chown -R mysql:mysql /data/mysql# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql--user 定义数据库的所属主, --datadir 定义数据库安装到哪里,建议放到大空间的分区上,这个目录需要自行创建。这一步骤很关键,如果看到两个 “OK” 说明执行正确,否则请仔细查看错误信息错误信息为./bin/mysqld: error while loading shared libraries: libstdc++.so.5: cannot open shared object file: No such file or directory使用yum -y install epel-release使用yum -y install *libstdc++*安装依赖包拷贝配置文件# cp support-files/my-large.cnf /etc/my.cnf拷贝启动脚本文件并修改其属性# cp support-files/mysql.server/etc/init.d/mysqld# chmod 755 /etc/init.d/mysqld修改启动脚本# vim /etc/init.d/mysqld需要修改的地方有 “datadir=/data/mysql” (前面初始化数据库时定义的目录)把启动脚本加入系统服务项,并设定开机启动,启动mysql# chkconfig --add mysqld# chkconfig mysqld on# service mysqld start如果启动不了,请到 /data/mysql/ 下查看错误日志,这个日志通常是主机名.err. 检查mysql是否启动的命令为:# ps aux |grep mysqld将mysql自带命令放入$PATH# PATH=$PATH:/usr/local/mysql/bin/#当前有效,重启shell就失效# echo "export PATH=$PATH:/usr/local/mysql/bin/" >>/etc/profile


安装Apache
apache官网下载地址: http://www.apache.org/dyn/closer.cgi # cd /usr/local/src/# wget http://syslab.comsenz.com/downloads/linux/httpd-2.2.16.tar.gz解压:# tar zxvf httpd-2.2.16.tar.gz配置编译参数:# cd httpd-2.2.16# ./configure \--prefix=/usr/local/apache2 \--with-included-apr \--enable-so \--enable-deflate=shared \--enable-expires=shared \--enable-rewrite=shared \--with-pcre--prefix 指定安装到哪里, --enable-so 表示启用DSO --enable-deflate=shared 表示共享的方式编译deflate,后面的参数同理。如果这一步你出现了这样的错误:error: mod_deflate has been requested but can not be built due to prerequisite failures解决办法是:yum install -y zlib-devel为了避免在make的时候出现错误,所以最好是提前先安装好一些库文件:yum install -y pcre pcre-devel apr apr-devel编译:# make安装:# make install以上两个步骤都可以使用 echo $? 来检查是否正确执行,否则需要根据错误提示去解决问题。将apache自带命令放入$PATH# PATH=$PATH:/usr/local/apache2/bin/#当前有效,重启shell就失效# echo "export PATH=$PATH:/usr/local/apache2/bin" >>/etc/profile#source /etc/profile使配置PATH立即生效


安装PHP
php官方下载地址: http://www.php.net/downloads.php
# cd /usr/local/src解压:# tar zxf php-5.3.27.tar.gz配置编译参数:# cd php-5.3.27# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/php/etc --with-gd --with-gettext --with-libxml-dir=/usr/local --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif --enable-bcmath --enable-mbstring --enable-sockets --disable-ipv6在这一步,遇到如下错误:configure: error: xml2-config not found. Please check your libxml2 installation.解决办法是:yum install -y libxml2-devel错误:configure: error: Cannot find OpenSSL's <evp.h>解决办法是:yum install -y openssl openssl-devel错误:checking for BZip2 in default path... not foundconfigure: error: Please reinstall the BZip2 distribution解决办法:yum install -y bzip2 bzip2-devel错误:configure: error: png.h not found.解决办法:yum install -y libpng libpng-devel错误:configure: error: jpeglib.h not found.解决办法:yum -y install *jpeglib*错误:configure: error: freetype.h not found.解决办法:yum install -y freetype freetype-devel错误:configure: error: mcrypt.h not found. Please reinstall libmcrypt.解决办法:yum install -ylibmcrypt-devel因为centos6.x 默认的yum源没有libmcrypt-devel 这个包,只能借助第三方yum源,之前已经安装过了epel源,所以可以直接yum安装。编译:# make安装:# make install如果报错:/usr/bin/ld: cannot find -lltdl解决办法:yum -y install libtool-ltdl-devel安装完成后使用如下命令检测echo$?/usr/local/apache2/bin/apachectl -M检查是否加载了PHP模块拷贝配置文件:# cp php.ini-production /usr/local/php/etc/php.ini

apache结合php
Apache主配置文件为:/usr/local/apache2/conf/httpd.confvim /usr/local/apache2/conf/httpd.conf找到:AddType application/x-gzip .gz .tgz在该行下面添加:AddType application/x-httpd-php .php找到:<IfModule dir_module>    DirectoryIndex index.html</IfModule>将该行改为:<IfModule dir_module>    DirectoryIndex index.html index.htm index.php</IfModule>找到:#ServerName www.example.com:80修改为:ServerName localhost:80测试LAMP是否成功
启动apache之前先检验配置文件是否正确:apachectl -t如果有错误,请继续修改httpd.conf, 如果是正确的则显示为 “Syntax OK”, 启动apache的命令为:apachectl start查看是否启动:# netstat -lnp |grep httpdtcp      0      0 :::80                     :::*   LISTEN      7667/httpd如果有显示这行,则启动了。 也可以使用curl命令简单测试:# curl localhost<html><body><h1>It works!</h1></body></html>只有显示这样才正确。测试是否正确解析php:vim /usr/local/apache2/htdocs/1.php写入:<?php echo phpinfo();?>保存后,继续测试:用浏览器打开http://IP/1.php页面看是否能看到如下信息:PHP配置详细信息初次使用浏览器访问我们的web服务的时候,你可能无法访问,这是因为防火墙的缘故。请运行下面的命令:# iptables -F这样就可以清除系统默认的防火墙规则,放行80端口。LAMP环境搭建好了。
页: [1]
查看完整版本: 源码安装LAMP环境