lamp的搭建

boxifeng 2015-07-21

最近在vagrant下搭建lamp系统,问题不少。。。

版本:CentOS6.6+apache2.2+mysql5.6+php5.4+JDK1.7

yum install -y wget gcc  gcc-c++   make  cmake bison  bison-devel  libaio-devel  perl file patch mlocate flex diffutils readline-devel libcap-devel glibc-devel glib2-devel autoconf automake libgcrypt* libtool* openssl openssl-devel ncurses ncurses-devel libxml2  libxml2-* libmcrypt* curl curl-devel zlib zlib-devel bzip2*  gd gd-devel libjpeg libjpeg-devel  libpng  libpng-devel  mcrypt freetype* gettext gettext-devel pcre pcre-devel

1、安装JDK

 卸载再带的JDK:rpm -qa|grep jdk

如果出现包名: rpm -e filename 

tar zxvf  jdk-7u71-linux-x64.tar.gz

mv jdk1.7.0_71  /usr/local/java

vim  /etc/profile

在最后面加上:

export JAVA_HOME=/usr/local/java
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH

退出   source /etc/profile

检测   java  -version

2、mysql5.6的安装

单装mysql5.6:(yum install gcc gcc-c++ kernel-devel ncurses-devel bison cmake)

groupadd mysql

useradd -g mysql -s  /sbin/nologin mysql

mkdir -p /usr/local/mysql        //创建mysql安装目录;
mkdir -p /usr/local/mysql/data   //创建mysql数据存放目录;

cd /usr/local/src

tar zxvf mysql-5.6.13.tar.gz

tar zxvf cmake-2.8.9.tar.gz

cd cmake-2.8.9

./bootstrap        make&&make install

cd ..

cd  mysql-5.6.13

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysqldata -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_TCP_PORT=3306 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_USER=mysql -DWITH_DEBUG=0

make&&make install

cp support-files/my-default.cnf  /etc/my.cnf      (mysql5.5与mysql5.6的默认配置文件不同 mysql5.5是my-medium.cnf)

cp support-files/mysql.server /etc/init.d/mysqld

chown -R mysql:mysql /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql/data

vim /etc/my.cnf

在[mysqld]下

user=mysql
datadir=/usr/local/mysql/data

basedir=/usr/local/mysql

//保存

cd /usr/local/mysql/

scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql

添加mysql到系统服务:

chmod 755 /etc/init.d/mysqld

chkconfig --add mysqld

chkconfig mysqld on

优化mysql命令调用:
vim /etc/profile
添加:
PATH=/usr/local/mysql/bin:$PATH

export PATH
:wq                                   //保存
source /etc/profile

启动mysql服务,并设置管理员账号密码
service mysqld start
mysqladmin -u root password '111111'

3、安装apache

首先安装apr与apr-util

<安装apr>

wget http://apache.fayea.com//apr/apr-1.5.2.tar.gz

tar -zxvf apr-1.5.2.tar.gz -C /usr/local/src/

cd /usr/local/src/apr-1.5.2/

./configure --prefix=/usr/local/apr

make&&make install

<安装apr-util>

wget http://apache.fayea.com//apr/apr-util-1.5.4.tar.gz

cd apr-util-1.5.4

 ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config

make&&make install

理不清依赖关系的,建议yum install -y httpdlamp的搭建

cd httpd-2.2.29

./configure --prefix=/usr/local/httpd  --sysconfdir=/etc/httpd --enable-rewrite --enable-ssl --enable-cgi --enable-expires=shared --enable-mods-shared --enable-mudules=most --enable-mods-shared=all --enable-deflate --enable-speling --enable-cache --enable-file-cache --enable-disk-cache --enable-mem-cache --enable-so --enable-rewrite=shared --enable-static-support --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre

make&&make install

服务优化:

cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd

vim /etc/init.d/httpd

