search
HomeDatabaseMysql Tutorial记一次痛苦的过程-------源码编译安装apache+php5+mysql_MySQL

当时有我们准备做一个项目,于是我就自己搭建了lamp服务器,直接yum install所有文件,因为centos是一个比较稳重的系统,所以它上面所有软件都不是最新的,apache是2.2.15版本,php是5.3.3,mysql是5.1.69.结果发现页面提示错误,提示什么内容我忘了,反正放到本地就没有任何问题,后来发现是由于thinkphp框架的原因,有些语法不支持php5.4以下,于是决定升级php,于是痛苦的过程开始了!!!!

刚开始想到的方法是换源,给centos换源,服务器用的是6.3版本,先换了163的源,后来又换了中科大的源,发现都一样,yum info php都是5.3.3,后来决定源码安装php,但是后来发现编译的时候必须加上apache和mysql的安装目录,因为是yum安装的apache和mysql,没办法添加目录,所以决定全部重新编译!!!好,先下源码!

卸载yum或rpm安装的amp软件
在编译安装lamp之前,首先先卸载已存在的rpm包吧。
rpm -e httpd
rpm -e mysql
rpm -e php
yum -y remove httpd
yum -y remove php
yum -y remove mysql-server mysql
yum -y remove php-mysql
禁用SeLinux
selinux可能会致使编译安装失败,我们先禁用它。
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config //永久禁用,需要重启生效
setenforce 0 //临时禁用,不需要重启
yum安装必要工具
1、安装编译工具gcc gcc-c++make automake autoconf kernel-devel
2、安装PHP所需依赖,如libxml2-devel openssl-devel curl-devel libjpeg-devel libpng-devel等
yum -y install gcc gcc-c++ make automake autoconf kernel-devel ncurses-devel libxml2-devel openssl-devel curl-devel libjpeg-devel libpng-devel pcre-devel libtool-libs freetype-devel gd zlib-devel file bison patch mlocate flex diffutils readline-devel glibc-devel glib2-devel bzip2-devel gettext-devel libcap-devel libmcrypt-devel
下载所需源码
apache:http://httpd.apache.org/
mysql:http://mysql.com/downloads/mysql/
php:http://php.net/downloads.php
phpmyadmin:http://www.phpmyadmin.net/home_page/downloads.php
我们这里选择的版本为:apache-2.2.22,mysql-5.1.62,php-5.2.17,phpmyadmin-3.4.10.2
cd /tmp
wget -c http://apache.ziply.com//httpd/httpd-2.2.22.tar.gz
wget -c http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.64.tar.gz/from/http://mysql.he.net/
wget -c http://us2.php.net/get/php-5.2.17.tar.gz/from/am.php.net/mirror
wget -c http://iweb.dl.sourceforge.net/project/phpmyadmin/phpMyAdmin/3.4.10.2/phpMyAdmin-3.4.10.2-all-languages.tar.gz
tar xzf httpd-2.2.22.tar.gz
tar xzf mysql-5.1.62.tar.gz
tar xzf php-5.2.17.tar.gz
tar xzf phpMyAdmin-3.4.10.2-all-languages.tar.gz
安装apache2.2.22
cd /tmp/httpd-2.2.22
./configure --prefix=/usr/local/apache --with-included-apr --enable-so --enable-deflate=shared --enable-expires=shared --enable-headers=shared --enable-rewrite=shared --enable-static-support
make
make install
编译参数解释:
--prefix=/usr/local/apache:指定安装目录
--with-included-apr:在编译时强制使用当前源代码中绑定的APR版本
--enable-so:允许运行时加载DSO模块
--enable-deflate=shared:将deflate模块编译为DSO
--enable-expires=shared:将expires模块编译为DSO
--enable-headers=shared:将headers模块编译为DSO
--enable-rewrite=shared:将rewrite模块编译为DSO
--enable-static-support:使用静态连接(默认为动态连接)编译所有二进制支持程序
更详细的编译参数解释:http://lamp.linux.gov.cn/Apache/ApacheMenu/programs/configure.html
cp build/rpm/httpd.init /etc/init.d/httpd //使用init脚本管理httpd
chmod 755 /etc/init.d/httpd //增加执行权限
chkconfig --add httpd //添加httpd到服务项
chkconfig httpd on //设置开机启动
ln -fs /usr/local/apache/ /etc/httpd
ln -fs /usr/local/apache/bin/httpd /usr/sbin/httpd
ln -fs /usr/local/apache/bin/apachectl /usr/sbin/apachectl
ln -fs /usr/local/apache/logs /var/log/httpd //设置软链接以适应init脚本
安装mysql5.1.62
groupadd mysql
useradd -g mysql mysql
cd /tmp/mysql-5.1.62
./configure --prefix=/usr/local/mysql/ --localstatedir=/usr/local/mysql/data --without-debug --with-unix-socket-path=/tmp/mysql.sock --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --enable-assembler --with-extra-charsets=gbk,gb2312,utf8 --with-pthread
make
make install //注意:这里是参考别人的,个人安装时候因为mysql版本过高,不支持make编译,必须用到cmake,可以直接yum install cmake安装
编译参数解释:
--prefix=/usr/local/mysql/:指定安装位置
--localstatedir=/usr/local/mysql/data:指定数据库文件位置
--without-debug:禁用调用模式
--with-unix-socket-path=/tmp/mysql.sock:指定sock文件位置
--with-client-ldflags=-all-static:
--with-mysqld-ldflags=-all-static:以纯静态方式编译服务端和客户端
--enable-assembler:使用一些字符函数的汇编版本
--with-extra-charsets=gbk,gb2312,utf8 :gbk,gb2312,utf8字符支持
--with-pthread:强制使用pthread库(posix线程库)
更多编译参数请执行./configure --help命令查看。
cp support-files/my-medium.cnf /etc/my.cnf //复制配置文件夹my.cnf
/usr/local/mysql/bin/mysql_install_db --user=mysql //初始化数据库
chown -R root.mysql /usr/local/mysql
chown -R mysql /usr/local/mysql/data
cp /tmp/mysql-5.1.62/support-files/mysql.server /etc/rc.d/init.d/mysqld //init启动脚本
chown root.root /etc/rc.d/init.d/mysqld
chmod 755 /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
ln -s /usr/local/mysql/bin/mysql /usr/bin
ln -s /usr/local/mysql/bin/mysqladmin /usr/bin
service mysqld start
/usr/local/mysql/bin/mysqladmin -u root password '新密码' //设置root密码
安装PHP5.2.17
在编译php之前,先要解决两个问题:centos 6上libmcrypt的安装和可能有些系统找不到libiconv导致的错误。
1、centos 6官方源已经没有libmcrypt的rpm包,我们这里选择编译安装,当然你也可以导入第三方源安装(centos 5略过此步)。
下载源码:
cd /tmp
wget http://superb-dca2.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
wget http://superb-dca2.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz
wget http://superb-sea2.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz
tar xzf libmcrypt-2.5.8.tar.gz
tar xzf mhash-0.9.9.9.tar.gz
tar xzf mcrypt-2.6.8.tar.gz
//安装libmcrypt
cd /tmp/libmcrypt-2.5.8
./configure --prefix=/usr
make && make install
//安装libmcrypt
cd /tmp/mhash-0.9.9.9
./configure --prefix=/usr
make && make install
//安装mcrypt
/sbin/ldconfig //搜索出可共享的动态链接库
cd /tmp/mcrypt-2.6.8
./configure
make && make install
2、解决可能出现的libiconv错误。
cd /tmp
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
tar xzf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local/libiconv
make && make install
开始安装php-5.2.17:
cd /tmp/php-5.2.17
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-openssl --with-zlib --enable-bcmath --with-bz2 --with-curl --enable-ftp --with-gd --enable-gd-native-ttf --with-gettext --with-mhash --enable-mbstring --with-mcrypt --enable-soap --enable-zip --with-iconv=/usr/local/libiconv --with-mysql=/usr/local/mysql --without-pear
make
make install
编译参数解释:
--prefix=/usr/local/php:设置安装路径
--with-apxs2=/usr/local/apache/bin/apxs:编译共享的 Apache 2.0 模块
--with-config-file-path=/etc:指定配置文件php.ini地址
--with-config-file-scan-dir=/etc/php.d:指定额外的ini文件目录
--with-openssl:编译OpenSSL支持
--with-zlib:编译zlib支持
--enable-bcmath:启用BC风格精度数学函数
--with-bz2:BZip2支持
--with-curl:CRUL支持
--enable-ftp:FTP支持
--with-gd:GD支持
--enable-gd-native-ttf:启用TrueType字符串函数
--with-gettext:启用GNU gettext支持
--with-mhash:mhash支持
--enable-mbstring:启用支持多字节字符串
--with-mcrypt:编译mcrypt加密支持
--enable-soap:SOAP支持
--enable-zip:启用zip 读/写支持
--with-iconv=/usr/local/libiconv:iconv支持
--with-mysql=/usr/local/mysql:启用mysql支持
--without-pear:不安装PEAR
更多编译参数解释参考http://www.php.net/manual/zh/configure.about.php或者./configure --help查看。
cp php.ini-dist /usr/local/php/etc/php.ini //复制配置文件php.ini
在/etc/httpd/conf/httpd.conf文件中加入php文件类型解析:
Addtype application/x-httpd-php .php
重启httpd:
service httpd restart

