当前位置: > CentOS > CentOS服务器 > 环境配置 >

CentOS 6.2 Minimal 编译安装LAMP

时间:2016-07-14 14:29来源:linux.it.net.cn 作者:IT
安装好Centos 6.2 Minimal后,第一件事导入Fedora EPEL repo安装源、安装yum优先级控制软件并升级内核:

rpm -ivh http://mirrors.sohu.com/fedora-epel/6/x86_64/epel-release-6-7.noarch.rpm
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
yum -y install yum-priorities
yum update
—————————————————————————


編譯前準備工作

卸载yum或rpm安装的amp软件(CentOS Minimal不需要)

rpm -e httpd
rpm -e mysql
rpm -e php
yum -y remove httpd
yum -y remove php
yum -y remove mysql-server mysql
yum -y remove php-mysql


安裝編譯工具

安装编译工具gcc gcc-c++make automake autoconf kernel-devel
安装PHP所需依赖,如libxml2-devel openssl-devel curl-devel libjpeg-devel libpng-devel等
yum -y install gcc gcc-c++ make automake autoconf kernel-devel ncurses-devel libxml2-devel openssl-devel curl-devel libjpeg-devel libpng-devel pcre-devel libtool-libs freetype-devel gd zlib-devel file bison patch mlocate flex diffutils readline-devel glibc-devel glib2-devel bzip2-devel gettext-devel libcap-devel libmcrypt-devel
安裝下載工具

yum -y install wget


