首页 > 代码库 > centos6.5编译安装lamp开发环境
centos6.5编译安装lamp开发环境
一、系统以及软件的准备
系统及编译安装包的下载地址:http://pan.baidu.com/s/1jIjqinc 密码:ghc2
说明:由于centos6.5是分卷压缩的,且压缩为三个压缩包,所以请下载三个压缩包,并放于同一文件夹中,解压CentOS-6.5-x86_64-bin-DVD.zip即可。
lamp安装包文件夹中有19个安装包,均为必要的环境安装包或依赖包;下载完成之后将lamp安装包压缩为.zip格式压缩包。
本次环境安装已以上系统和安装包为实验安装,为确保安装正确,请严格按照以上系统和安装包。
二、系统的安装和网络的配置。
centos6.5 ×86_64的安装,在此省略安装步骤。
vim /etc/sysconfig/network-scripts/ifcfg-eth0 配置好网络。
分区时注意给/usr 分区空间大点,至少10G。因为安装包是放于/usr/local/src/下,且安装的位置都是在/usr/local 下。
三、就绪工作
1. 查看系统是否已经默认安装了httpd、mysql、php。
[root@localhost ~]# rpm -qa | grep httpd* httpd-tools-2.2.15-29.el6.centos.x86_64 httpd-2.2.15-29.el6.centos.x86_64 [root@localhost ~]# rpm -qa | grep mysql* mysql-libs-5.1.71-1.el6.x86_64 [root@localhost ~]# rpm -qa | grep php* redhat-lsb-graphics-4.0-7.el6.centos.x86_64 sane-backends-libs-gphoto2-1.0.21-3.el6.x86_64 gvfs-gphoto2-1.4.3-15.el6.x86_64 phonon-backend-gstreamer-4.6.2-26.el6_4.x86_64 plymouth-graphics-libs-0.8.3-27.el6.centos.x86_64 hyphen-en-2.4-5.1.el6.noarch libreoffice-graphicfilter-4.0.4.2-9.el6.x86_64 hyphen-2.4-5.1.el6.x86_64 libgphoto2-2.4.7-4.el6.x86_64 xorg-x11-drv-elographics-1.4.1-2.el6.x86_64
以上可以看出系统已经默认安装 了相关软件,使用以下命令卸载:
yum –y remove htppd *
yum –y remove mysql*
yum –y remove php*
2. 配置防火墙
Vim /etc/sysconfig/iptables ,在以下相应位置,加入 红色 的两行
A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT -A INPUT -p icmp -j ACCEPT -A INPUT -i lo -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT -A INPUT -j REJECT --reject-with icmp-host-prohibited -A FORWARD -j REJECT --reject-with icmp-host-prohibited
/etc/init.d/iptables restart 重启生效。
3. 关闭selinux
vim /etc/selinux/config
在 SELINUX=enforcing SELINUXTYPE=targeted 两句前面加#号注释 增加一句 SELINUX=disabled 保存完毕后,shutdown –r now 重启系统。如下:
#SELINUX=enforcing # SELINUXTYPE= can take one of these two values: # targeted - Targeted processes are protected, # mls - Multi Level Security protection. #SELINUXTYPE=targeted SELINUX=disabled
4. 上传安装包到指定的位置。
使用rz命令上传到本机。此时得先安装rz命令,使用命令 yum –y install lrzsz 命令。切换到指定目录:cd /usr/local/src ,使用 rz 命令上传安装包,上传完毕后如下:
[root@localhost src]# pwd /usr/local/src [root@localhost src]# ls lamp安装包.zip
解压 lamp安装包.zip, unzip lamp安装包.zip ;修改名称为lamp mv lamp安装包 lamp ,删除lamp安装包.zip rm -rf lamp安装包.zip
四、安装相关源码包
- yum安装编译工具 gcc 和gcc-c++ 用rpm -q make gcc gcc-c++ zlib-devel libaio 查询是否安装以上安装包,用 yum -y install make gcc gcc-c++ zlib-devel libaio 安装以上安装包。
2. 编译安装libxml2 先yum安装python-devel
yum –y install python-devel
cd /usr/local/src/lamp
tar zxvf libxml2-2.9.4.tar.gz
cd libxml2-2.9.4
配置安装目录,命令如下:
[root@localhost libxml2-2.9.4]# ./configure --prefix=/usr/local/libxml2/
编译以及安装 make && make install
此时推荐make 和make install 分两步操作,以便查看错误。且原则上,如果没有报 eorro错误,而只是 leving drictory 是不算错误的。
3. 编译安装libmcrypt
cd/usr/local/src/lamp
tar zxvf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
配置安装目录,命令如下:
[root@localhost libmcrypt-2.5.7]# ./configure --prefix=/usr/local/libmcrypt/
make make install
4. 编译安装zlib
cd/usr/local/src/lamp
tar zxvf zlib-1.2.8.tar.gz
cd zlib-1.2.8
配置安装目录,命令如下
[root@localhost zlib-1.2.8]# ./configure --prefix=/usr/local/zlib/
make make install
5. 编译安装libpng
cd /usr/local/src/lamp
tar zxvf libpng-1.6.23.tar.gz
cd libpng-1.6.23
配置安装目录,命令如下
[root@localhost libpng-1.6.23]# ./configure --prefix=/usr/local/libpng/ --enable-shared
make make install
6. 编译安装jpeg
cd /usr/local/src/lamp
tar zxvf jpegsrc.v9a.tar.gz
cd jpeg-9a/
mkdir /usr/local/jpeg/
mkdir /usr/local/jpeg/bin
mkdir /usr/local/jpeg/lib/
mkdir /usr/local/jpeg/include/
mkdir -p /usr/local/jpeg/man/man1
配置安装目录,命令如下
[root@localhost jpeg-9a]# ./configure --prefix=/usr/local/jpeg/ --enable-shared --enable-static
make make install
7. 编译安装freeetype
cd /usr/local/src/lamp
tar zxvf freetype-2.6.3.tar.gz
cd freetype-2.6.3
配置安装目录,命令如下
[root@localhost freetype-2.6.3]# ./configure --prefix=/usr/local/freetype/ --enable-shared
make make install
8. 编译安装autoconf
cd /usr/local/src/lamp
tar zxvf autoconf-2.69.tar.gz
cd autoconf-2.69
autoconf直接在当前目录配置
./configure
make make install
9. 编译安装GD
cd/usr/local/src/lamp
tar zxvf gd-2.0.35.tar.gz
cd gd-2.0.35
vim gd_png.c
找到#include "png.h"改成#include "/usr/local/libpng/include/png.h" ,如下:
/* JCE: Arrange HAVE_LIBPNG so that it can be set in gd.h */ #ifdef HAVE_LIBPNG #include "gdhelpers.h" #include "/usr/local/libpng/include/png.h" /* includes zlib.h and setjmp.h */ #define TRUE 1 #define FALSE 0
配置安装目录,命令如下
[root@localhost gd-2.0.35]# ./configure --prefix=/usr/local/gd --with-jpeg=/usr/local/jpeg --with-png=/usr/local/libpng --with-zlib=/usr/local/zlib --with-freetype=/usr/local/freetype
make make install
五、安装apache
1. 编译安装apr-1.5.2
先查看是否安装apr 、apr-util 使用命令 rpm -q apr apr-util,如果已经安装则yum –y remove apr apr-util
cd /usr/local/src/lamp
tar zxvf apr-1.5.2.tar.gz
cd apr-1.5.2
配置安装目录,命令如下
[root@localhost apr-1.5.2]# ./configure --prefix=/usr/local/apr-httpd/
make make install
2. 编译安装apr-util
cd /usr/local/src/lamp
tar zxvf apr-util-1.5.4.tar.gz
cd apr-util-1.5.4
配置安装目录,命令如下
[root@localhost apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util-httpd/ --with-apr=/usr/local/apr-httpd
make make install
3. 编译安装pcre
cd/usr/local/src/lamp
tar zxvf pcre-8.34.tar.gz
cd pcre-8.34
配置安装目录,命令如下
[root@localhost pcre-8.34]# ./configure --prefix=/usr/local/pcre
make make install
4. 编译安装apache
cd /usr/local/src/lamp
tar zxvf httpd-2.4.20.tar.gz
cd httpd-2.4.20
配置安装目录,命令如下
[root@localhost httpd-2.4.20]# ./configure --prefix=/usr/local/apache2 --enable-mods-shared=all --enable-deflate --enable-speling --enable-cache --enable-file-cache --enable-disk-cache --enable-mem-cache --enable-so --enable-expires=shared --enable-rewrite=shared --enable-static-support --sysconfdir=/etc/httpd --with-z=/usr/local/zlib/ --with-apr=/usr/local/apr-httpd --with-apr-util=/usr/local/apr-util-httpd --with-pcre=/usr/local/pcre --disable-userdir
make make install
修改配置,vim /etc/httpd/httpd.conf
在配置文件增加一行 ServerName localhost:80
#ServerName www.example.com:80 ServerName localhost:80
启动apache /usr/local/apache2/bin/apachectl start
打开浏览器测试,输入192.168.0.225 (本机ip地址为192.168.0.225)发现 it works 证明 apache安装成功
设置apahce开机启动,使用命令 echo "/usr/local/apache2/bin/apachectl start" >> /etc/rc.d/rc.local
将apache启动加入服务, cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd ,给予执行权限 chmod +x /etc/init.d/httpd
vi /etc/rc.d/init.d/httpd 在第二行加入以下两行 #chkconfig:2345 10 90 #description:Activates/Deactivates Apache Web Server,保存后退出
#!/bin/sh #chkconfig:2345 10 90 #description:Activates/Deactivates Apache Web Server # Licensed to the Apache Software Foundation (ASF) under one or more
chkconfig --add httpd
chkconfig --level 2345 httpd on
service httpd restart
六、安装mysql
1. 编译安装cmake
cd /usr/local/src/lamp
tar zxvf cmake-3.4.3.tar.gz
cd cmake-3.4.3
./bootstrap
gmake
make make install
2. 安装ncurses-devel
yum -y install ncurses-devel
3. 创建用户、组和目录
groupadd mysql
useradd mysql -g mysql
passwd mysql 设置密码为123
mkdir /usr/local/mysql
mkdir /usr/local/mysql/data
chown -R mysql.mysql /usr/local/mysql
4. 编译安装msql
cd/usr/local/src/lamp
tar zxvf mysql-5.5.23.tar.gz
cd mysql-5.5.23
配置安装目录,命令如下
[root@localhost mysql-5.5.23]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DMYSQL_DATADIR=/usr/local/mysql/data -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_USER=mysql-DMYSQL_TCP_PORT=3306
make make install
cd /usr/local/mysql/
给当前安装目录设置权限
chown -R root.mysql .
chown -R mysql.mysql ./data
初始化数据库 /usr/local/mysql/scripts/mysql_install_db --user=mysql
拷贝mysql配置文件 cp support-files/my-medium.cnf /etc/my.cnf
启动mysql服务 /usr/local/mysql/bin/mysqld_safe --user=mysql &
给sock文件设置mysql权限 chown mysql.mysql /tmp/mysql.sock
追加开机启动 echo "/usr/local/mysql/bin/mysqld_safe --user=mysql &" >> /etc/rc.d/rc.local
设置密码为123 /usr/local/mysql/bin/mysqladmin -uroot password 123
测试连接mysql /usr/local/mysql/bin/mysql -uroot -p ,连接成功,则整个mysql安装成功。
为mysql配置环境变量 export PATH=/usr/local/mysql/bin:$PATH
将mysql加入服务 cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
设置远程登录root用户权限,密码为 123 登录录进mysql
use mysql;
GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘123‘ WITH GRANT OPTION;
flush privileges;
重启mysql服务 service mysqld restart
七、安装php
1. 安装libXpm-devel
yum -y install libXpm-devel
2. 编译安装php
cd /usr/local/src/lamp
tar zxvf php-5.6.22.tar.gz
cd php-5.6.22
配置安装目录,命令如下
[root@localhost php-5.6.22]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir=/usr/local/libxml2 --with-png-dir=/usr/local/libpng --with-jpeg-dir=/usr/local/jpeg --with-freetype-dir=/usr/local/freetype --with-gd --with-zlib-dir=/usr/local/zlib --with-mcrypt=/usr/local/libmcrypt --with-xpm-dir=/usr/lib64 --enable-soap --enable-mbstring=all -enable-sockets
make make install
cp php.ini-development /usr/local/php/etc/php.ini
vim /usr/local/php/etc/php.ini
修改php.ini 把;date.timezone 前面的分号去掉,改成date.timezone ="PRC"
vim /etc/httpd/httpd.conf
在AddType application/x-gzip .gz .tgz后面添加两行
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
# # AddType allows you to add to or override the MIME configuration # file specified in TypesConfig for specific file types. # #AddType application/x-gzip .tgz AddType application/x-httpd-php .php .phtml AddType application/x-httpd-php-source .phps # # AddEncoding allows you to have certain browsers uncompress # information on the fly. Note: Not all browsers support this.
将下面一行DirectoryIndex index.html 更改为:DirectoryIndex index.php index.html index.htm 修改完后,退出。
# # DirectoryIndex: sets the file that Apache will serve if a directory # is requested. # <IfModule dir_module> DirectoryIndex index.php index.html index.htm </IfModule>
Service httpd restart
八、安装PDO扩展
cd /usr/local/src/lamp
tar zxvf PDO_MYSQL-1.0.2.tgz.1
cd PDO_MYSQL-1.0.2
/usr/local/php/bin/phpize
ln -s /usr/local/mysql/include/* /usr/local/include/
配置安装目录,命令如下
[root@localhost PDO_MYSQL-1.0.2]# ./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql
make make install
vim /usr/local/php/etc/php.ini
在php.ini里面配置加载pdo 扩展
extension=pdo.so extension=pdo_mysql.so
; For example, on Windows: ; ; extension=msql.dll ; ; ... or under UNIX: ; ; extension=msql.so extension=pdo.so extension=pdo_mysql.so ;
加入一行命令 extension_dir = "/usr/local/php/lib/php/extensions/no-debug-zts-20131226"
; Directory in which the loadable extensions (modules) reside. ; http://php.net/extension-dir ; extension_dir = "./" extension_dir = "/usr/local/php/lib/php/extensions/no-debug-zts-20131226" ; On windows: ; extension_dir = "ext"
重启apache service httpd restart
vim /usr/local/apache/htdocs/index.php phpinfo()检测是否安装成。如图:
参考链接:http://wenku.baidu.com/view/98299b48c5da50e2524d7fd3.html?re=view
centos6.5编译安装lamp开发环境