后来发现还是不行,提示系统不支持pdo,还有各种问题,最后又在网上找到了yum安装php5.4的方法,又决定重装系统yum安装,好了,重装系统!!!!

此处省略半天...................................................................................................................................................................................

装好之后,先yum install apache mysql mysql-server mysql-devel

重点来了!!!!

使用 Webtatic EL6的YUM源来安装php5.4,

rpm -Uvh http://repo.webtatic.com/yum/el6/latest.rpm

yum install php54w

如果安装失败,先卸载以前的php

这样肯定不行,它会提示could not find driver

因为thinkphp里有用到pdo连接数据库,所以必须安装pdo模块!

我是自己又安装了php54w-mysql php54w-odbc php54w-pdo

每个人情况不一样,你们酌情安装!

 

附带的php扩展列表:
Package Provides
php54w mod_php
php54w-bcmath  
php54w-cli php-cgi, php-pcntl, php-readline
php54w-common php-api, php-bz2, php-calendar, php-ctype, php-curl, php-date, php-exif, php-fileinfo, php-ftp, php-gettext, php-gmp, php-hash, php-iconv, php-json, php-libxml, php-openssl, php-pcre, php-pecl-Fileinfo, php-pecl-phar, php-pecl-zip, php-reflection, php-session, php-shmop, php-simplexml, php-sockets, php-spl, php-tokenizer, php-zend-abi, php-zip, php-zlib
php54w-dba  
php54w-devel  
php54w-embedded php-embedded-devel
php54w-enchant  
php54w-fpm  
php54w-gd  
php54w-imap  
php54w-interbase php_database, php-firebird
php54w-intl  
php54w-ldap  
php54w-mbstring  
php54w-mcrypt  
php54w-mssql  
php54w-mysql php-mysqli, php_database
php54w-odbc php-pdo_odbc, php_database
php54w-pdo  
php54w-pgsql php-pdo_pgsql, php_database
php54w-process php-posix, php-sysvmsg, php-sysvsem, php-sysvshm
php54w-pspell  
php54w-recode  
php54w-snmp  
php54w-soap  
php54w-tidy  
php54w-xml php-dom, php-domxml, php-wddx, php-xsl
php54w-xmlrpc  
php54w-zts  