# 在第二行下添加以下两行内容
 #chkconfig:345 85 15
 #description:Apache httpd
# wq!                               //保存文件并退出;
# chkconfig --add httpd              //添加到系统服务;
# chkconfig --level 235 httpd on    //设置系统级别为:235 为开机自启动

配置优化:

vim /etc/httpd/httpd.conf
找到:ServerName 80
ServerName 80    //取消掉注释符号,改为"ServerName localhost:80";

service httpd start

检测:netstat -lnp|grep 80

4、安装PHP

tar jxvf php-5.4.35.tar.bz2

cd php-5.4.35

./configure  --prefix=/usr/local/php --with-mysql=mysqlnd  --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-openssl --with-zlib --with-libxml-dir --enable-sockets --with-apxs2=/usr/local/httpd/bin/apxs  --with-mcrypt  --with-config-file-path=/etc  --with-config-file-scan-dir=/etc/php.d  --with-bz2  --with-gd  --with-mhash  --enable-gd-native-ttf  --with-iconv  --with-png-dir  --with-jpeg-dir  --with-gettext  --with-curl  --with-pear --with-freetype-dir  --enable-bcmath --enable-xml --enable-mbstring --enable-shmop --enable-soap  --enable-sysvsem  --enable-calendar --enable-zip --enable-ftp --enable-maintainer-zts

出现:configure: error: mcrypt.h not found. Please reinstall libmcrypt.

解决方法:

1、安装第三方yum源:wget http://www.atomicorp.com/installers/atomic
sh ./atomic

2、yum  install  php-mcrypt  libmcrypt  libmcrypt-devel

重新编译安装PHP

cp  /usr/local/src/php-5.4.35/php.ini-development  /etc/php.ini

vim  /etc/php.ini

找到如下内容,并修改
# ;default_charset = "UTF-8"      //取消掉注释符号";"将值设为"utf-8";
#  engine = On                    //将此选项的开关为 on ;
#  short_open_tag = on            //将此选项的开关为 on ,表示支持php标语;
# ;date.timezone = Asia/Shanghai  //取消掉注释符号";",将值设为"Asia/Shanghai"或"PRC";

make&&make install

5、lamp相关程序支持

编辑apache配置文件,让apache支持php解析

vim /etc/httpd/httpd.conf
首先查看是否有用支持php解析的模块
LoadModule php5_module        modules/libphp5.so
找到这行
AddType application/x-gzip .gz .tgz
添加这两行内容
AddType application/x-httpd-php .php
AddType application/x-httpd-php-sourece .phps
找到以下这句,在后面添加index.php 
DirectoryIndex index.html     //修改前
DirectoryIndex index.html index.php  //修改后

service httpd restart

 6、测试

编辑两个个测试页面
# vim /usr/local/httpd/htdocs/info.php  内容如下
<?php
 $conn=mysqli_connect('127.0.0.1','root','111111');
 if ($conn)
   echo "<h2>Success...</h2>";
 else
   echo "<h2>Failure...</h2>";
?>
<?php
phpinfo();
?>

 浏览器输入 http://ip/info.php   ,大功告成!

 7、顺便安装下redis、memcached扩展:

安装redis与其扩展:
下载:wget  https://github.com/nicolasff/phpredis/archive/2.2.4.tar.gz
tar zxvf  2.2.4.tar.gz
cd phpredis-2.2.4
/usr/local/php/bin/phpize   #用phpize生成configure配置文件
./configure --with-php-config=/usr/local/php/bin/php-config  #配置
make&&make install
安装完成之后,出现下面的安装路径
/usr/local/php/lib/php/extensions/no-debug-zts-20100525/
配置php支持
vim /etc/php.ini  #编辑配置文件,在最后一行添加以下内容
添加:
extension="redis.so"
wq!

安装memcached与其扩展

wget http://launchpadlibrarian.net/66527034/libmemcached-0.48.tar.gz

相关推荐