2013年11月08日 11:38:48

Linux下MySQL、Apache、PHP源码安装全程实录(CentOS 6.4)

作者: 

本文记录了我自己配置LAMP的全过程,借此记录一下,同时希望能够帮助一下需要帮助的LINUX新人,跟我一起学习,一起进步。

MySQL安装全过程

  1. 源码包来自:http://distfiles.macports.org/mysql56/
  2. $cd ~/Download
  3. $wget http://distfiles.macports.org/mysql56/mysql-5.6.29.tar.gz
  4. $chmod +x mysql-5.6.29.tar.gz
  5. $tar zxvf mysql-5.6.29.tar.gz
  6. $cd mysql-5.6.29
  7. $su
  8. 输入密码:
  9. #./configure --prefix=/usr/local/mysql --with-extra-charsets=all --with-unix-socket-path=/usr/local/mysql/var/mysql.sock --with-named-curses-libs=/usr/lib/libncursesw.so
  10. #make
  11. 提示错误:exec: g++: not found
  12. 原因:缺少gcc-c++
  13. 解决:yum install gcc-c++
  14. #yum install gcc-c++
  15. #./configure --prefix=/usr/local/mysql --with-extra-charsets=all --with-unix-socket-path=/usr/local/mysql/var/mysql.sock --with-named-curses-libs=/usr/lib/libncursesw.so
  16. #make
  17. 提示错误:configure: error: No curses/termcap library found
  18. 原因:缺少ncurses-devel
  19. 解决:yum install ncurses-devel
  20. #yum install ncurses-devel
  21. #./configure --prefix=/usr/local/mysql --with-extra-charsets=all --with-unix-socket-path=/usr/local/mysql/var/mysql.sock --with-named-curses-libs=/usr/lib/libncursesw.so
  22. #make
  23. #make install
  24. `make install 假错`
  25. make[4]: Entering directory /mysql-test 运行到这句会有不动几分钟,等待就好。
  26. 安装成功结束
  27. 复制my.cnf
  28. #cp /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf
  29. 初始化数据库
  30. #cd /usr/local/mysql/
  31. #./bin/mysql_install_db
  32. 添加mysql用户组
  33. #groupadd mysql
  34. 添加mysql用户,位于mysql用户组
  35. #useradd -g mysql mysql
  36. mysql用户一个密码
  37. #passwd mysql
  38. mysql目录的拥有者设置成mysql
  39. #chown -R mysql:mysql *
  40. mysql启动拷贝到系统默认的目录下
  41. #cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysql
  42. 启动mysql服务
  43. #/etc/init.d/mysql start
  44. 创建root用户
  45. #/usr/local/mysql/bin/mysqladmin -u root password 123456
  46. 登陆mysql管理
  47. #./bin/mysql -uroot -p123456