最后还是出了问题!!!提示

SQLSTATE[HY000] [2019] Can't initialize character set UTF-8

在这儿卡了好久,查了好多都,最后一个大牛过来,不到两分钟解决了问题,原因是在Thinkphp的配置文件上,连接数据库的时候字符集设置为UTF-8,在这把UTF-8改为UTF8就ok了!!!!这困扰了我一周的问题就被大牛秒了!!!大牛我膜拜你!!!顺便说一下,这个配置文件是在Index/conf/config.php,当初因为对thinkphp框架不熟悉,导致找这个文件找了好久!!!现在把我的痛苦经历写出来以免大家走弯路!!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
MySQL's Role: Databases in Web ApplicationsMySQL's Role: Databases in Web ApplicationsApr 17, 2025 am 12:23 AM

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

MySQL: Building Your First DatabaseMySQL: Building Your First DatabaseApr 17, 2025 am 12:22 AM

The steps to build a MySQL database include: 1. Create a database and table, 2. Insert data, and 3. Conduct queries. First, use the CREATEDATABASE and CREATETABLE statements to create the database and table, then use the INSERTINTO statement to insert the data, and finally use the SELECT statement to query the data.

MySQL: A Beginner-Friendly Approach to Data StorageMySQL: A Beginner-Friendly Approach to Data StorageApr 17, 2025 am 12:21 AM

