编译安装更轻量,不会像yum安装那么臃肿。
(一) 安装MYSQL:
一、安装简介
用户名:mysql
安装目录:/usr/local/mysql-5.5
数据库目录:/data/mysql/data
源码包:mysql-5.5.28.tar.gz
二、安装准备
添加用户
useradd -s /sbin/nologin mysql
建立所需目录
mkdir -p /data/mysql/data
chown -R mysql:mysql /data/mysql
安装编译所需文件或程序
yum install gcc gcc-c++ cmake ncurses-devel bison
下载源码包
http://sourceforge.net/projects/mysql.mirror/files/MySQL%205.5.28/
wget http://ncu.dl.sourceforge.net/project/mysql.mirror/MySQL%205.5.28/mysql-5.5.28.tar.gz
三、编译安装
cd
tar xzvf mysql-5.5.28.tar.gz
cd mysql-5.5.28
cmake -DMYSQL_USER=mysql -DCMAKE_INSTALL_PREFIX=/usr/local/mysql5.5 -DINSTALL_DATADIR=/data/mysql/data -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1
参数说明:
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql //安装目录
-DMYSQL_DATADIR=/usr/local/mysql/data //数据库存放目录
-DWITH_MYISAM_STORAGE_ENGINE=1 //安装myisam存储引擎
-DWITH_INNOBASE_STORAGE_ENGINE=1 //安装innodb存储引擎
-DWITH_ARCHIVE_STORAGE_ENGINE=1 //安装archive存储引擎
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 //安装blackhole存储引擎
-DENABLED_LOCAL_INFILE=1 //允许从本地导入数据
-DDEFAULT_CHARSET=utf8 //使用utf8字符
-DDEFAULT_COLLATION=utf8_general_ci //校验字符
-DEXTRA_CHARSETS=all //安装所有扩展字符集
-DMYSQL_TCP_PORT=3306 //MySQL监听端口
-DMYSQL_USER=mysql //MySQL用户名
其他参数:
-DWITH-EMBEDDED_SERVER=1 //编译成embedded MySQL library (libmysqld.a)
-DSYSCONFDIR=/etc //MySQL配辑文件
-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock //Unix socket 文件路径
-DWITH_READLINE=1 //快捷键功能
-DWITH_SSL=yes //SSL
-DWITH_MEMORY_STORAGE_ENGINE=1 //安装memory存储引擎
-DWITH_FEDERATED_STORAGE_ENGINE=1 //安装frderated存储引擎
-DWITH_PARTITION_STORAGE_ENGINE=1 //安装数据库分区
-DINSTALL_PLUGINDIR=/usr/local/mysql/plugin //插件文件及配置路径
make && make install
chown -R mysql:mysql /usr/local/mysql5.5/
mv /root/mysql-5.5.28/support-files/my-large.cnf /etc/my.cnf
mv /root/mysql-5.5.28/support-files/mysql.server /etc/init.d/mysqld
chmod a+x /etc/init.d/mysqld
开启启动
chkconfig --level 345 mysqld on
设置环境变量
echo "export PATH=/usr/local/mysql5.5/bin/:$PATH" >> /etc/profile
source /etc/profile
/usr/local/mysql5.5/scripts/mysql_install_db --user=mysql --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql5.5 --datadir=/data/mysql/data
vim /etc/my.cnf
basedir=/usr/local/mysql5.5
datadir=/data/mysql/data
创建mysql管理员
/usr/bin/mysqladmin -u root password 'z'
连接数据库:
mysql -u root -p -P port
(二) 编译安装Apache+PHP
1.安装程序依赖库和开发环境
为了省事把所需要的库文件全都安装上,可以使用rpm包安装,也可以用yum命令安装,
yum -y install gcc gcc-c++ autoconf automake make libjpeg libjpeg-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers libtool* mysql-devel
当APACHE 与MYSQL不是同一台机器上时:ln -s /usr/lib64/mysql/libmysqlclient.so.16.0.0 /usr/lib/libmysqlclient_r.so
2.部署apache
(1) 解包 tar zxvf httpd-2.2.22.tar.gz
(2) 切换目录 cd httpd-2.2.22
(3) 配置 ./configure --prefix=/usr/local/apache --enable-so --enable-proxy --enable-rewrite --with-mpm=worker
(4) 编译安装:make&&make install
检查模块是否安装上
3.Apache整合PHP
(1) 安装freetype
tar jxvf freetype-2.3.10.tar.bz2
cd freetype-2.3.10
./configure --prefix=/usr/local/freetype
make
make install
cd ..
(2) 安装jpeg
tar zxvf jpegsrc.v7.tar.gz
cd jpeg-7
./configure –prefix=/usr/local/jpeg
make
make install
cd ..
(3) 安装libpng
tar jxvf libpng-1.2.41.tar.bz2
cd libpng-1.2.41
./configure –prefix=/usr/local/libpng
make
make install
(4) 安装GD
① 链接头文件
ln -s /usr/local/libpng/include/pngconf.h /usr/include
ln –s /usr/local/libpng/include/png.h /usr/include
② 安装GD
tar zxvf gd-2.0.35.tar.gz
cd gd-2.0.35
./configure –prefix=/usr/local/gd2 \
--with-freetype=/usr/local/freetype –with-png=/usr/local/libpng \
--with-jpeg=/usr/local/jpeg
make
make install
cd ..
(5) 安装PHP
tar jxvf php-5.2.17.tar.bz2
cd php-5.2.17
./configure --prefix=/usr/local/php \
--with-gd=/usr/local/gd2 --with-apxs2=/usr/local/apache/bin/apxs \
--enable-mbregex --enable-bcmath \
--with-mysql --with-zlib-dir --enable-mbstring=all \
--with-pdo-mysql --with-freetype-dir=/usr/local/freetype --with-jpeg-dir=/usr/local/jpeg \
--with-openssl \
--with-curl
make
make install
cp php.ini-dist /usr/local/php/lib/php.ini
cd ..
(6) 修改apache配置文件
cd /usr/local/apache/
mkdir conf/
vim httpd.conf
在主配置文件<\IfModule>之间插入行&#xff1a;
AddType application/x-httpd-php .php
添加apache用户&#xff0c;修改User和Group为&#xff1a;
User apache
Group apache
ServerName localhost:80
Include conf.d/*.conf
(7) 检查
在默认的Apache根文档目录创建文件/usr/local/apache/htdocs/test.php,其内容为&#xff1a;
PHPinfo();
?>
检查是否有语法错误&#xff1a;/usr/local/apache/bin/apachectl –t
编写启动脚本httpd放在/etc/init.d下
启动apache&#xff1a;service httpd start
输入&#xff1a;http://apache-ip/test.php 查看php所支持的模块加载情况。
4虚拟目录&#xff1a;
vim /usr/local/apache/conf.d/vhost.conf
NameVirtualHost *:80
DocumentRoot /home/linuxops/www/
ServerName linuxops.com
&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;分割线&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;&#61;
安装APACHE时&#xff0c;一定要先检查安装操作系统时的有没有安装默认的APACHE&#xff0c;需要查找有&#xff0c;并卸载&#xff01;
rpm -qa | grep httpd
rpm -e httpd