Apache安装全过程

  1. CentOS会自带apache服务,自带apache可以使用service httpd start启动,
  2. 程序目录位于/var/www/html/下面,这里移除系统自带Apache
  3. #rpm -e httpd
  4. 提示gnome-user-share依赖
  5. 下面忽略依赖删除Apache
  6. #rpm -e --nodeps httpd
  7. 源码包来自:
  8. http://www.apache.org/底部
  9. HTTP Server (http://httpd.apache.org/)
  10. #exit
  11. $cd ~/Download
  12. $wget http://mirrors.hust.edu.cn/apache/httpd/httpd-2.2.25.tar.gz
  13. $tar zxvf httpd-2.2.25.tar.gz
  14. $cd httpd-2.2.25
  15. $su
  16. 输入密码:
  17. #./configure --prefix=/usr/local/apache --enable-track-vars --enable-cgi --with-config-file-path=/usr/local/apache/conf --enable-so --enable-rewrite --enable-proxy --enable-ssl
  18. 提示错误:configure: error: ...No recognized SSL/TLS toolkit detected
  19. 原因:确实SSL
  20. 解决:yum -y install openssl openssl-devel
  21. #yum -y install openssl openssl-devel
  22. #./configure --prefix=/usr/local/apache --enable-track-vars --enable-cgi --with-config-file-path=/usr/local/apache/conf --enable-so --enable-rewrite --enable-proxy --enable-ssl
  23. #make
  24. #make install
  25. 安装完成
  26. 启动Apache服务器
  27. #/usr/local/apache/bin/apachectl start
  28. 浏览器访问http://localhost可以看到“It Works!”
  29. 程序目录为:/usr/local/apache/htdocs/
  30. 创建service httpd start启动
  31. #cp /usr/local/apache/bin/apachectl /etc/init.d/httpd



PHP安装全过程

  1. 源码包来自http://php.net/downloads.php
  2. $cd ~/Download
  3. $wget http://us1.php.net/get/php-5.3.27.tar.gz/from/cn2.php.net/mirror
  4. $tar zxvf php-5.3.27.tar.gz
  5. $cd php-5.3.27
  6. $su
  7. 输入密码:
  8. #./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql/ --with-apxs2=/usr/local/apache/bin/apxs --enable-track-vars --enable-force-cgi-redirect --with-config-file-path=/usr/local/php/etc --with-curl --with-mcrypt=/usr/local/libmcrypt/ --with-mbstring --with-incov --with-gd --with-jpeg-dir=/usr/local/lib --enable-pdo --enable-ssl
  9. 提示错误:configure: error: xml2-config not found. Please check your libxml2 installation.
  10. 原因:缺少libxml2-devel
  11. 解决:yum install libxml2-devel
  12. #yum install libxml2-devel
  13. #./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql/ --with-apxs2=/usr/local/apache/bin/apxs --enable-track-vars --enable-force-cgi-redirect --with-config-file-path=/usr/local/php/etc --with-curl --with-mcrypt=/usr/local/libmcrypt/ --with-mbstring --with-incov --with-gd --with-jpeg-dir=/usr/local/lib --enable-pdo --enable-ssl
  14. 提示错误:configure: error: Please reinstall the libcurl distribution -
  15. easy.h should be in /include/curl/
  16. 原因:curl-devel没安装
  17. 解决:yum install curl-devel
  18. #yum install curl-devel
  19. #./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql/ --with-apxs2=/usr/local/apache/bin/apxs --enable-track-vars --enable-force-cgi-redirect --with-config-file-path=/usr/local/php/etc --with-curl --with-mcrypt=/usr/local/libmcrypt/ --with-mbstring --with-incov --with-gd --with-jpeg-dir=/usr/local/lib --enable-pdo --enable-ssl
  20. 错误:configure: error: jpeglib.h not found.
  21. 解决:yum install libjpeg-devel libpng-devel
  22. #yum install libjpeg-devel libpng-devel
  23. #./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql/ --with-apxs2=/usr/local/apache/bin/apxs --enable-track-vars --enable-force-cgi-redirect --with-config-file-path=/usr/local/php/etc --with-curl --with-mcrypt=/usr/local/libmcrypt/ --with-mbstring --with-incov --with-gd --with-jpeg-dir=/usr/local/lib --with-png-dir=/usr/local/lib --enable-pdo --enable-ssl
  24. 错误:configure: error: mcrypt.h not found. Please reinstall libmcrypt.
  25. 解决:CentOS使用yun install libmcrypt安装提示没包,因此需要下载libmcrypt源码包,手动安装
  26. 项目地址:http://sourceforge.net/projects/mcrypt/files/Libmcrypt/
  27. 回到Download目录
  28. #cd ..
  29. #wget http://jaist.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
  30. #tar zxvf libmcrypt-2.5.8.tar.gz
  31. #cd libmcrypt-2.5.8
  32. #./configure --prefix=/usr/local/libmcrypt
  33. #make
  34. #make install
  35. 重新进入php目录
  36. #cd ../php-5.3.27
  37. #./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql/ --with-apxs2=/usr/local/apache/bin/apxs --enable-track-vars --enable-force-cgi-redirect --with-config-file-path=/usr/local/php/etc --with-curl --with-mcrypt=/usr/local/libmcrypt/ --with-mbstring --with-incov --with-gd --with-jpeg-dir=/usr/local/lib --with-png-dir=/usr/local/lib --enable-pdo --enable-ssl
  38. #make
  39. #make install
  40. #cp php.ini-development /usr/local/php/lib/php.ini
  41. #vi /usr/local/apache/conf/httpd.conf
  42. 1、在最后加入(:$(冒号$)可以跳到文件最后一行):
  43. AddType application/x-httpd-php .php
  44. 2、修改文件访问顺序(Line 168):
  45. DirectoryIndex index.php index.html
  46. 提示:vi +168 /usr/local/apache/conf/httpd.conf 可以打开文件,并且指针停留在168行,:set nu(冒号set nu)可以显示行号。
  47. 安装成功Apache已经启动了服务器,现在关闭,然后重新启动,使用restart我遇见了php依然没识别的问题,所以最好用stop停止再启动
  48. #/usr/local/apache/bin/apachectl stop
  49. #/usr/local/apache/bin/apachectl start
  50. 创建第一PHP文件
  51. #vi /usr/local/apache/htdocs/index.php
  52. <?php
  53. phpinfo();
  54. ?>
  55. 在浏览器访问http://localhost 会看到phpinfo输出的信息,证明php成功解析。
  56. PHP解析成功后还需要测试PHPMySQL数据库连通情况
  57. 前面没有启动mysql则使用 /etc/init.d/mysql start启动服务器
  58. #/etc/init.d/mysql start
  59. #/usr/local/mysql/bin/mysql -uroot -p123456
  60. mysql>show databases;
  61. mysql>use test;
  62. mysql>CREATE TABLE tb_test(
  63. >id int(11) auto_increment not null,
  64. >name varchar(255) not null,
  65. >PRIMARY KEY(id)
  66. >);
  67. mysql>INSERT INTO tb_test(name) VALUES('hzg'),('Zjmainstay');
  68. mysql>SELECT * FROM tb_test;
  69. 确认数据库表tb_test有两行数据即可。
  70. 创建PHP测试程序db_test.php
  71. #vi /usr/local/apache/htdocs/db_test.php
  72. <?php
  73. $db = mysql_connect("localhost","root","123456") or die("Can not connect database!");
  74. mysql_select_db("test", $db) or die("Can not select database!");
  75. mysql_query("set names utf8", $db) or die("Can not set names!");
  76. $sql = "SELECT * FROM tb_test";
  77. $res = mysql_query($sql, $db);
  78. if(!$res){
  79. die("Query error" . mysql_error($db));
  80. }else {
  81. $format = 'Id=%s, Name=%s<br />';
  82. while($row = mysql_fetch_assoc($res)){
  83. echo sprintf($format, $row['id'], $row['name']);
  84. }
  85. }
  86. ?>
  87. 保存,并在浏览器端执行http://localhost/db_test.php
  88. 提示错误:Can not connect to local MySQL server through socket '/usr/local/mysql/var/mysql.sock'
  89. localhost改成127.0.0.1后运行正常
  90. 原因:var目录没权限,无法写入mysql.sock
  91. 解决:chmod 0755 /usr/local/mysql/var/
  92. #ls /usr/local/mysql/var/
  93. 打印结果为空
  94. 授权0755
  95. #chmod 0755 /usr/local/mysql/var/
  96. 授权成功重启服务
  97. #/etc/init.d/mysql restart
  98. 再次查看var目录
  99. #ls /usr/local/mysql/var/
  100. 可以看到此时有数据了,而且有mysql.sock
  101. 再次运行localhost为服务器的db_test.php程序,执行成功。

LAMP源码安装完成,Enjoy It.

过程可能碰到的其他问题(我第一次安装时碰到,第二次安装时又没了)

  1. 错误:erroDIr: redeclaration of C++ built-in type bool
  2. 原因:gcc-c++在configure后面安装
  3. 解决:重新configure,make
  4. 错误:make: *** [libphp5.la] Error 1
  5. 解决:yum install libtool libtool-ltdl-devel
  6. 错误:undefined symbol: zend_parse_parameters
  7. 解决:yum install bison //bison 是替代yacc的语法分析程序生成器


未经同意禁止转载!
转载请附带本文原文地址:Linux下MySQL、Apache、PHP源码安装全程实录(CentOS 6.4),首发自 Zjmainstay学习笔记
阅读( 12032 )
看完顺手点个赞呗:
(2 votes)

1.PHP cURL群:PHP cURL高级技术
2.正则表达式群:专精正则表达式
3. QQ联系(加请说明):QQ联系博主(951086941)
4. 邮箱:zjmainstay@163.com
5. 打赏博主:

网站总访问量: