一.安装mysql
1.假设已经有mysql-5.5.10.tar.gz以及cmake-2.8.4.tar.gz两个源文件
(1)先安装cmake(mysql5.5以后是通过cmake来编译的)
sudo apt-get install cmake
[root@ rhel5 local]#tar -zxv -f cmake-2.8.4.tar.gz[root@ rhel5 local]#cd cmake-2.8.4[root@ rhel5 cmake-2.8.4]#./configure[root@ rhel5 cmake-2.8.4]#make[root@ rhel5 cmake-2.8.4]#make install
(2)创建mysql的安装目录及数据库存放目录
[root@ rhel5~]#mkdir -p /usr/local/mysql //安装mysql [root@ rhel5~]#mkdir -p /usr/local/mysql/data //存放数据库
(3)创建mysql用户及用户组
[root@ rhel5~]groupadd mysql[root@ rhel5~]useradd -r -g mysql mysql
(4)安装mysql
[root@ rhel5 local]#tar -zxv -f mysql-5.5.10.tar.gz[root@ rhel5 local]#cd mysql-5.5.10[root@ rhel5 mysql-5.5.10]#cmake . -DCMAKE_INSTALL_PREFIX=/home/pf/add/lamp/lamp/mysql -DMYSQL_DATADIR=/home/pf/add/lamp/lamp/mysql/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DENABLED_LOCAL_INFILE=1[root@ rhel5 mysql-5.5.10]#make[root@ rhel5 mysql-5.5.10]#make install参数说明:
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql //安装目录
-DINSTALL_DATADIR=/usr/local/mysql/data //数据库存放目录
-DDEFAULT_CHARSET=utf8 //使用utf8字符
-DDEFAULT_COLLATION=utf8_general_ci //校验字符
-DEXTRA_CHARSETS=all //安装所有扩展字符集
-DENABLED_LOCAL_INFILE=1 //允许从本地导入数据
注意事项:
重新编译时,需要清除旧的对象文件和缓存信息。
# make clean
# rm -f CMakeCache.txt
# rm -rf /etc/my.cnf
2.配置
(1)设置目录权限
[root@ rhel5~]# cd /usr/local/mysql[root@ rhel5 mysql]# chown -R root:mysql . //把当前目录中所有文件的所有者所有者设为root,所属组为mysql[root@ rhel5 mysql]# chown -R mysql:mysql data
(2)
[root@ rhel5 mysql]# cp support-files/my-medium.cnf /etc/my.cnf //将mysql的启动服务添加到系统服务中
(3)创建系统数据库的表
[root@ rhel5 mysql]# cd /usr/local/mysql[root@ rhel5 mysql]# scripts/mysql_install_db --user=mysql
COLLATION 'latin1_swedish_ci' is not valid for CHARACTER SET 'utf8'
待解决
解决办法:
./scripts/mysql_install_db --user=mysql --collation-server=utf8_general_ci
(4)设置环境变量
[root@ rhel5~]# vi /root/.bash_profile在PATH=$PATH:$HOME/bin添加参数为:PATH=$PATH:$HOME/bin:/usr/local/mysql/bin:/usr/local/mysql/lib[root@ rhel5~]#source /root/.bash_profile
(5)手动启动mysql
[root@ rhel5~]# cd /usr/local/mysql[root@ rhel5 mysql]# ./bin/mysqld_safe --user=mysql & //启动MySQL,但不能停止启动日志写在此文件下:/usr/local/mysql/data/localhost.err关闭MySQL服务[root@ rhel5 mysql]# mysqladmin -u root -p shutdown //这里MySQL的root用户还没有配置密码,所以为空值。需要输入密码时,直接点回车键即可。
(6)另一种简单的启动mysql的方法(mysql已经被添加到系统服务中)
[root@ rhel5~]# service mysql.server start [root@ rhel5~]# service mysql.server stop[root@ rhel5~]# service mysql.server restart如果上述命令出现:mysql.server 未识别的服务
则可能mysql还没添加到系统服务中,下面用另一种方法添加:
[root@ rhel5 mysql]# cp support-files/mysql.server /etc/init.d/mysql //将mysql的启动服务添加到系统服务中注意:主要是将mysql.server拷贝到/etc/init.d中,命名为mysql。在有的系统中,mysql.server在/usr/local/mysql/share/mysql/mysql.server中,而本系统中,mysql.server在/usr/local/mysql/support-files/mysql.server中。
然后再用#service mysql start 来启动mysql即可。
(7)修改MySQL的root用户的密码以及打开远程连接
[root@ rhel5~]# mysql -u root mysqlmysql>use mysql;mysql>desc user;mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root"; //为root添加远程连接的能力。mysql>update user set Password = password('xxxxxx') where User='root';mysql>select Host,User,Password from user where User='root'; mysql>flush privileges;mysql>exit重新登录:mysql -u root -p若还不能进行远程连接,则关闭防火墙[root@ rhel5~]# /etc/rc.d/init.d/iptables stop注:如果不能远程连接,出现错误mysql error number 1130,则加入下面语句试试:
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '******' WITH GRANT OPTION;
二.安装GD库
a.安装 jpeg6 建立目录:
# mkdir -p /usr/local/jpeg6
# mkdir -p /usr/local/jpeg6
# mkdir -p /usr/local/jpeg6/bin
# mkdir -p /usr/local/jpeg6/lib
# mkdir -p /usr/local/jpeg6/include
# mkdir -p /usr/local/jpeg6/man
# mkdir -p /usr/local/jpeg6/man1
# mkdir -p /usr/local/jpeg6/man/man1
# tar -zvxf jpegsrc.v6b.tar.gz
# cd jpeg6
# ./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static
# make
# make install
b.libpng包(支持PNG)
# cd /root/Software/
# tar -zvxf libpng-(version).tar.gz
# cd libpng-(version)
# ./configure --prefix=/usr/local/libpng
# make
#> make install
c.安装 freetype
# cd /root/Software/
# tar -zvxf freetype-(version).tar.gz
# cd freetype-(version)
# mkdir -p /usr/local/freetype
# ./configure --prefix=/usr/local/freetype
# make
# make install
d.安装zlib
# cd /root/Software/
# tar -zxvf zlib-1.2.3.tar.gz
# cd zlib.1.2.3
# mkdir /usr/local/zlib
# ./configure --prefix=/usr/local/zlib
# make
# make install
e.安装GD库
# cd /root/Software/
# tar -zvxf gd-(version).tar.gz
# mkdir -p /usr/local/gd2
# cd gd-(version)
# ./configure --prefix=/usr/local/gd2 --with-jpeg=/usr/local/jpeg6 --with-zlib-dir=/usr/local/zlib --with-png=/usr/local/libpng --with-freetype=/usr/local/freetype
# make
# make install
e.安装Curl库
# cd /root/Software/
# tar -zxf curl-(version).tar.gz
# mkdir -p /usr/local/curl
# ./configure --prefix=/usr/local/curl
# make
# make install
三:安装apache2
# cd /roo/Software/
# tar -zvxf httpd-2.2.6.tar.gz
# cd httpd-2.2.6
# mkdir -p /usr/local/apache2
# ./configure --prefix=/usr/local/apache --enable-modules=so --enable-rewrite
# make
# make install
# /usr/local/apache2/bin/apachectl -k start //启动apahce
用浏览器查看[url]http://localhost[/url],得到it works,说明apache已经配置成功了.
# /usr/local/apache2/bin/apachectl -k stop //停止apache
提示configure: error: APR not found. Please read the documentation.
具体步骤如下:
1.解决apr not found问题——————>
[root@yahoo test]# tar -zxf apr-1.4.5.tar.gz
[root@yahoo apr-1.4.5]# ./configure --prefix=/usr/local/apr
[root@yahoo apr-1.4.5]# make
[root@yahoo apr-1.4.5]# make install
2.解决APR-util not found问题>>>>
[root@yahoo test]# tar -zxf apr-util-1.3.12.tar.gz
[root@yahoo apr-util-1.3.12]# ./configure --prefix=/usr/local/apr-util -with- apr=/usr/local/apr/bin/apr-1-config
[root@yahoo apr-util-1.3.12]# make
[root@yahoo apr-util-1.3.12]# make install
再次提示缺少pcre,下载之http://sourceforge.net/projects/pcre/ 编译 安装(我这里均安装在/root/soft目录里,例如./configure --prefix=/root/soft/pcre)
./configure --prefix=/root/soft/apache --with-apr=/root/soft/apr/ --with-apr-util=/root/soft/apr-util/ --with-pcre=/root/soft/pcre
./configure --prefix=/home/pf/add/lamp/lamp/apache --with-apr=/home/pf/add/lamp/lamp/apr --with-apr-util=/home/pf/add/lamp/lamp/apr-util --with-apr-pcre=/home/pf/add/lamp/lamp/pcre --enable-modles=so --enable-rewrite
3.编译Apache
[root@yahoo httpd-2.3.12-beta]# ./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/
[root@yahoo httpd-2.3.12-beta]# make
[root@yahoo httpd-2.3.12-beta]# make install
[root@yahoo httpd-2.3.12-beta]# /usr/local/apache2/bin/apachectl start
四:安装php5,php5必须有libxml2支持!
a. 安装libxml2
# cd /root/Software/
# tar -zvxf libxml2-(version).tar.gz
# cd libxml2-(version)
# mkdir -p /usr/local/libxml2
# ./configure --prefix=/usr/local/libxml2
# make
# make install
b.安装 libxslt (可选安装,你可以不安装)
# cd /root/Software/
# tar -zvxf libxslt-(version).tar.gz
# mkdir -p /usr/local/libxslt
# cd libxslt-(version)
# ./configure --prefix=/usr/local/libxslt --with-libxml-prefix=/usr/local/libxml2
# make
# make install
c.安装php5
# cd /root/Software/
# tar -zvxf php-(version).tar.gz
# mkdir -p /usr/local/php5
# cd php-(version)
# ./configure --prefix=/home/pf/add/lamp/lamp/php --with-apxs2=/home/pf/add/lamp/lamp/apache/bin/apxs --with-gd=/home/pf/add/lamp/lamp/gd --with-jpeg-dir=/home/pf/add/lamp/lamp/jpeg6 --with-zlib-dir=/home/pf/add/lamp/lamp/zlib --with-png-dir=/home/pf/add/lamp/lamp/libpng --with-freetype-dir=/home/pf/add/lamp/lamp/freetype --enable-trace-vars --with-mysql=/home/pf/add/lamp/lamp/mysql --enable-mbstring=all --with-curl=/home/pf/add/lamp/lamp/curl --enable-mbregex --with-config-file-path=/home/pf/add/lamp/lamp/php --enable-ftp --enable-soap --with-xsl=/home/pf/add/lamp/lamp/libxslt --with-libxml-dir=/home/pf/add/lamp/lamp/libxml
# make
# make install
# cp php.ini-development /usr/php/lib/php.ini (别忘记了呵呵)
安装php5.4时,php-5.4.0/ext/gd/gd_ctx.c:153: 错误:‘gdIOCtx’ 没有名为 ‘data’ 的成员
解决方法
vi <gd_dir>/include/gd_io.h
gdIOCtx结构中增加void *data;
六:重新配置apache2让他支持php
# cd /usr/local/apache2/conf
# vim httpd.conf
在LoadModule php5_module modules/libphp5.so
添加AddType application/x-httpd-php .php
OK,基本的安装已经完成.
重新起动APACHE:
# /usr/local/apache2/bin/apachectl start
如果重新起动APACHE出现:
Syntax error . line 232 of /usr/local/apache2/conf/httpd.conf: Cannot load /usr/local/apache2/modules/libphp5.so into server:
/usr/local/apache2/modules/libphp4.so: cannot restore segment prot after reloc: Permission denied
那就要按照下面的方法解决:
1.chcon -t texrel_shlib_t /usr/local/apache2/modules/*.so
2.编辑/etc/selinux/config,找到这段:
# This file controls the state of SELinux . the system.
# SELINUX= can take .e of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - SELinux is fully disabled.
SELINUX=enforcing
把 SELINUX=enforcing 注释掉:#SELINUX=enforcing ,然后新加一行为:
SELINUX=disabled
保存,关闭。
编辑/etc/sysconfig/selinux,找到:
# This file controls the state of SELinux . the system.
# SELINUX= can take .e of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - SELinux is fully disabled.
SELINUX=enforcing
如果SELINUX已经是 SELINUX=disabled,那么就不用改了,否则就把SELINUX=enforcing 注释掉,新加一行:
SELINUX=disabled
保存,退出。
(1)在默认的apache根目录创建文件/usr/local/apache/htdocs/test.php,其内容为:
[root@serv-169 htdocs]# cat test.php
<?php
PHPinfo();
?>
在其他计算机的浏览器地址栏输入http://IP/test.php,查看php所支持的模块加载情况。
启动数据库:
./bin/mysqld_safe --user=mysql &
mysqladmin -u root -p shutdown
/etc/init.d/mysql start
一) 连接MYSQL:
格式: mysql -h主机地址 -u用户名 -p用户密码
root 123456
pf hust
apache
/usr/local/apache2/bin/apachectl -k start
/usr/local/apache2/bin/apachectl -k stop
403错误
Require all granted