下载所需的源码
下载apache(http://httpd.apache.org)

wget http://labs.renren.com/apache-mirror//httpd/httpd-2.4.2.tar.gz
下载MySQL(http://mysql.mirror.kangaroot.net/Downloads/MySQL-5.5/)

wget http://mysql.mirror.kangaroot.net/Downloads/MySQL-5.5/mysql-5.5.25.tar.gz
下载php(http://www.php.net)

wget http://cn.php.net/get/php-5.4.4.tar.gz/from/this/mirror
下载cmake(MySQL编译工具)

wget http://www.cmake.org/files/v2.8/cmake-2.8.8.tar.gz
下载libmcrypt(PHPlibmcrypt模块)

wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
下载apr(Apache库文件)

wget http://mirror.bit.edu.cn/apache//apr/apr-1.4.6.tar.gz
下载apr-util(Apache库文件)

wget http://labs.mop.com/apache-mirror//apr/apr-util-1.4.1.tar.gz
下載APR iconv(Apache库文件)

wget http://labs.mop.com/apache-mirror//apr/apr-iconv-1.2.1.tar.gz


開始編譯安裝

安装libmcrypt

cd /usr/local/src
tar zxf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
./configure && make && make install


安装cmake

cd /usr/local/src
tar zxf cmake-2.8.8.tar.gz
cd cmake-2.8.8
./configure && make && make install


安装Apr

cd /usr/local/src
tar zxf apr-1.4.6.tar.gz
cd apr-1.4.6
./configure --prefix=/usr/local/apr && make && make install


安装Apr-util

cd /usr/local/src
tar zxf apr-util-1.4.1.tar.gz
cd apr-util-1.4.1
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config && make && make install


安装Apr-iconv

cd /usr/local/src
tar zxf apr-iconv-1.2.1.tar.gz
cd apr-iconv-1.2.1
./configure --prefix=/usr/local/apr-iconv --with-apr=/usr/local/apr/bin/apr-1-config && make && make install


安装Mysql

(準備工作)

#添加mysql组并创建用户mysql并加入到mysql组,不允许mysql用户直接登录系统
groupadd mysql && useradd -g mysql mysql -s /bin/false
#创建MySQL数据库存放目录并设置MySQL数据库目录权限
mkdir -p /var/data/mysql && chown -R mysql:mysql /var/data/mysql
#创建MySQL安装目录
mkdir -p /usr/local/mysql
#進入源碼目錄解壓mysql源代碼并進入源碼目錄
cd /usr/local/src && tar zxvf mysql-5.5.25.tar.gz && cd mysql-5.5.25
#配置、編譯和安裝
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/var/data/mysql -DSYSCONFDIR=/etc && make && make install
(配置工作)

cd /usr/local/mysql
cp ./support-files/my-huge.cnf /etc/my.cnf #拷贝配置文件(注意:/etc目录下面默认有一个my.cnf,直接覆盖即可)
vi /etc/my.cnf #编辑配置文件,在 [mysqld] 部分增加
datadir = /var/data/mysql #添加MySQL数据库路径

./scripts/mysql_install_db --user=mysql #生成mysql系统数据库
cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld #把Mysql加入系统服務
chmod 755 /etc/init.d/mysqld #增加执行权限


(開啟自啟動)

chkconfig mysqld on #加入开机启动
vi /etc/rc.d/init.d/mysqld #编辑Mysql服务参数
basedir = /usr/local/mysql #MySQL程序安装路径
datadir = /var/data/mysql #MySQl数据库存放目录

service mysqld start #启动Mysql服务
vi /etc/profile #把mysql服务加入系统环境变量:在最后添加下面这一行
export PATH=$PATH:/usr/local/mysql/bin



#下面这两行把myslq的库文件链接到系统默认的位置,这样你在编译类似PHP等软件时可以不用指定mysql的库文件地址
ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql && ln -s /usr/local/mysql/include/mysql /usr/include/mysql
shutdown -r now #需要重启系统,等待系统重新启动之后继续在终端命令行下面操作


mysql_secure_installation #设置Mysql密码
根据提示按Y,回车输入2次密码



或者直接修改密码

/usr/local/mysql/bin/mysqladmin -u root -p password "123456" #修改密码


service mysqld restart #重启
安装Apache2



cd /usr/local/src && tar -zvxf httpd-2.4.2.tar.gz
cd httpd-2.4.2
mkdir -p /usr/local/apache2 #创建安装目录
./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-apr-iconv=/usr/local/apr-iconv --with-ssl --enable-ssl --enable-so --enable-deflate=shared --enable-expires=shared --enable-headers=shared --enable-rewrite=shared --enable-static-support #配置、編譯和安装
编译参数解释:
–prefix=/usr/local/apache:指定安装目录
–with-apr=/usr/local/apr #指定apr目錄
–with-apr-util=/usr/local/apr-util #指定apr-util目錄
–with-apr-iconv=/usr/local/apr-iconv #指定apr-iconv目錄
–enable-so:允许运行时加载DSO模块
–enable-deflate=shared:将deflate模块编译为DSO
–enable-expires=shared:将expires模块编译为DSO
–enable-headers=shared:将headers模块编译为DSO
–enable-rewrite=shared:将rewrite模块编译为DSO
–enable-static-support:使用静态连接(默认为动态连接)编译所有二进制支持程序



更详细的编译参数解释:http://lamp.linux.gov.cn/Apache/ApacheMenu/programs/configure.html

/usr/local/apache2/bin/apachectl -k start #启动


(配置工作)
vi /usr/local/apache2/conf/httpd.conf #编辑配置文件
找到:#ServerName www.example.com:80
修改为:ServerName www.localhost.com.cn:80
找到:DirectoryIndex index.html
修改为:DirectoryIndex index.html index.php
找到:Options Indexes FollowSymLinks
修改为:Options FollowSymLinks #不显示目录结构
找到:AllowOverride None
修改为:AllowOverride All #开启apache支持伪静态,有两处都做修改
LoadModule rewrite_module modules/mod_rewrite.so #取消前面的注释,开启apache支持伪静态



vi /etc/profile #添加apache服务系统环境变量
#在最后添加下面这一行
export PATH=$PATH:/usr/local/apache2/bin





cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd #把apache加入到系统服務
vi /etc/init.d/httpd
在#!/bin/sh下面添加以下两行
#chkconfig:2345 10 90
#descrption:Activates/Deactivates Apache Web Server



chown daemon.daemon -R /var/www #更改目录所有者
chmod 700 /var/www -R #更改apache网站目录权限
chkconfig httpd on #设置开机启动
service httpd restart
安装php

cd /usr/local/src
tar -zvxf php-5.4.4.tar.gz
cd php-5.4.4
mkdir -p /usr/local/php5 #建立php安装目录
./configure --prefix=/usr/local/php5 --with-config-file-path=/usr/local/php5/etc --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/tmp/mysql.sock --with-gd --with-iconv --with-freetype --with-jpeg --with-png --with-zlib--with-libxml --enable-xml --enable-discard-path --enable-magic-quotes --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-force-cgi-redirect --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --with-mime-magic --enable-suhosin --enable-session --with-mcrypt && make && make install #配置、编译和安装
mkdir /usr/local/php5/etc
cp php.ini-production /usr/local/php5/etc/php.ini #复制php配置文件到安装目录
rm -rf /etc/php.ini #删除系统自带的配置文件
ln -s /usr/local/php5/etc/php.ini /etc/php.ini #创建配置文件软链接
(配置工作)

vi /usr/local/php5/etc/php.ini #编辑


disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popep,assthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname #列出PHP可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用。
date.timezone = PRC
expose_php = OFF #禁止显示php版本的信息
display_errors = OFF #关闭错误提示


配置apache支持php

vi /usr/local/apache2/conf/httpd.conf #编辑apache配置文件
在LoadModule php5_module modules/libphp5.so这一行下面添加:
AddType application/x-httpd-php .php (注意:php .php这个点前面有一个空格)

service httpd restart && service mysqld restart #重启apache和mysql


—————————————————————————————-

配置防火牆,允許防火牆通過21(FTP)、80(WEB)、3306(MYSQL)端口

vi /etc/sysconfig/iptables


#########################################################
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-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 21 -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
COMMIT
#########################################################
service iptables restart //最后重启防火墙使配置生效



(责任编辑:IT)
------分隔线----------------------------