本文讲了从源码简单的安装apache+mysql+php+phpmyadmin 安装步骤我们基本安装源码本身提供的安装文档来。 安装过程中 出现缺少其他软件包的情况 我们将使用yum安装 如果你的rhel未付费无法使用yum 请配置centos的yum源 或者下载rpm包安装 安装之前 防火墙与s
本文讲了从源码简单的安装apache+mysql+php+phpmyadmin 安装步骤我们基本安装源码本身提供的安装文档来。
安装过程中 出现缺少其他软件包的情况 我们将使用yum安装 如果你的rhel未付费无法使用yum 请配置centos的yum源 或者下载rpm包安装
安装之前 防火墙与selinux均设置无效。
本文测试环境rhel5.5 同样适合于centos5.5。
本文适合新手学习安装 不适合生产环境。
1.下载软件
[root@rhel src]# cd /usr/local/src/[root@rhel src]# wget http://dev.mysql.com/get/downloads/mysql-5.1/mysql-5.1.50.tar.gz/from/http://ftp.iij.ad.jp/pub/db/mysql/[root@rhel src]# wget http://jp.php.net/get/php-5.2.14.tar.bz2/from/this/mirror[root@rhel src]# wget http://ftp.riken.jp/net/apache//httpd/httpd-2.2.16.tar.gz[root@rhel src]# wget http://downloads.sourceforge.net/project/phpmyadmin/phpmyadmin/3.3.7/phpmyadmin-3.3.7-all-languages.tar.bz2
2.安装配置mysql
2.1.编译安装[root@rhel src]# tar -xzvf mysql-5.1.50.tar.gz[root@rhel src]# cd mysql-5.1.50[root@rhel mysql-5.1.50]# more install-source 2.3.1. source installation overview the basic commands that you must execute to install a mysql source distribution are: shell> groupadd mysql shell> useradd -g mysql mysql (一会我们修改一下 不让mysql用户能登录系统) shell> gunzip cd mysql-version (我们已经进入解压目录了) shell> ./configure --prefix=/usr/local/mysql shell> make shell> make install shell> cp support-files/my-medium.cnf /etc/my.cnf shell> cd /usr/local/mysql shell> chown -r mysql . shell> chgrp -r mysql . shell> bin/mysql_install_db --user=mysql shell> chown -r root . shell> chown -r mysql var shell> bin/mysqld_safe --user=mysql &[root@rhel mysql-5.1.50]# groupadd mysql[root@rhel mysql-5.1.50]# useradd -g mysql -s /bin/false mysql[root@rhel mysql-5.1.50]# ./configure --prefix=/usr/local/mysql ...... checking for termcap functions library... configure: error: no curses/termcap library found ...... oops!出错了![root@rhel mysql-5.1.50]# yum -y install ncurses-devel (rpm下载地址http://ftp.sjtu.edu.cn/centos/5.5/os/i386/centos/ncurses-devel-5.5-24.20060715.i386.rpm)[root@rhel mysql-5.1.50]# ./configure --prefix=/usr/local/mysql[root@rhel mysql-5.1.50]# make[root@rhel mysql-5.1.50]# make install[root@rhel mysql-5.1.50]# cd /usr/local/mysql[root@rhel mysql]# chown -r mysql .[root@rhel mysql]# chgrp -r mysql .[root@rhel mysql]# bin/mysql_install_db --user=mysql[root@rhel mysql]# chown -r root .[root@rhel mysql]# chown -r mysql var[root@rhel mysql]# bin/mysqld_safe --user=mysql &2.2.确认mysql状态 并修改密码[root@rhel mysql]# ps -ef | grep mysql[root@rhel mysql]# /usr/local/mysql/bin/mysqladmin -u root password 'mysql'[root@rhel mysql]# /usr/local/mysql/bin/mysql -uroot -penter password:welcome to the mysql monitor. commands end with ; or /g.your mysql connection id is 2server version: 5.1.50 source distributioncopyright (c) 2000, 2010, oracle and/or its affiliates. all rights reserved.this software comes with absolutely no warranty. this is free software,and you are welcome to modify and redistribute it under the gpl v2 licensetype 'help;' or '/h' for help. type '/c' to clear the current input statement.mysql>2.3.使用官方提供的启动脚本并添加开机启动[root@rhel mysql]# cp share/mysql/mysql.server /etc/init.d/mysqld[root@rhel mysql]# /etc/init.d/mysqld stopshutting down mysql100909 20:06:48 mysqld_safe mysqld from pid file /usr/local/mysql/var/rhel.pid ended [确定][1]+ done bin/mysqld_safe --user=mysql[root@rhel mysql]# /etc/init.d/mysqld startstarting mysql. [确定][root@rhel mysql]# /sbin/chkconfig --add mysqld[root@rhel mysql]# /sbin/chkconfig mysqld on
3.安装apache2.2
3.1.编译安装[root@rhel mysql]# cd /usr/local/src/[root@rhel src]# tar -xzvf httpd-2.2.16.tar.gz[root@rhel src]# cd httpd-2.2.16[root@rhel httpd-2.2.16]# more installquick start - unix ------------------ for complete installation documentation, see [ht]docs/manual/install.html or http://httpd.apache.org/docs/2.2/install.html $ ./configure --prefix=prefix $ make $ make install $ prefix/bin/apachectl start notes: * replace prefix with the filesystem path under which apache should be installed. a typical installation might use /usr/local/apache2 for prefix (without the quotes).*在他说的最简单的安装方式上 我们加2个编译参数*--enable-rewrite rule based url manipulation*--enable-so dso capability[root@rhel httpd-2.2.16]# ./configure --prefix=/usr/local/apache2 --enable-rewrite --enable-so[root@rhel httpd-2.2.16]# make [root@rhel httpd-2.2.16]# make install3.2.建立apache专用用户[root@rhel httpd-2.2.16]# groupadd apache[root@rhel httpd-2.2.16]# useradd -g apache -m -s /sbin/nologin apache[root@rhel httpd-2.2.16]# vi /usr/local/apache2/conf/httpd.conf 找到如下2句 并在行头加#号注释掉 user daemon group daemon 追加如下2句 user apache group apache3.3.启动状态确认[root@rhel httpd-2.2.16]# /usr/local/apache2/bin/apachectl start[root@rhel httpd-2.2.16]# lsof -i:80[root@rhel httpd-2.2.16]# lsof -i:80command pid user fd type device size node namehttpd 14125 root 3u ipv6 194322 tcp *:http (listen)httpd 14354 apache 3u ipv6 194322 tcp *:http (listen)httpd 14355 apache 3u ipv6 194322 tcp *:http (listen)httpd 14356 apache 3u ipv6 194322 tcp *:http (listen)httpd 14357 apache 3u ipv6 194322 tcp *:http (listen)httpd 14358 apache 3u ipv6 194322 tcp *:http (listen)[root@rhel httpd-2.2.16]# curl http://localhost (你可以在浏览器里输入http://ip测试)it works!
*通过apachectl就可以方便的启动关闭apache了 我就不做启动脚本了
*如果你需要你可以上网搜一下 或者参照/etc/init.d/下的其他脚本 在apachectl的基础上修改一个
*或者 你可以再/etc/rc.local里追加一句来让apache开机启动/usr/local/apache2/bin/apachectl start
4.源码编译安装php
4.1.编译安装root@rhel httpd-2.2.16]# cd /usr/local/src/[root@rhel src]# tar -jxvf php-5.2.14.tar.bz2[root@rhel src]# cd php-5.2.14[root@rhel php-5.2.14]# more install apache 2.0 on unix systems ·....... you are highly encouraged to take a look at the apache documentation to get a basic understanding of the apache 2.0 server. ...... example 2-4. installation instructions (apache 2 shared module version) 1. gzip -d httpd-2_0_nn.tar.gz 2. tar xvf httpd-2_0_nn.tar 3. gunzip php-nn.tar.gz 4. tar -xvf php-nn.tar 5. cd httpd-2_0_nn 6. ./configure --enable-so 7. make 8. make install now you have apache 2.0.nn available under /usr/local/apache2, configured with loadable module support and the standard mpm prefork. to test the installation use your normal procedure for starting the apache server, e.g.: /usr/local/apache2/bin/apachectl start and stop the server to go on with the configuration for php: /usr/local/apache2/bin/apachectl stop. 9. cd ../php-nn 10. ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql (一会我们指定一下mysql的安装路径) 11. make 12. make install ....... 13. setup your php.ini cp php.ini-dist /usr/local/lib/php.ini ....... 14. edit your httpd.conf to load the php module. ...... for php 5: loadmodule php5_module modules/libphp5.so 15. tell apache to parse certain extensions as php. ...... addtype application/x-httpd-php .php .phtml it's also common to setup the .phps extension to show highlighted php source, this can be done with: addtype application/x-httpd-php-source .phps 16. use your normal procedure for starting the apache server, e.g.: /usr/local/apache2/bin/apachectl start ......[root@rhel php-5.2.14]# ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql ...... configure: error: xml2-config not found. please check your libxml2 installation. ...... oops!出错了![root@rhel php-5.2.14]# yum -y install libxml2-devel(我的情况 安装libxml2-devel的时候 依赖于zlib-devel) (rpm下载地址 http://ftp.sjtu.edu.cn/centos/5.5/os/i386/centos/zlib-devel-1.2.3-3.i386.rpm) (rpm下载地址 http://ftp.sjtu.edu.cn/centos/5.5/os/i386/centos/libxml2-devel-2.6.26-2.1.2.8.i386.rpm)[root@rhel php-5.2.14]# ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql[root@rhel php-5.2.14]# make[root@rhel php-5.2.14]# make install[root@rhel php-5.2.14]# cp php.ini-dist /usr/local/lib/php.ini[root@rhel php-5.2.14]# vi /usr/local/apache2/conf/httpd.conf 在内容里搜一下是否有libphp5.so 我的情况 已经有了 如果没有追加下面那句前面不带#的 # loadmodule foo_module modules/mod_foo.so loadmodule php5_module modules/libphp5.so # 再搜索addtype关键字 在那附近追加如下一句 addtype application/x-httpd-php .php .phtml 再搜索下面一段 把第二句directoryindex的后面追加index.php directoryindex index.html index.php 4.1.2测试php网页[root@rhel php-5.2.14]# cd /usr/local/apache2/htdocs/[root@rhel htdocs]# vi index.php 输入内容 [root@rhel php-5.2.14]# /usr/local/apache2/bin/apachectl restart[root@rhel mysql]# curl -i http://localhost/index.php 或者你在你的浏览器里输入http://yourip/index.php4.1.3测试php和mysql连接[root@rhel htdocs]# vi phpmysql.php 输入内容 因为我们编译php的时候没有加--with-mysqli选项 所以不支持mysqli扩展[root@rhel htdocs]# curl http://localhost/phpmysql.php mysql first test:success 好了 我这里成功了 你可以再浏览器里输入http://ip/phpmysql.php
5.安装配置phpmyadmin
5.1.配置phpmyadmin[root@rhel mysql]# cd /usr/local/src/[root@rhel src]# tar -jxvf phpmyadmin-3.3.7-all-languages.tar.bz2我们把phpmyadmin配置到/var/www/下 命名为phpmyadmin[root@rhel src]# test -d /var/www || mkdir -p /var/www[root@rhel src]# mv phpmyadmin-3.3.7-all-languages /var/www/phpmyadmin[root@rhel src]# cp /var/www/phpmyadmin/config.sample.inc.php /var/www/phpmyadmin/config.inc.php[root@rhel src]# chmod 660 /var/www/phpmyadmin/config.inc.php[root@rhel src]# vi /var/www/phpmyadmin/config.inc.php 追加$cfg['lang'] = 'zh-utf-8';----------可选设置 为phpmyadmin设置50位的短语密码---------------推荐你设置 但是要使用mkpasswd命令 你需要安装expect包[root@rhel src]# mkpasswd -l 50clecxjgn7hg%whkyajmmq8zisgzceinvcuqnwhbxlwapnzemwm复制产生的短语密码[root@rhel src]# vi /var/www/phpmyadmin/config.inc.php 找到如下参数 $cfg['blowfish_secret'] = 'clecxjgn7hg%whkyajmmq8zisgzceinvcuqnwhbxlwapnzemwm'----------------------可选设置 结束-----------------------[root@rhel src]# chown -r root.apache /var/www/phpmyadmin[root@rhel src]# cd /usr/local/apache2/conf/[root@rhel conf]# vi extra/phpmyadmin.conf 加入内容 alias /phpmyadmin /var/www/phpmyadmin order deny,allow deny from all allow from 127.0.0.1 allow from 10.110.108.55 //这里改成你实际允许访问的ip [root@rhel conf]# vi httpd.conf 追加 include conf/extra/phpmyadmin.conf[root@rhel conf]# /usr/local/apache2/bin/apachectl restart5.2.测试 在浏览器输入下面的网址http://ip/phpmyadmin/输入我们前面设置的mysql用户名root 和密码mysqlenjoy!
后话;因为我们安装php的时候 加的参数比较少 所以打开phpmyadmin的时候会有一些警告
但是我相信读者已经会重新编译php来解决这些问题了吧!
