MySQL安装全过程
源码包来自:http://distfiles.macports.org/mysql56/$cd ~/Download$wget http://distfiles.macports.org/mysql56/mysql-5.6.29.tar.gz$chmod +x mysql-5.6.29.tar.gz$tar zxvf mysql-5.6.29.tar.gz$cd mysql-5.6.29$su输入密码:#./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#make提示错误:exec: g++: not found原因:缺少gcc-c++解决:yum install gcc-c++#yum install gcc-c++#./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#make提示错误:configure: error: No curses/termcap library found原因:缺少ncurses-devel解决:yum install ncurses-devel#yum install ncurses-devel#./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#make#make install`make install 假错`make[4]: Entering directory /mysql-test 运行到这句会有不动几分钟,等待就好。安装成功结束复制my.cnf#cp /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf初始化数据库#cd /usr/local/mysql/#./bin/mysql_install_db添加mysql用户组#groupadd mysql添加mysql用户,位于mysql用户组#useradd -g mysql mysql给mysql用户一个密码#passwd mysql把mysql目录的拥有者设置成mysql#chown -R mysql:mysql *把mysql启动拷贝到系统默认的目录下#cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysql启动mysql服务#/etc/init.d/mysql start创建root用户#/usr/local/mysql/bin/mysqladmin -u root password 123456登陆mysql管理#./bin/mysql -uroot -p123456
Apache安装全过程
CentOS会自带apache服务,自带apache可以使用service httpd start启动,程序目录位于/var/www/html/下面,这里移除系统自带Apache#rpm -e httpd提示gnome-user-share依赖下面忽略依赖删除Apache#rpm -e --nodeps httpd源码包来自:http://www.apache.org/底部HTTP Server (http://httpd.apache.org/)#exit$cd ~/Download$wget http://mirrors.hust.edu.cn/apache/httpd/httpd-2.2.25.tar.gz$tar zxvf httpd-2.2.25.tar.gz$cd httpd-2.2.25$su输入密码:#./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提示错误:configure: error: ...No recognized SSL/TLS toolkit detected原因:确实SSL解决:yum -y install openssl openssl-devel#yum -y install openssl openssl-devel#./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#make#make install安装完成启动Apache服务器#/usr/local/apache/bin/apachectl start浏览器访问http://localhost可以看到“It Works!”程序目录为:/usr/local/apache/htdocs/创建service httpd start启动#cp /usr/local/apache/bin/apachectl /etc/init.d/httpd
PHP安装全过程
源码包来自http://php.net/downloads.php$cd ~/Download$wget http://us1.php.net/get/php-5.3.27.tar.gz/from/cn2.php.net/mirror$tar zxvf php-5.3.27.tar.gz$cd php-5.3.27$su输入密码:#./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提示错误:configure: error: xml2-config not found. Please check your libxml2 installation.原因:缺少libxml2-devel解决:yum install libxml2-devel#yum install libxml2-devel#./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提示错误:configure: error: Please reinstall the libcurl distribution -easy.h should be in /include/curl/原因:curl-devel没安装解决:yum install curl-devel#yum install curl-devel#./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错误:configure: error: jpeglib.h not found.解决:yum install libjpeg-devel libpng-devel#yum install libjpeg-devel libpng-devel#./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错误:configure: error: mcrypt.h not found. Please reinstall libmcrypt.解决:CentOS使用yun install libmcrypt安装提示没包,因此需要下载libmcrypt源码包,手动安装项目地址:http://sourceforge.net/projects/mcrypt/files/Libmcrypt/回到Download目录#cd ..#wget http://jaist.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz#tar zxvf libmcrypt-2.5.8.tar.gz#cd libmcrypt-2.5.8#./configure --prefix=/usr/local/libmcrypt#make#make install重新进入php目录#cd ../php-5.3.27#./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#make#make install#cp php.ini-development /usr/local/php/lib/php.ini#vi /usr/local/apache/conf/httpd.conf1、在最后加入(:$(冒号$)可以跳到文件最后一行):AddType application/x-httpd-php .php2、修改文件访问顺序(Line 168):DirectoryIndex index.php index.html提示:vi +168 /usr/local/apache/conf/httpd.conf 可以打开文件,并且指针停留在168行,:set nu(冒号set nu)可以显示行号。安装成功Apache已经启动了服务器,现在关闭,然后重新启动,使用restart我遇见了php依然没识别的问题,所以最好用stop停止再启动#/usr/local/apache/bin/apachectl stop#/usr/local/apache/bin/apachectl start创建第一PHP文件#vi /usr/local/apache/htdocs/index.php<?phpphpinfo();?>在浏览器访问http://localhost 会看到phpinfo输出的信息,证明php成功解析。PHP解析成功后还需要测试PHP和MySQL数据库连通情况前面没有启动mysql则使用 /etc/init.d/mysql start启动服务器#/etc/init.d/mysql start#/usr/local/mysql/bin/mysql -uroot -p123456mysql>show databases;mysql>use test;mysql>CREATE TABLE tb_test(>id int(11) auto_increment not null,>name varchar(255) not null,>PRIMARY KEY(id)>);mysql>INSERT INTO tb_test(name) VALUES('hzg'),('Zjmainstay');mysql>SELECT * FROM tb_test;确认数据库表tb_test有两行数据即可。创建PHP测试程序db_test.php#vi /usr/local/apache/htdocs/db_test.php<?php$db = mysql_connect("localhost","root","123456") or die("Can not connect database!");mysql_select_db("test", $db) or die("Can not select database!");mysql_query("set names utf8", $db) or die("Can not set names!");$sql = "SELECT * FROM tb_test";$res = mysql_query($sql, $db);if(!$res){die("Query error" . mysql_error($db));}else {$format = 'Id=%s, Name=%s<br />';while($row = mysql_fetch_assoc($res)){echo sprintf($format, $row['id'], $row['name']);}}?>保存,并在浏览器端执行http://localhost/db_test.php提示错误:Can not connect to local MySQL server through socket '/usr/local/mysql/var/mysql.sock'将localhost改成127.0.0.1后运行正常原因:var目录没权限,无法写入mysql.sock解决:chmod 0755 /usr/local/mysql/var/#ls /usr/local/mysql/var/打印结果为空授权0755#chmod 0755 /usr/local/mysql/var/授权成功重启服务#/etc/init.d/mysql restart再次查看var目录#ls /usr/local/mysql/var/可以看到此时有数据了,而且有mysql.sock再次运行localhost为服务器的db_test.php程序,执行成功。
LAMP源码安装完成,Enjoy It.
过程可能碰到的其他问题(我第一次安装时碰到,第二次安装时又没了)
错误:erroDIr: redeclaration of C++ built-in type ‘bool’原因:gcc-c++在configure后面安装解决:重新configure,make错误:make: *** [libphp5.la] Error 1解决:yum install libtool libtool-ltdl-devel错误:undefined symbol: zend_parse_parameters解决:yum install bison //bison 是替代yacc的语法分析程序生成器
未经同意禁止转载!
转载请附带本文原文地址:Linux下MySQL、Apache、PHP源码安装全程实录(CentOS 6.4),首发自 Zjmainstay学习笔记




