搭建LAMP环境
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了搭建LAMP环境相关的知识,希望对你有一定的参考价值。
搭建LAMP环境
mysql免编译安装包下载链接(5.1版本):
32位:http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.73-linux-i686-glibc23.tar.gz
64位:http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.73-linux-x86_64-glibc23.tar.gz
如果使用源代码包安装的话,编译时间花费较长
Apache源代码下载链接(2.2版本):
http://mirrors.sohu.com/apache/httpd-2.2.31.tar.bz2
php源代码包下载连接(5.4版本):
http://mirrors.sohu.com/php/php-5.4.44.tar.bz2
安装顺序:mysql、apache、php
将php放到最后安装是因为安装php时需要指定mysql的安装目录和apache的apxs工具的路径。
Mysql安装
首先使用命令uname –i查看系统位数,然后选择相应mysql免编译安装包进行下载。
[[email protected] ~]# cd /usr/local/src
[[email protected] src]# wget http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.73-linux-i686-glibc23.tar.gz
[[email protected] src]# tar -xzvfmysql-5.1.73-linux-i686-glibc23.tar.gz
//解压
[[email protected] src]# mvmysql-5.1.73-linux-i686-glibc23 /usr/local/mysql
//移动mysql安装包到/usr/local/目录下
[[email protected] src]# cd /usr/local/mysql
[[email protected] mysql]# useradd -M -s/sbin/nologin mysql
//创建运行mysql服务的账户
[[email protected] mysql]# mkdir -p /data/mysq
//创建mysql数据文件存放目录
[[email protected] mysql]# chown -R mysql:mysql/data/mysql
[[email protected] mysql]#./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
//初始化mysql服务,--user指定运行mysql服务的账户,--datadir指定数据文件存放目录。这一步骤很关键,如果你看到两个“OK”说明执行正确,否则,请仔细查看错误信息。
下面是两个常见的错误,如果你正好遇到了,那就照着下面的解决办法解决一下。
( 1)遇到错误: ./bin/mysqld: error while loading shared libraries: libstdc++.so.5:cannot
open shared object file:
解决办法:
# yum install -y compat-libstdc++-33
( 2)遇到错误: ./scripts/mysql_install_db: ./bin/my_print_defaults:/lib/ld-linux.so.2: bad
ELF interpreter: No such file or directory
这是因为,你的系统版本和 mysql 版本不一致。比如,你的系统是 32 位,结果你下载
了一个 64 位的包。所以,解决办法是,下载合适的包。
[[email protected] mysql]# cp support-files/my-large.cnf/etc/my.cnf
cp:是否覆盖"/etc/my.cnf"? y
//使用安装包中提供的配置模版文件到替代系统自带/etc/my.cnf文件(my.cnf只能存放在/etc/或者是dasedir目录下)
[[email protected] mysql]# cpsupport-files/mysql.server /etc/init.d/mysqld
[[email protected] mysql]# chmod 755/etc/init.d/mysqld
[[email protected] mysql]# chkconfig --add mysqld
[[email protected] mysql]# chkconfig mysqld on
//使用安装包中提供的启动脚本文件,将mysql加入到系统服务列表里。
[[email protected] mysql]# service mysqld start
Starting MySQL.Manager of pid-file quitwithout updating fi[失败]
//启动失败,提示pid文件没有更新。解决方法:编辑启动配置文件/etc/init.d/mysqld,设置basedir=/usr/local/mysql、datadir=/data/mysql
[[email protected] mysql]# service mysqld start
Starting MySQL. [确定]
[[email protected] mysql]# ps aux|grep mysql
[[email protected] mysql]# netstat -lnp|grepmysql
//查看服务是否启动成功。
[[email protected] mysql]#/usr/local/mysql/bin/mysqladmin -u root password ‘123456‘
//默认mysql的root用户密码为空,为了安全性我们应该设置mysql的root用户密码。(修改密码可以使用命令mysqladmin –u root –p password ‘new-password‘,输入旧密码)
放了能够方便使用mysql的命令,我们应该将路径/usr/local/mysql/bin加入PATH变量中
[[email protected] mysql]# vi/etc/profile.d/path.sh
PATH=$PATH:/usr/local/mysql/bin/
[[email protected] mysql]# source/etc/profile.d/path.sh
Apache安装
常见的源代码包都是用C语言开发的,所以再编译安装源代码包前,应该先安装linux下的C语言编译器gcc。
[[email protected] ~]# yum install –y gcc
[[email protected] ~]# cd /usr/local/src
[[email protected] src]# wget http://mirrors.sohu.com/apache/httpd-2.2.31.tar.bz2
[[email protected] src]# tar -xjvfhttpd-2.2.24.tar.bz2
[[email protected] src]# cd httpd-2.2.24
[[email protected] httpd-2.2.24]# ./configure \
--prefix=/usr/local/apache2 \
--with-included-apr \
--enable-so \
--enable-deflate=shared \
--enable-expires=shared \
--enable-rewrite=shared \
--with-pcre
//配置编译参数,生成Makefile文件
[[email protected] httpd-2.2.24]# echo $?
0
//校验配置编译参数的过程是否出错
如果./configure 这一步你出现了这样的错误:
error: mod_deflate has been requested butcan not be built due to prerequisite failures
解决办法是:
# yum install -y zlib-devel
为了避免在 make 的时候出现错误,所以最好是提前先安装好一些库文件:
# yum install -y pcre pcre-devel aprapr-devel
[[email protected] httpd-2.2.24]# make &&make install
//编译、安装
[[email protected] httpd-2.2.24]# cd/usr/local/apache2/
[[email protected] apache2]# bin/apachectl –M
//查看apache的mpm工作模式
常见的mpm有prefork、worker和event。2.2版本默认使用的mpm是prefork,2.4版本默认使用的是event。编译时可以使用参数—with-mpm=prefork、worker、event选择mpm工作模式(如果选择event还要加上一条参数 --enable-nonportable-atomics=yes )。
Prefork、Worker和Event三种MPM分析:
http://www.cnblogs.com/fnng/archive/2012/11/20/2779977.html
[[email protected] apache2]#PATH=$PATH:/usr/local/apache2/bin
[[email protected] apache2]# vi/etc/profile.d/path.sh
PATH=$PATH:/usr/local/mysql/bin:/usr/local/apache2/bin
将apache添加到启动服务列表里:
[[email protected] ~]# cp/usr/local/apache2/bin/apachectl /etc/init.d/httpd
[[email protected] ~]# vim /etc/init.d/httpd
添加语句# chkconfig: - 66 66
[[email protected] ~]# chkconfig --add httpd
[[email protected] ~]# chkconfig httpd on
[[email protected] ~]# service httpd start
[[email protected] ~]# ps aux|grep httpd
[[email protected] ~]# netstat -lnp|grep httpd
Php安装
[[email protected] apache2]# cd
[[email protected] ~]# cd /usr/local/src/
[[email protected] src]# tar -xzvfphp-5.4.44.tar.gz
[[email protected] src]# cd php-5.4.44
[[email protected] php-5.4.44]# yum –y installepel-release
[[email protected] php-5.4.44]# yum -y installlibxml2-devel openssl-devel bzip2 bzip2-devel libpng-devel libjpeg-turbo-devel freetypefreetype-devel libmcrypt-devel
//为了避免出错,编译安装前先安装一些依赖的包
[[email protected] php-5.4.44]# ./configure \
> --prefix=/usr/local/php \
>--with-apxs2=/usr/local/apache2/bin/apxs \
>--with-config-file-path=/usr/local/php/etc \
> --with-mysql=/usr/local/mysql \
> --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 \
> --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... notfound
configure: error: Please reinstall theBZip2 distribution
解决办法:
# yum install -y bzip2 bzip2-devel
错误:
configure: error: png.h not found.
解决办法:
# yum install -y libpng libpng-devel
错误:
configure: error: freetype.h not found.
解决办法:
# yum install -y freetype freetype-devel
错误:
configure: error: jpeglib.h not found.
解决方法:
# yum -y install libjpeg-turbo-devel
错误:
configure: error: mcrypt.h not found.Please reinstall libmcrypt.
解决办法:
# yum install -y epel-release
# yum install -y libmcrypt-devel
因为 centos6 默认的 yum 源没有 libmcrypt-devel 这个包,只能借助 epel 的 yum 源。
[[email protected] php-5.4.44]# make &&make install
[[email protected] php-5.4.44]# echo $?
[[email protected] php-5.4.44]# 0
[[email protected] php-5.4.44]# cpphp.ini-production /usr/local/php/etc/php.ini
[[email protected] php-5.4.44]# vim /usr/local/php/etc/php.ini
找到;date.timezone = 修改为date.timezone = Asia/Shanghai
[[email protected] ~]# vim/usr/local/apache2/conf/httpd.conf
找到:
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
改为:
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Allow from all
</Directory>
找到:
AddType application/x-gzip .gz .tgz
在该行下面添加:
AddType application/x-httpd-php .php
关联php,让apache能实现解析php脚本
找到:
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
将该行改为:
<IfModule dir_module>
DirectoryIndex index.html index.htmindex.php
</IfModule>
添加默认索引页
再找到:
#ServerName www.example.com:80
修改为:
ServerName localhost:80
如果不去掉#,则启动 apache 时,会有警告信息“httpd: Could not reliably determine the
server‘s fully qualified domain name, usinglocalhost.localdomain for ServerName”,看起来像是
错误,其实没有影响。
[[email protected] ~]# apachectl -t
Syntax OK
//检查配置文件是否有错
测试是否成功解析php文件
[[email protected] ~]# vim/usr/local/apache2/htdocs/index.php
<?php
phpinfo()
?>
[[email protected] ~]# service httpd restart
[[email protected] ~]# curl localhost/index.php
This is test![[email protected] ~]#
本文出自 “好大一只葫芦” 博客,请务必保留此出处http://zhuxingye.blog.51cto.com/11121336/1740083
以上是关于搭建LAMP环境的主要内容,如果未能解决你的问题,请参考以下文章