centos6.5lamp环境搭建

软件的配置,解决遇到的问题

Linux Apache MysqL PHP

mirrors.sohu.com sohu镜像下载网站

mirrors.163.com 网易镜像下载网站

区分平台

uname -i 查看系统位数

i386 32位

x86_64 64位

cd /usr/local/src 存放软件源码包,常用目录

MysqL安装

MysqL安装在/usr/local/MysqL

配置文件/etc/MysqL.cnf

启动脚本/etc/init.d/MysqL

二进制安装,节省编译时间

获取MysqL二进制免编译包

cd /usr/local/src 存放软件源码包

yum install -y wget 安装wget包

wget http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.73-linux-x86_64-glibc23.tar.gz

初始化MysqL

tar zxvf /usr/local/src/.....tar.gz 解包同时解压缩

mv ...... /usr/local/MysqL 移动安装包位置

useradd -s /sbin/nologin MysqL 创建MysqL用户,同时设定不可登陆

cd /usr/local/MysqL 进入MysqL安装目录

mkdir -p /data/MysqL 创建datadir,数据库文件存放位置

chown -R MysqL:MysqL /data/MysqL 级联更改用户用户

./scripts/MysqL_install_db --user=MysqL --datadir=/data/MysqL

--user=MysqL 定义用户所属主 --datadir=/data/MysqL 定义数据库安装到那里

两个ok 安装成功

拷贝配置文件

[root@lijian-centos6 MysqL]# cp support-files/my-large.cnf /etc/my.cnf

cp:是否覆盖"/etc/my.cnf"? y

[root@lijian-centos6 MysqL]#

拷贝启动脚本文件修改权限

[root@lijian-centos6 MysqL]# cp support-files/MysqL.server /etc/init.d/MysqLd

[root@lijian-centos6 MysqL]# chmod 755 /etc/init.d/MysqLd

修改启动脚本

vim /etc/init.d/MysqLd

datadir=/data/MysqL

启动脚本加入系统服务项,并设定开机启动,启动MysqL

chkconfig --add MysqLd

chkconfig MysqLd on

service MysqLd start

检查MysqL是否启动

ps aux| grep MysqLd

MysqL安装成功

安装Apache

cd /usr/local/src 进入文件夹下载源码包

wget http://mirrors.sohu.com/apache/httpd-2.2.32.tar.bz2

解压源码包

[root@lijian-centos6 src]# tar jxvf httpd-2.2.32.tar.bz2

配置编译参数

[root@localhost src]# cd httpd-2.2.24 [root@localhost 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

进入文件所在目录

指定安装位置/usr/local/apache2

配置编译参数时候出现错误,因为缺少软件

configure: error: in `/usr/local/src/httpd-2.2.32/srclib/apr':

configure: error: no acceptable C compiler found in $PATH

*

[root@lijian-centos6 httpd-2.2.32]# yum install -y gcc

checking for zlib location... not found

checking whether to enable mod_deflate... configure: error: mod_deflate has been requested but can not be built due to prerequisite failures

*

[root@lijian-centos6 httpd-2.2.32]# yum install -y zlib-devel

安装一些库,避免make 时出现错误

yum install -y pcre pcre-devel apr apr-devel

make

make install

echo $? 检查结果是否有错

Apache安装完毕

安装PHP

cd /usr/local/src

wget http://mirrors.sohu.com/php/php-5.3.27.tar.gz

tar zxvf PHP-5.3.27.tar.gz

[root@localhost src]# cd PHP-5.3.27 [root@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-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

configure: error: Please reinstall the BZip2 distribution

解决:yum install -y bzip2 bzip2-devel

configure: error: jpeglib.h not found.

解决:yum install -y libjpeg libjpeg-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: mcrypt.h not found. Please reinstall libmcrypt.

解决:安装扩展源

rpm -ivh "http://www.lishiming.net/data/attachment/forum/month_1211/epel-release-6-7.noarch.rpm" 阿明

wget -P /etc/yum.repos.d/http://mirrors.aliyun.com/repo/epel-6.repo

阿里云yum install -y libmcrypt-devel

首先,标题学了下雷不撕的风格。

epel是个好东西,不过国外的速度实在是不能忍受。所以 有了这篇文章

1、 首先卸载以前装的epel 以免影响

rpm -e epel-release

2、 下载阿里提供的epel ,PS感谢马云。

wget -P /etc/yum.repos.d/http://mirrors.aliyun.com/repo/epel-6.repo

3、yum clean all

4、yum makecache

好了,现在你要装epel源的软件的时候 不再慢吞吞了。

全部改成阿里云的源

1、rm -rf /etc/yum.repos.d/* (执行此操作的时候记得事先装好wget 不然 你就得挂载光盘用rpm装wget了。)

2、wget -P /etc/yum.repos.d/http://mirrors.aliyun.com/repo/epel-6.repohttp://mirrors.aliyun.com/repo/Centos-6.repo

这个时候,执行 yum repolist的结果如下

[root@di02 ~]# yum repolist

已加载插件:fastestmirror

Loading mirror speeds from cached hostfile

* base: mirrors.aliyun.com

* epel: mirrors.aliyun.com

* extras: mirrors.aliyun.com

* updates: mirrors.aliyun.com

拷贝配置文件:

[root@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/lcoal/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之前先检验配置文件是否正确:

/usr/local/apache2/bin/apachectl -t

如果有错误,请继续修改httpd.conf,如果是正确的则显示为 “Syntax OK”,启动apache的命令为:

/usr/local/apache2/bin/apachectl start

查看是否启动:

[root@localhost ~]# netstat -lnp |grep httpd tcp 0 0 :::80 :::* LISTEN 7667/httpd

如果有显示这行,则启动了。 也可以使用curl命令简单测试:

[root@localhost ~]# curl localhost <html><body><h1>It works!</h1></body></html>

只有显示这样才正确。

测试是否正确解析PHP:

vim /usr/local/apache2/htdocs/1.PHP

写入:

<?PHP echo "PHP解析正常"; ?>

保存后,继续测试:

curl localhost/1.PHP

看是否能看到如下信息:

[root@localhost ~]# curl localhost/1.PHP PHP解析正常[root@localhost ~]#

只有显示这样才正确。

相关文章

Centos下搭建性能监控Spotlight
CentOS 6.3下Strongswan搭建IPSec VPN
在CentOS6.5上安装Skype与QQ
阿里云基于centos6.5主机VPN配置
CentOS 6.3下配置multipah
CentOS安装、配置APR和tomcat-native