MySQL is suitable for beginners because it is easy to use and powerful. 1.MySQL is a relational database, and uses SQL for CRUD operations. 2. It is simple to install and requires the root user password to be configured. 3. Use INSERT, UPDATE, DELETE, and SELECT to perform data operations. 4. ORDERBY, WHERE and JOIN can be used for complex queries. 5. Debugging requires checking the syntax and use EXPLAIN to analyze the query. 6. Optimization suggestions include using indexes, choosing the right data type and good programming habits.

Is MySQL Beginner-Friendly? Assessing the Learning CurveIs MySQL Beginner-Friendly? Assessing the Learning CurveApr 17, 2025 am 12:19 AM

MySQL is suitable for beginners because: 1) easy to install and configure, 2) rich learning resources, 3) intuitive SQL syntax, 4) powerful tool support. Nevertheless, beginners need to overcome challenges such as database design, query optimization, security management, and data backup.

Is SQL a Programming Language? Clarifying the TerminologyIs SQL a Programming Language? Clarifying the TerminologyApr 17, 2025 am 12:17 AM

Yes,SQLisaprogramminglanguagespecializedfordatamanagement.1)It'sdeclarative,focusingonwhattoachieveratherthanhow.2)SQLisessentialforquerying,inserting,updating,anddeletingdatainrelationaldatabases.3)Whileuser-friendly,itrequiresoptimizationtoavoidper

Explain the ACID properties (Atomicity, Consistency, Isolation, Durability).Explain the ACID properties (Atomicity, Consistency, Isolation, Durability).Apr 16, 2025 am 12:20 AM

ACID attributes include atomicity, consistency, isolation and durability, and are the cornerstone of database design. 1. Atomicity ensures that the transaction is either completely successful or completely failed. 2. Consistency ensures that the database remains consistent before and after a transaction. 3. Isolation ensures that transactions do not interfere with each other. 4. Persistence ensures that data is permanently saved after transaction submission.

MySQL: Database Management System vs. Programming LanguageMySQL: Database Management System vs. Programming LanguageApr 16, 2025 am 12:19 AM

MySQL is not only a database management system (DBMS) but also closely related to programming languages. 1) As a DBMS, MySQL is used to store, organize and retrieve data, and optimizing indexes can improve query performance. 2) Combining SQL with programming languages, embedded in Python, using ORM tools such as SQLAlchemy can simplify operations. 3) Performance optimization includes indexing, querying, caching, library and table division and transaction management.

MySQL: Managing Data with SQL CommandsMySQL: Managing Data with SQL CommandsApr 16, 2025 am 12:19 AM

MySQL uses SQL commands to manage data. 1. Basic commands include SELECT, INSERT, UPDATE and DELETE. 2. Advanced usage involves JOIN, subquery and aggregate functions. 3. Common errors include syntax, logic and performance issues. 4. Optimization tips include using indexes, avoiding SELECT* and using LIMIT.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software