设为首页 收藏本站
查看: 1097|回复: 0

源码安装LAMP环境

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-8-5 09:17:37 | 显示全部楼层 |阅读模式

之前在网上找的一些大牛们的源码安装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环境搭建好了。



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-94270-1-1.html 上篇帖子: lamp一键安装第二版 下篇帖子: 64位CentOS 6.5下搭建LAMP环境详细步骤
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表