zoukankan      html  css  js  c++  java
  • linux centos apache+php+mysql 安装( 用包安装 非yum 安装)

    Centos5.4 _x86 _64位操作系统 

    httpd-2.2.15.tar.gz

    mysql-5.5.2-m2.tar.gz

    php-5.3.2.tar.gz

    如果出现问题 并且在过程中没有说明,请看文章尾部的   常见问题 

    如果下面不能成功安装的话 可以参考我自己的安装过程(注意 php mysql apache 的版本号)

    地址:http://www.cnblogs.com/qingfeng2010/articles/2080333.html

    1.lsb_release –a 查看系统环境 

    [root@localhost ~]# lsb_release -a
    LSB Version:    :core-3.1-amd64:core-3.1-ia32:core-3.1-noarch:graphics-3.1-amd64:graphics-3.1-ia32:graphics-3.1-noarch
    Distributor ID: CentOS
    Description:    CentOS release 5.4 (Final)
    Release:        5.4
    Codename:       Final
    [root@localhost ~]#
    

    2.查找是否已经安装过环境 

    [root@localhost www]# rpm -qa|grep httpd
    [root@localhost www]# rpm -qa|grep mysqld
    [root@localhost www]# rpm -qa|grep php
    [root@localhost www]# rpm -qa|grep apache
    
    如果找到 删除  (--nodeps 是强制删除的意思)
    [root@localhost ~]# rpm -qa|grep httpd
    httpd-2.2.3-31.el5.centos
    [root@localhost ~]# rpm -e --nodeps httpd
    
    3.解压缩
    [root@localhost www]# tar -zxf httpd-2.2.15.tar.gz 
    [root@localhost www]# tar -zxf mysql-5.5.2-m2.tar.gz 
    [root@localhost www]# tar -zxf php-5.3.2.tar.gz
    

    4.安装mysql  (新建用户组mysql 当然如果有就不用重建 )

    4.安装mysql  (新建用户组mysql 当然如果有就不用重建 )
    [root@localhost www]# groupadd mysql
    [root@localhost www]# useradd -g mysql -c "MySQL Server" mysql
    第二句的意思是:添加一个用户mysql 到 mysql这个组中, 备注是 MySQL Server
    
    [root@localhost www]# cd /var/www/mysql-5.5.2-m2 (进入mysql的文件夹)
    [root@localhost mysql-5.5.2-m2]# chown -R root.root *    (更改当前文件夹拥有者)      
    
    (下面代码要复制全  从 ./configure   到  --without-bench)
    [root@localhost mysql-5.5.2-m2]# ./configure \
    > --prefix=/usr/local/mysql \                        (mysql安装路径)
    > --localstatedir=/usr/local/mysql/data \          (mysql数据库存放路径)
    > --disable-maintainer-mode \     (服务器用来与本地客户端进行通信的Unix套接字文件)
    > --with-mysqld-user=mysql \
    > --with-unix-socket-path=/tmp/mysql.sock \
    > --without-comment \
    > --without-debug \
    > --without-bench
    

    网上找到的资料 如果报错 请核对是否是下面的错误 并查看其下面的连接  

    18-Jul-2005: If you are installing MySQL 4.0.x on Fedora Core 4, there is a problem with LinuxThreads that prevents MySQL from compiling properly. Installing on Fedora Core 3 works fine though. Thanks to Kevin Spencer for bringing this to my attention. There is a workaround listed at http://bugs.mysql.com/bug.php?id=9497. Thanks to Collin Campbell for that link. Another solution can be found at http://bugs.mysql.com/bug.php?id=2173. Thanks to Kaloyan Raev for that one. 

    [root@localhost mysql-5.5.2-m2]# make;make install (此处需要一段时间,特别到一处要停留一段时间,需要等待一下) 

    5.配置mysql

    [root@localhost mysql-5.5.2-m2]# ./scripts/mysql_install_db (初始化mysql)
    [root@localhost mysql-5.5.2-m2]# chown -R root:mysql /usr/local/mysql/
    [root@localhost mysql-5.5.2-m2]# chown -R mysql:mysql /usr/local/mysql/data/
    [root@localhost mysql-5.5.2-m2]# cp support-files/my-medium.cnf /etc/my.cnf
    [root@localhost mysql-5.5.2-m2]# chown root:sys /etc/my.cnf 
    [root@localhost mysql-5.5.2-m2]# chmod 644 /etc/my.cnf

     

    If you get an error message about the data directory not existing, etc., something went wrong in the mysql_install_dbstep above. Go back and review that; make sure you didn't get some sort of error message when you ran it, etc.

     

    [root@localhost mysql-5.5.2-m2]# echo "/usr/local/mysql/lib/mysql/" >> /etc/ld.so.conf
    [root@localhost mysql-5.5.2-m2]# ldconfig
    [root@localhost mysql-5.5.2-m2]# cp ./support-files/mysql.server /etc/rc.d/init.d/mysql
    [root@localhost mysql-5.5.2-m2]# chmod +x /etc/rc.d/init.d/mysql 
    [root@localhost mysql-5.5.2-m2]# /sbin/chkconfig --level 3 mysql on
    [root@localhost mysql-5.5.2-m2]# cd /usr/local/mysql/bin/
    [root@localhost bin]# for file in *; do ln -s /usr/local/mysql/bin/$file /usr/bin/$file; done

    [root@localhost ~]# cd /etc/rc.d/rc3.d/
    [root@localhost rc3.d]# ll
    
    总计 292
    lrwxrwxrwx 1 root root 17 12-16 02:12 K01dnsmasq -> ../init.d/dnsmasq
    lrwxrwxrwx 1 root root 24 12-16 02:16 K02avahi-dnsconfd -> ../init.d/avahi-dnsconfd
    lrwxrwxrwx 1 root root 24 12-16 02:17 K02NetworkManager -> ../init.d/NetworkManager
    lrwxrwxrwx 1 root root 17 12-16 02:14 K02oddjobd -> ../init.d/oddjobd
    lrwxrwxrwx 1 root root 16 12-16 02:10 K05conman -> ../init.d/conman
    lrwxrwxrwx 1 root root 19 12-16 02:12 K05saslauthd -> ../init.d/saslauthd
    lrwxrwxrwx 1 root root 17 12-16 02:12 K05wdaemon -> ../init.d/wdaemon
    lrwxrwxrwx 1 root root 16 12-16 02:10 K10psacct -> ../init.d/psacct
    lrwxrwxrwx 1 root root 14 12-16 02:10 K10tcsd -> ../init.d/tcsd
    lrwxrwxrwx 1 root root 13 12-16 02:14 K20nfs -> ../init.d/nfs
    lrwxrwxrwx 1 root root 14 12-16 02:14 K24irda -> ../init.d/irda
    lrwxrwxrwx 1 root root 19 12-16 02:17 K35vncserver -> ../init.d/vncserver
    lrwxrwxrwx 1 root root 17 12-16 02:26 K35winbind -> ../init.d/winbind
    lrwxrwxrwx 1 root root 14 12-16 02:19 K36lisa -> ../init.d/lisa
    lrwxrwxrwx 1 root root 20 12-16 02:12 K50netconsole -> ../init.d/netconsole
    lrwxrwxrwx 1 root root 16 12-19 06:18 K50vsftpd -> ../init.d/vsftpd
    lrwxrwxrwx 1 root root 20 12-16 02:14 K69rpcsvcgssd -> ../init.d/rpcsvcgssd
    lrwxrwxrwx 1 root root 16 12-16 02:26 K73ypbind -> ../init.d/ypbind
    lrwxrwxrwx 1 root root 14 12-16 02:10 K74nscd -> ../init.d/nscd
    lrwxrwxrwx 1 root root 14 12-17 00:12 K74ntpd -> ../init.d/ntpd
    lrwxrwxrwx 1 root root 15 12-16 02:12 K85mdmpd -> ../init.d/mdmpd
    lrwxrwxrwx 1 root root 20 12-16 02:09 K87multipathd -> ../init.d/multipathd
    lrwxrwxrwx 1 root root 15 12-16 02:14 K87named -> ../init.d/named
    lrwxrwxrwx 1 root root 24 12-16 02:14 K88wpa_supplicant -> ../init.d/wpa_supplicant
    lrwxrwxrwx 1 root root 14 12-16 02:17 K89dund -> ../init.d/dund
    lrwxrwxrwx 1 root root 18 12-16 02:09 K89netplugd -> ../init.d/netplugd
    lrwxrwxrwx 1 root root 14 12-16 02:17 K89pand -> ../init.d/pand
    lrwxrwxrwx 1 root root 15 12-16 02:07 K89rdisc -> ../init.d/rdisc
    lrwxrwxrwx 1 root root 14 12-16 02:14 K91capi -> ../init.d/capi
    lrwxrwxrwx 1 root root 25 12-16 02:10 K99readahead_later -> ../init.d/readahead_later
    lrwxrwxrwx 1 root root 23 12-16 02:12 S00microcode_ctl -> ../init.d/microcode_ctl
    lrwxrwxrwx 1 root root 22 12-16 02:10 S02lvm2-monitor -> ../init.d/lvm2-monitor
    lrwxrwxrwx 1 root root 25 12-16 02:10 S04readahead_early -> ../init.d/readahead_early
    lrwxrwxrwx 1 root root 15 12-16 02:17 S05kudzu -> ../init.d/kudzu
    lrwxrwxrwx 1 root root 18 12-16 02:08 S06cpuspeed -> ../init.d/cpuspeed
    lrwxrwxrwx 1 root root 19 12-16 02:07 S08ip6tables -> ../init.d/ip6tables
    lrwxrwxrwx 1 root root 18 12-16 02:07 S08iptables -> ../init.d/iptables
    lrwxrwxrwx 1 root root 18 12-16 02:12 S08mcstrans -> ../init.d/mcstrans
    lrwxrwxrwx 1 root root 14 12-16 02:14 S09isdn -> ../init.d/isdn
    lrwxrwxrwx 1 root root 17 12-16 02:12 S10network -> ../init.d/network
    lrwxrwxrwx 1 root root 16 12-16 02:10 S11auditd -> ../init.d/auditd
    lrwxrwxrwx 1 root root 21 12-16 02:13 S12restorecond -> ../init.d/restorecond
    lrwxrwxrwx 1 root root 16 12-16 02:12 S12syslog -> ../init.d/syslog
    lrwxrwxrwx 1 root root 20 12-16 02:12 S13irqbalance -> ../init.d/irqbalance
    lrwxrwxrwx 1 root root 17 12-16 02:12 S13portmap -> ../init.d/portmap
    lrwxrwxrwx 1 root root 17 12-16 02:14 S14nfslock -> ../init.d/nfslock
    lrwxrwxrwx 1 root root 19 12-16 02:12 S15mdmonitor -> ../init.d/mdmonitor
    lrwxrwxrwx 1 root root 19 12-16 02:14 S18rpcidmapd -> ../init.d/rpcidmapd
    lrwxrwxrwx 1 root root 17 12-16 02:14 S19rpcgssd -> ../init.d/rpcgssd
    lrwxrwxrwx 1 root root 20 12-16 02:16 S22messagebus -> ../init.d/messagebus
    lrwxrwxrwx 1 root root 19 12-16 02:17 S25bluetooth -> ../init.d/bluetooth
    lrwxrwxrwx 1 root root 15 12-16 02:12 S25netfs -> ../init.d/netfs
    lrwxrwxrwx 1 root root 15 12-16 02:13 S25pcscd -> ../init.d/pcscd
    lrwxrwxrwx 1 root root 15 12-16 02:12 S26acpid -> ../init.d/acpid
    lrwxrwxrwx 1 root root 19 12-16 02:17 S26haldaemon -> ../init.d/haldaemon
    lrwxrwxrwx 1 root root 14 12-16 02:17 S26hidd -> ../init.d/hidd
    lrwxrwxrwx 1 root root 20 12-16 02:07 S26lm_sensors -> ../init.d/lm_sensors
    lrwxrwxrwx 1 root root 16 12-16 02:10 S28autofs -> ../init.d/autofs
    lrwxrwxrwx 1 root root 14 12-16 02:14 S55sshd -> ../init.d/sshd
    lrwxrwxrwx 1 root root 14 12-16 02:17 S56cups -> ../init.d/cups
    lrwxrwxrwx 1 root root 20 12-16 02:12 S56rawdevices -> ../init.d/rawdevices
    lrwxrwxrwx 1 root root 15 12-19 09:29 S64mysql -> ../init.d/mysql               (注意此处 下面要用到)
    lrwxrwxrwx 1 root root 18 12-16 02:12 S80sendmail -> ../init.d/sendmail
    lrwxrwxrwx 1 root root 13 12-16 02:07 S85gpm -> ../init.d/gpm
    lrwxrwxrwx 1 root root 15 12-16 02:12 S90crond -> ../init.d/crond
    lrwxrwxrwx 1 root root 13 12-16 02:16 S90xfs -> ../init.d/xfs
    lrwxrwxrwx 1 root root 17 12-16 02:08 S95anacron -> ../init.d/anacron
    lrwxrwxrwx 1 root root 13 12-16 02:12 S95atd -> ../init.d/atd
    lrwxrwxrwx 1 root root 22 12-16 02:17 S97yum-updatesd -> ../init.d/yum-updatesd
    lrwxrwxrwx 1 root root 22 12-16 02:16 S98avahi-daemon -> ../init.d/avahi-daemon
    lrwxrwxrwx 1 root root 19 12-16 02:17 S99firstboot -> ../init.d/firstboot
    lrwxrwxrwx 1 root root 11 12-16 02:12 S99local -> ../rc.local
    lrwxrwxrwx 1 root root 16 12-16 02:12 S99smartd -> ../init.d/smartd

    /etc/rc.d/rc3.d/ 查看 mysql 对应的名字 每个机器可能都不一样 我的是S64mysql

    目地是确保symlink被正确的开设 

    [root@localhost rc3.d]# /etc/rc.d/rc3.d/S64mysql start   (用到了上面的加蓝的那个名称)
    Starting MySQL.[确定]

    查看mysql是否安装成功 成功会返回mysql 的版本信息 

    [root@localhost rc3.d]# mysqladmin version
    mysqladmin  Ver 8.42 Distrib 5.5.2-m2, for unknown-linux-gnu on x86_64
    Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
    This software comes with ABSOLUTELY NO WARRANTY. This is free software,
    and you are welcome to modify and redistribute it under the GPL license
    
    Server version          5.5.2-m2-log
    Protocol version        10
    Connection              Localhost via UNIX socket
    UNIX socket             /tmp/mysql.sock
    Uptime:                 4 min 58 sec
    
    Threads: 1  Questions: 1  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 0.3
    
    [root@localhost rc3.d]# mysqladmin -u root password 'rootpassword' (设置mysql 密码,  注:rootpassword 替换成你自己的密码)
    
    测试mysql
    [root@localhost rc3.d]# mysql -u root -p
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 3
    Server version: 5.5.2-m2-log Source distribution
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql>

    安装apache

    [root@localhost /]# cd /var/www/httpd-2.2.15
    [root@localhost httpd-2.2.15]# ./configure \
    > --prefix=/usr/local/apache \
    > --enable-shared=max \
    > --enable-module=rewrite \
    > --enable-module=so
    
    [root@localhost httpd-2.2.15]# make;make install
    
    后台会接着配置 apache 的配置文件

    安装php

    [root@localhost httpd-2.2.15]# cd /var/www/php-5.3.2
    [root@localhost php-5.3.2]# ./configure \
    > --with-apxs2=/usr/local/apache/bin/apxs \
    > --disable-debug \
    > --enable-ftp \
    > --enable-inline-optimization \
    > --enable-magic-quotes \
    > --enable-mbstring \
    > --enable-mm=shared \
    > --enable-safe-mode \
    > --enable-track-vars \
    > --enable-trans-sid \
    > --enable-wddx=shared \
    > --enable-xml \
    > --with-dom \
    > --with-gd \
    > --with-gettext \
    > --with-mysql=/usr/local/mysql \
    > --with-regex=system \
    > --with-xml \
    > --with-zlib-dir=/usr/lib
    
    [root@localhost httpd-2.2.15]# make;make install (等)

    开始配置环境 

    Php.ini  php.ini-development  php.ini-production   两个文件中的任意一个   php.ini-dist 也可以 但有的包里面没有

     [root@localhost php-5.3.2]# cp php.ini-development /usr/local/lib/php.ini
    [root@localhost php-5.3.2]# ln -s /usr/local/lib/php.ini /etc/php.ini
    [root@localhost php-5.3.2]# ln -s /usr/local/apache/conf/httpd.conf /etc/httpd.conf
    [root@localhost htdocs]# ln -s /usr/local/apache/bin/apachectl /etc/rc.d/init.d/apache
    [root@localhost rc3.d]# ln -s /etc/rc.d/init.d/apache /etc/rc.d/rc3.d/S90apache
    

    现在可以向下面这样启动apache

    /etc/rc.d/init.d/apache start 

     

    现在配置apache 使php能够执行 

    [root@localhost rc3.d]# vi /etc/httpd.conf
    如果找不下面的 就添加
        AddType application/x-tar .tgz
        AddType application/x-httpd-php .php .foo     (主要是这句)
        AddType application/x-httpd-php-source .phps .phtmls
        AddType application/x-httpd-php .php .htm .html
    <IfModule mod_dir.c>
        DirectoryIndex index.php index.htm index.html
    </IfModule>

    测试环境 

    [root@localhost rc3.d]# cd /usr/local/apache/htdocs/
    [root@localhost htdocs]# vi index.php
    写入 
    <?php
    phpinfo();
    ?>
    保存退出
    

    访问 http://服务器的ip/index.php     看看会不会有错误出现  (最好从头看到尾) 

    错误提示  解决办法在下面的常见问题中 

    Warning: phpinfo() [function.phpinfo]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Asia/Chongqing' for 'CST/8.0/no  


    常见问题 

    mysqladmin 不能使用 

    http://www.cnblogs.com/qingfeng2010/archive/2011/01/03/1924787.html

     

    mysql 安全

    http://www.symantec.com/connect/articles/securing-mysql-step-step

     

    mysql 刷新

    flush privileges;

     

    Mysql 启动方式 

    /etc/rc.d/init.d/mysql start | stop | restart

     

    Apache 启动方式

    /usr/local/apache/bin/apachectl start | stop | restart

     

    最终启动方式

    service apache start | stop | restart

    service mysql start | stop | restart

     

    MySQL Security Issues

    First, we will assume that only applications on the same server will be allowed to access the database (i.e., not a program running on a physically separate server). So we'll tell MySQL not to even listen on port 3306 for TCP connections like it does by default.

    Edit /etc/my.cnf and uncomment the

    skip-networking

    line (delete the leading #).

    For more security info, check out this MySQL security tutorial. 

     

     

    Php 出下面错误   

    Configuring SAPI modules

    checking for AOLserver support... no

    checking for Apache 1.x module support via DSO through APXS... configure: error: You have enabled Apache 1.3 support while your server is Apache 2.  Please use the appropiate switch --with-apxs2

    只需 ./configure  后面的  

    Ø       --with-apxs=/usr/local/apache/bin/apxs \ 

    换成 

    Ø       --with-apxs2=/usr/local/apache/bin/apxs \  

     

    本文中用的是 后者   如果不行 可以 以上两种方式 都式一下 

     

     

    查看 ./configure 的用法 

    [root@localhost php-5.3.2]# ./configure –help    

     

     

    Php.ini  php.ini-development  php.ini-production   两个文件中的任意一个 

    php.ini-dist 也可以 但有的包里面没有 

     

     

     

    输入IP 访问的是  /usr/local/apache/htdocs/  这个文件夹 

    你也可以在 httpd.conf 中查找 

    DocumentRoot      这个后面跟着的路径就是直接输入IP 所访问到的文件夹 

     

    访问 

    http://服务器的ip/index.php 

     

    往下看  看看会有错误出现   

    Warning: phpinfo() [function.phpinfo]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Asia/Chongqing' for 'CST/8.0/no  

    解决办法:  

    1. index.php 修改成 下面的代码 

    <?php

    date_default_timezone_set ('Asia/Shanghai');

    phpinfo();

    ?> 

    重启 apache

    [root@localhost htdocs]# /etc/rc.d/init.d/apache restart 

    如果不出现错误 可以去 编辑/etc/php.ini 添加设置时区 

    添加 下面一句话 

    date.timezone =Asia/Shanghai 

    保存 退出 

    重启 apache

    [root@localhost htdocs]# /etc/rc.d/init.d/apache restart 

     

    默认打开的程序 设置 

    编辑 /etc/httpd.conf  修改下面内容DirectoryIndex后面跟的 所有文件名以空格格开 打开时 会按先后顺序打开   如果index.php存在则打开;index.php 不存在 则打开 index.html

    <IfModule dir_module>

        DirectoryIndex index.php index.html

    </IfModule>

    保存 退出 

    记得要重启 apache

    service apache restart

     

    要撑握的知识 

    命令 

    groupadd

    useradd

    ln

     

    了解mysql安全 




  • 相关阅读:
    基于jQuery弹性展开收缩菜单插件gooey.js
    动态插入和移除
    匹配0-59 0-23 的正则表达式
    换行问题
    iOSBug -- The file “Info.plist” couldn’t be opened
    MarkDown语法
    Mac -- 右键添加pages文件
    iOS -- 使用蒲公英进行内测
    Mac使用技巧--如何给safari安装翻译插件
    iOS--优化
  • 原文地址:https://www.cnblogs.com/qingfeng2010/p/1930333.html
Copyright © 2011-2022 走看看