之前在网上找的一些大牛们的源码安装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.gz tar -xzvf mysql-5.1.40-linux-x86_64-icc-glibc23.tar.gz tar -xzvf php-5.3.28.tar.gz
开始安装mysql
下载: wget http://syslab.comsenz.com/downlo ... -icc-glibc23.tar.gz把解压完的数据移动到/usr/local/mysql [iyunv@localhost src]# mv mysql-5.1.40-linux-x86_64-icc-glibc23 /usr/local/mysql 建立mysql用户 [iyunv@localhost src]# useradd -s /sbin/nologin mysql 初始化数据库 [iyunv@localhost src]# cd /usr/local/mysql [iyunv@localhost mysql]# mkdir -p /data/mysql ; chown -R mysql:mysql /data/mysql [iyunv@localhost 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++*安装依赖包 拷贝配置文件 [iyunv@localhost mysql]# cp support-files/my-large.cnf /etc/my.cnf 拷贝启动脚本文件并修改其属性 [iyunv@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld [iyunv@localhost mysql]# chmod 755 /etc/init.d/mysqld 修改启动脚本 [iyunv@localhost mysql]# vim /etc/init.d/mysqld 需要修改的地方有 “datadir=/data/mysql” (前面初始化数据库时定义的目录) 把启动脚本加入系统服务项,并设定开机启动,启动mysql [iyunv@localhost mysql]# chkconfig --add mysqld [iyunv@localhost mysql]# chkconfig mysqld on [iyunv@localhost mysql]# service mysqld start 如果启动不了,请到 /data/mysql/ 下查看错误日志,这个日志通常是主机名.err. 检查mysql是否启动的命令为: [iyunv@localhost mysql]# ps aux |grep mysqld 将mysql自带命令放入$PATH [iyunv@localhost ~]# PATH=$PATH:/usr/local/mysql/bin/#当前有效,重启shell就失效 [iyunv@localhost ~]# echo "export PATH=$PATH:/usr/local/mysql/bin/" >>/etc/profile
安装Apache
apache官网下载地址: http://www.apache.org/dyn/closer.cgi [iyunv@localhost mysql]# cd /usr/local/src/ [iyunv@localhost src]# wget http://syslab.comsenz.com/downloads/linux/httpd-2.2.16.tar.gz 解压: [iyunv@localhost src]# tar zxvf httpd-2.2.16.tar.gz 配置编译参数: [iyunv@localhost src]# cd httpd-2.2.16 [iyunv@localhost 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 [1] --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 编译: [iyunv@localhost httpd-2.2.16]# make 安装: [iyunv@localhost httpd-2.2.16]# make install 以上两个步骤都可以使用 echo $? 来检查是否正确执行,否则需要根据错误提示去解决问题。 将apache自带命令放入$PATH [iyunv@localhost ~]# PATH=$PATH:/usr/local/apache2/bin/#当前有效,重启shell就失效 [iyunv@localhost ~]# echo "export PATH=$PATH:/usr/local/apache2/bin" >>/etc/profile [iyunv@localhost ~]#source /etc/profile使配置PATH立即生效
安装PHP
php官方下载地址: http://www.php.net/downloads.php
[rot@localhost httpd-2.2.16]# cd /usr/local/src 解压: [iyunv@localhost src]# tar zxf php-5.3.27.tar.gz 配置编译参数: [iyunv@localhost src]# cd php-5.3.27 [iyunv@localhost 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 found configure: 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 -y libmcrypt-devel 因为centos6.x 默认的yum源没有libmcrypt-devel 这个包,只能借助第三方yum源,之前已经安装过了epel源,所以可以直接yum安装。 编译: [iyunv@localhost php-5.3.27]# make 安装: [iyunv@localhost php-5.3.27]# make install 如果报错: /usr/bin/ld: cannot find -lltdl 解决办法: yum -y install libtool-ltdl-devel 安装完成后使用如下命令检测 echo$? /usr/local/apache2/bin/apachectl -M检查是否加载了PHP模块 拷贝配置文件: [iyunv@localhost php-5.3.27]# cp php.ini-production /usr/local/php/etc/php.ini
apache结合php
Apache主配置文件为:/usr/local/apache2/conf/httpd.conf vim /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 查看是否启动: [iyunv@localhost ~]# netstat -lnp |grep httpd tcp 0 0 :::80 :::* LISTEN 7667/httpd 如果有显示这行,则启动了。 也可以使用curl命令简单测试: [iyunv@localhost ~]# 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服务的时候,你可能无法访问,这是因为防火墙的缘故。请运行下面的命令: [iyunv@localhost ~]# iptables -F 这样就可以清除系统默认的防火墙规则,放行80端口。 LAMP环境搭建好了。
|