1 mysql二进制安装


1 准备二进制包

 mysql-5.6.21-linux-glibc2.5-x86_64.tar.gz

cd /usr/local/src

tar xf  mysql-5.6.21-linux-glibc2.5-x86_64.tar.gz

cd /usr/local/

ln -sv src/mysql-5.6.21-linux-glibc2.5-x86_64 mysql  

groupadd -r -g 306 mysql

useradd -g 306 -r -s /sbin/nologin  -u 306 mysql

mkdir -pv /data/mysql

chown -R mysql.mysql /data/mysql/

mkdir -pv /data/owbinlogbackup /data/mysql-tmpdir

chown -R mysql.mysql /data/owbinlogbackup/ /data/mysql-tmpdir/

cd /usr/local/mysql  && ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql

cp support-files/my-default.cnf /etc/my.cnf  (用上线的配置文件替换)

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

chmod 755 /etc/init.d/mysqld 

vim /etc/init.d/mysqld   #修改basedir=/usr/local/mysql 和datadir=/data/mysq

chkconfig --add mysqld

chkconfig mysqld on

/etc/init.d/mysqld start

将mysql 客户端命令加入环境变量

vim /etc/profile.d/mysql.sh

export PATH=$PATH:/usr/local/mysql/bin

source /etc/profile

设置root 密码

 mysqladmin -uroot password 'c110123'


测试成功sql常用的语句:

登入:myql -uroot -p

查看:show processlist;

show status;

show databases;

退出:quit

\! ls 执行shell命令

2 安装apache--httpd

准备好httpd的源码包:httpd-2.2.27.tar.gz

安装步骤:


tar -xf httpd-2.2.27.tar.gz

cd httpd-2.2.27

查看INSTALL文档

./configure --prefix=/usr/local/apache --with-included-apr  --enable-deflate=shared  --enable-expires=shared  --enable-rewrite=shared  --with-pcre 

make && make install

echo $?


常用命令:

/usr/local/apache/bin/apachectl -t 配置文件检查

/usr/local/apache/bin/apachectl start  启动

/usr/local/apache/bin/apachectl graceful 平缓启动

出现如下信息,基本无影响,可以修改vim /usr/local/apache/conf/httpd.conf  

#

#ServerName 

ServerName 

spacer.gif

测试:

ps -ef |grep httpd

curl -I localhost

页面路径默认在

[ htdocs]# pwd

/usr/local/apache/htdocs

访问成功的默认页面:

spacer.gif


3 安装php

准备包php-5.3.27.tar.gz

tar -xvf php-5.3.27.tar.gz

cd php-5.3.27


./configure   --prefix=/usr/local/php   --with-apxs2=/usr/local/apache/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   --prefix=/usr/local/php   --with-apxs2=/usr/local/apache/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  --enable-bcmath --with-mysqli --with-gettext

make && make install 


如果安装mysql和zabbix-server web 独立开俩的则红色标记的选项要安装不然安装zabbix-web的时候会报错

报错:

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

解决方法:

libmcrypt-2.5.8.tar

mcrypt-2.6.8.tar.gz

编译安装mcrypt

报错:

configure: error: *** libmcrypt was not found

解决方法:

[ htdocs]# find / -name libmcrypt 

/usr/local/lib/libmcrypt

编辑:

[ mcrypt-2.6.8]# cat /etc/ld.so.conf 

include ld.so.conf.d/*.conf

/usr/local/lib/libmcrypt

然后执行:

ldconfig 

php编译成功的显示:

spacer.gif

4 . apache支持php配置


vim /usr/local/apache/conf/httpd.conf 

增加 AddType application/x-httpd-php .php  

AddType application/x-httpd-php-source .phps

DirectoryIndex index.html  改为 DirectoryIndex index.html  index.php

/usr/local/apache/bin/apachectl -t  查看配置文件是否有误

/usr/local/apache/bin/apachectl start  启动httpd服务

/usr/local/php/bin/php 1.php   一定可以解析

 #拷贝php配置文件,把样板文件拷贝到php安装路径etc下

 cp php.ini-production /usr/local/php/etc/php.ini

编辑测试页:vim /usr/local/apache2/htdocs/1.php 

测试: curl localhost/1.php 

vim 1.php

<?php

echo "this is my php web";

?>


vim phpinfo.php

<?php

phpinfo();

?>


spacer.gif

5 . 测试php连接mysql

vim test_conn_mysql.php


<?php

     $conn=mysql_connect('localhost','root','PSAAWORD');

     if ($conn)

            echo "connect mysql Success.......";

      else

            echo "Failure.......";

?>


结果:

[ htdocs]# curl localhost/test_conn_mysql.php

connect mysql Success.......[ htdocs]# 

6. LAMP中的几个常用的技巧


查看版本环境,查看编译参数 查看加载模块

查看apache编译参数 cat /usr/local/apache2/build/config.nice

注意:查看nginx的编译参数/usr/local/nginx/bin/nginx -V

查看apache加载的模块 apachectl -M 

查看apache的版本和环境,工作模式 apachectl -V

测试apache配置文件是否正确  apachectl -t

更改配置文件后,重新加载apache  apachectl graceful 

查看mysql编译参数  cat /usr/local/mysql/bin/mysqlbug|grep configure 

查看php编译参数 php -i |head

查看php加载模块 php –m

查看php的版本和环境 /usr/local/php/bin/php -v

查看php.ini在哪里  php -i |grep 'Configuration File‘

查看extension_dir路径 /usr/local/php/bin/php -i |grep 'extension_dir'

动态模块放在 /usr/local/apache2/modules/目录下面


查看apache的工作模式:

[ ~]# /usr/local/apache/bin/apachectl -l | egrep "prefork|worker"

  prefork.c