CentOS 6.5 安装与配置LAMP
软件版本:
Linux: CentOS-6.5-minimal
Apache:httpd-2.4.9
MySQL:mysql-5.5.38
PHP: php-5.5.13
准备工作:
1、 下载源码包
创建存放目录:mkdir –p /usr/local/src/LAMP
cd /usr/local/src/LAMP
下载Apache:wget http://mirror.bit.edu.cn/apache/httpd/httpd-2.4.9.tar.gz
依赖包:openssl-1.0.1g apr-1.5.1 apr-util-1.5.3 pcre-8.35 zlib-1.2.8 pcre-8.35 per5
openssl:wgethttp://www.openssl.org/source/openssl-1.0.1g.tar.gz
依赖包:perl-5.20.0
perl:wgethttp://www.cpan.org/src/5.0/perl-5.20.0.tar.gz
apr:wget http://apache.fayea.com/apache-mirror//apr/apr-1.5.1.tar.gz
apr-util:wgethttp://mirrors.cnnic.cn/apache//apr/apr-util-1.5.3.tar.gz
zlib:wgethttp://zlib.net/zlib-1.2.8.tar.gz
pcre:wgetftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.35.tar.gz
MySQL:wgethttp://cdn.mysql.com/Downloads/MySQL-5.5/mysql-5.5.38.tar.gz
依赖包:cmake-2.8.12.2 ncurses-5.9
ncureses:wgethttp://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.9.tar.gz
cmake: wgethttp://www.cmake.org/files/v2.8/cmake-2.8.12.2.tar.gz
PHP:wget http://cn2.php.net/distributions/php-5.5.13.tar.gz
依赖包:libxml2-2.9.0 libtool-2.4.2 libpng-1.6.10 jpeg6 freetype-2.5.3 libmcrypt-2.5.8 libgd-2.1.0
libxml2:wgethttp://xmlsoft.org/sources/libxml2-sources-2.9.0.tar.gz
libtool:wget http://mirrors.ustc.edu.cn/gnu/libtool/libtool-2.4.2.tar.gz
libpng:wgethttp://ncu.dl.sourceforge.net/project/libpng/libpng16/1.6.10/libpng-1.6.10.tar.gz
jpeg6:wget http://www.ijg.org/files/jpegsrc.v6b.tar.gz
freetype:wget http://fossies.org/linux/misc/freetype-2.5.3.tar.gz
libmcrypt:wgethttp://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
gd: wget https://bitbucket.org/libgd/gd-libgd/downloads/libgd-2.1.0.tar.gz
2、配置防火墙,开启80端口、3306端口
sed -i '10a -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT'/etc/sysconfig/iptables #允许80端口通过防火墙
sed -i '11a -A INPUT -m state --state NEW -m tcp -ptcp --dport 3306 -j ACCEPT' /etc/sysconfig/iptables #允许3306端口通过防火墙
/etc/init.d/iptables restart #重启防火墙
3、关闭SELinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled'/etc/selinuxconfig
4、重启系统
shutdown -r now
安装:
一、安装MySQL
1.安装cmake:
cd/usr/local/src/LAMP
tar -zxvf cmake-2.8.12.2.tar.gz
cd cmake-2.8.12.2
./configure
make && make install
2.安装ncurses:
cd/usr/local/src/LAMP
tar -zxvf ncurses-5.9.tar.gz
cd ncurses-5.9
./configure
make && make install
yum install -y ncurses-devel
2.安装MySQL:
groupadd mysql
useradd mysql -g mysql -M -s /sbin/nologin
cd /usr/local/src/LAMP
tar -zxvf mysql-5.5.38.tar.gz
cd mysql-5.5.38
cmake .
make && make install
cd /usr/local/mysql
chown -R mysql:mysql .
scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql--datadir=/usr/local/mysql/data
cp support-files/my-medium.cnf /etc/my.cnf
cp support-files/mysql.service /etc/rc.d/init.d/mysql
service mysql start
chkconfig --add mysql
chkconfig mysql on
二、安装Apache
1.安装pcre:
cd/usr/local/src/LAMP
tar -zxvf pcre-8.35.tar.gz
cd pcre-8.35
./configure --prefix=/usr/local/pcre
make && make install
2.安装openssl-1.0.1g:
1) .安装perl5:
cd/usr/local/src/LAMP
tar–zxvf perl-5.20.0.tar.gz
cdperl-5.20.0
./configure.gnu--prefix=/usr/local/perl
make&& make install
2) .安装openssl:
cd /usr/local/src/LAMP
tar -zxvf openssl-1.0.1g.tar.gz
cd openssl-1.0.1g
./config -fPIC --prefix=/usr/local/openssl/ enable-shared
make && make install
3.安装zlib
cd /usr/local/src/LAMP
tar -zxvf zlib-1.2.8.tar.gz
cd zlib-1.2.8/
./configure
make && make install
4.安装Apache
1) .将apr和apr-util解压复制到apache解压目录的srclib下:
cd /usr/local/src/LAMP
tar -zxvf httpd-2.4.9.tar.gz
tar -zxvf apr-1.5.1.tar.gz
tar -zxvf apr-util-1.5.3.tar.gz
mv apr-1.5.1 httpd-2.4.9/srclib/apr
mv apr-util-1.5.3 httpd-2.4.9/srclib/apr-util
2) .安装:
cd httpd-2.4.9
./configure --prefix=/usr/local/apache --enable-so --enable-rewrite --enable-ssl --with-ssl=/usr/local/openssl--with-zlib --enable-mods-shared=all --enable-track-vars--with-mysql=/usr/local/mysql --with-included-apr --with-pcre=/usr/local/pcre
make && make install
3) .启动Apache:
/usr/local/apache/bin/apachectl-k start
4) .配置自启动:
echo"/usr/local/apache-2.2.15/bin/apachectl start" >>/etc/rc.local
三、安装PHP5
1.安装libmcrypt
cd /usr/local/src/LAMP
tar -zxvf libcrypt-2.5.8.tar.gz
cd libcrypt-2.5.8
./configure
make && make install
2.安装libxml2
cd /usr/local/src/LAMP
tar -zxvf libxml2-sources-2.9.0.tar.gz
cd libxml2-2.9.0/
./configure --prefix=/usr/local/libxml
make && make install
3.安装libpng
cd /usr/local/src/LAMP
tar -zxvf libpng-1.6.10.tar.gz
cd libpng-1.6.10
./configure --prefix=/usr/local/libpng
make && make install
4.安装jpeg6
mkdir /usr/local/jpeg6
mkdir /usr/local/jpeg6/bin
mkdir /usr/local/jpeg6/lib
mkdir /usr/local/jpeg6/include
mkdir -p /usr/local/jpeg6/man/man1
cd /usr/local/src/LAMP
tar -zxvf jpegsrc.v6b.tar.gz
cd jpeg-6b/
cp -f /usr/local/share/libtool/config/config.sub config.sub
cp -f /usr/local/share/libtool/config/config.guess config.guess
./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static
make && make install
5.安装libgd
cd /usr/local/src/LAMP
tar -zxvf libgd-2.1.0.tar.gz
cd libgd-2.1.0
./configure --prefix=/usr/local/gd --with-zlib--with-jpeg=/usr/local/jpeg6 --with-png=/usr/local/libpng--with-freetype=/usr/local/freetype
make && make install
6.安装PHP
cd /usr/local/src/LAMP
tar -zxvf php-5.5.12.tar.gz
cd php-5.5.12
./configure --prefix=/usr/local/php--with-config-file-path=/usr/local/php/etc--with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql --with-libxml-dir=/usr/local/libxml--with-png-dir=/usr/local/libpng --with-jpeg-dir=/usr/local/jpeg6--with-freetype-dir=/usr/local/freetype --with-gd=/usr/local/gd--with-zlib-dir=/usr --with-mcrypt=/usr/local/libmcrypt--with-mysqli=/usr/local/mysql/bin/mysql_config --with-xpm-dir=/usr/lib64--enable-soap --enable-mbstring=all --enable-sockets
make && make install
配置:
一.Apache配置
二.vi /usr/local/apache/conf/httpd.conf
1.#ServerName 把#去掉,后面的IP改成本机的IP
2.在AddType下添加Addtype application/x-httpd-php .php#添加对PHP的支持3./usr/local/apache/bin/apachectlrestart #重启
二.PHP配置
vi /usr/local/php/etc/php.ini
1.将date.timezone =改为date.timezone = PRC
2./usr/local/apache/bin/apachectl restart #重启
三.配置MySQL
1.给添加root添加密码:/usr/local/mysql/bin/bin/mysqladmin -u root password
2.添加中文支持:vi /etc/my.cnf
在[client]下添加default-character-set=utf8
在[mysqld]下添加character-set-server=utf8
collation-server=utf8_general_ci
3.删除用户名为空的记录:delete from user where user=’’;
4.禁止root远程登录:delete from user where user='root' and host='%';
测试:
vi/usr/local/php/htdocs/phpinfo.php
<?php
phpinfo();
?>
运行结果: