一、安装mysql
cd /usr/local/src/ wget http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.40-linux-i686-icc-glibc23.tar.gz tar zxvf /usr/local/src/mysql-5.1.40-linux-i686-icc-glibc23.tar.gz mv mysql-5.1.40-linux-i686-icc-glibc23 /usr/local/mysql useradd -s /sbin/nologin mysql cd /usr/local/mysql mkdir -p /data/mysql chown -R mysql:mysql /data/mysql ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql cp support-files/my-large.cnf /etc/my.cnf cp support-files/mysql.server /etc/init.d/mysqld chmod 755 /etc/init.d/mysqld vim /etc/init.d/mysqld #修改datadir chkconfig --add mysqld chkconfig mysqld on service mysqld start
上面的mysql
只能32位
系统用,x86_64
要用另一个包
http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.40-linux-x86_64-icc-glibc23.tar.gz
如果安装系统的时候是最小化安装,可能还需要安装Development tools
工具包。
yum -y groupinstall "Development tools"
另外可能会报以下错误:
/usr/local/mysql/bin/mysqld: error while loading shared libraries: libstdc++.so.5: cannot open shared object file: No such file or directory
解决方法:
yum -y install compat-libstdc++-33
再用ldd
查看
ldd /usr/local/mysql/bin/mysqld/
所有的依赖库都有就可以运行了
二、安装apache
wget https://archive.apache.org/dist/httpd/httpd-2.2.16.tar.gz tar zvxf httpd-2.2.16.tar.gz cd httpd-2.2.16 ./configure --prefix=/usr/local/apache2 --with-included-apr --with-pcre --enable-mods-shared=most make && make install
三、安装php
wget http://cn2.php.net/distributions/php-5.3.28.tar.gz tar zxf php-5.3.28.tar.gz cd php-5.3.28 ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif --disable-ipv6 make && make install
四、配置apache
结合php
vim /usr/local/apache2/conf/httpd.conf
找到:
AddType application/x-gzip .gz .tgz
在该行下面添加:
AddType application/x-httpd-php .php
找到:
DirectoryIndex index.html
将该行改为:
DirectoryIndex index.html index.htm index.php
找到:
#ServerName www.example.com:80
修改为:
ServerName localhost:80
五、测试解析php
vim /usr/local/apache2/htdocs/1.php
写入:
保存后,继续测试:
curl localhost/1.php
六、资料扩展:
【httpd-2.4
版本编译安装方法】
centos6 yum
安装的apr
版本已经不适用httpd-2.4
版本了。所以,需要源码编译apr
以及apr-util
1. 下载源码:
cd /usr/local/src/ wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.12.tar.bz2 wget http://mirrors.cnnic.cn/apache/apr/apr-1.5.2.tar.bz2 wget http://mirrors.cnnic.cn/apache/apr/apr-util-1.5.4.tar.gz
2. 安装apr
tar jxvf apr-1.5.2.tar.bz2 cd apr-1.5.2 ./configure --prefix=/usr/local/apr make && make install
3. 安装apr-util
tar zxvf apr-util-1.5.4.tar.gz cd apr-util-1.5.4 ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/ make && make install
4. 安装httpd
yum install gcc make cmake pcre-devel ./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ make && make install