zoukankan      html  css  js  c++  java
  • Linux(centOS)手动安装删除Apache+MySQL+PHP+Memcached原创无错版

    ===================

    第一步:Apache安装

    ===================

    下载 去 http://www.apache.org 自己找最新的 国内有很多镜像点例如人人和163

    -------------------------------------------------

    #wget http://labs.renren.com/apache-mirror/httpd/httpd-2.2.21.tar.gz

    #tar zxvf httpd-2.2.21.tar.gz

    #cd httpd-2.2.21

    #./configure --prefix=/usr/local/apache2/ --enable-proxy --enable-ssl --enable-cgi --enable-rewrite --enable-so --enable-module=so

    #make

    #make install

    说明:如果make不成功,那么是configure不成,例如你缺少ssl组件,可以去掉

    --enable-ssl 
    ----------

    如果Make: command not found

    看看是不是make没装

    # rpm -qa|grep make   

    如果没有信息那么说明make没装

    #yum install make 即可
    -------------------

    手动启动

    # /usr/local/apache2/bin/apachectl start

    重启

    # /usr/local/apache2/bin/apachectl restart

    --------------------------

    YUM自动安装的启动
    #service httpd restart

    输入这个会提示出错 httpd未被被识别的服务

    这个请见本博客另一篇介绍

    -------------------------

    这就说明安装成功了。

    自己在浏览器输入:http://localhost/

    这样就说明成功了!

    ------------------------------------------

    增加权限和文件格式转换(不然apache会报没权限执行文件)
    #chmod +x   文件
    #dos2unix   文件

    ------------------------------------------

    卸载apache

    如果是源码安装

    #rm   -rf   你的apache安装路径

    同样作用于其他

    ========================

    YUM方式安装的,这样卸载:

    #yum remove httpd

    否则要用

    #rpm -qa|grep httpd

    一个个删除
    # rpm -e  ......

    ===================

    第二步 Mysql安装

    ===================

    第一种方法:使用yum自动安装

    #yum -y install mysql-server

    ----------------------------------------

    第二种:下载源码编译安装

    #wget http://mysql.cdpa.nsysu.edu.tw/Downloads/MySQL-5.1/mysql-5.1.57.tar.gz

    #tar zxvf mysql-5.1.57.tar.gz

    #cd mysql-5.1.57

    #./configure --prefix=/usr/local/mysql --with-mysqld-user=mysql --with-charset=gbk --bindir=/usr/local/bin --sbindir=/usr/local/sbin --with-plugins=innobase --with-partition

    #make

    #make install

    #cd /usr/local/mysql

    #mysql_install_db

    #chown -R mysql:mysql *

    #cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysql

    #/etc/rc.d/mysql start (加入到/etc/rc.local 以便系统重启后自动启动mysql)

    修改/etc/rc.local

    说明:请修改mysql配置文件my.cnf中wait_timeout = 600(有些程序执行时间较长,mysql超时时间如果太短的话,容易发生mysql server has go away的错误)

    注意事项:

    安装完成后,需要拷贝一份my.cnf到ect目录下,使用support-files目录中的一个作为模板。在这个目录中有4个模板文件,是根据不同机器的内存定制的。

    #cp support-files/my-medium.cnf /etc/my.cnf

    ===================

    第三步 PHP安装

    ===================

    www.php.net找最新的版本

    #wget  http://cn2.php.net/get/php-5.3.8.tar.gz/from/this/mirror

    #tar zxvf  php-5.3.8.tar.gz

    #cd php-5.3.8

    #./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql-dir=/usr/local/mysql

    如果失败 可能原因有各种各样

    -------------------------------

    如果提示:Cannot find MySQL header files under /date/mysql.


    这个是缺少了 mysql-devel 安装包,用
    yum -y install mysql-devel 即可解决!

    #yum -y install mysql-devel

    -------------------------------

    如果提示:xml2-config not found. Please check your libxml2 installation.

    需要安装libxml2

    #yum install libxml2-devel

    -------------------------------

    如果提示:Try adding --with-zlib-dir=<DIR>试着添加一下 zlib的路径,如下

    #./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql-dir=/usr/local/mysql --with-zlib-dir=/usr/local/zlib

    ------------------------------

    完全成功才可以编译安装

    #make

    #make install

    复制php.ini配置文件

    参考此文http://blog.csdn.net/21aspnet/article/details/7001344

    注意php新版本此文件名有变更

    #cp php.ini-production /usr/local/php/lib/php.ini

    ------------------------------

    在apache的配置文件httpd.conf

    增加

    AddType application/x-httpd-php .php

    ===================

    第四步 Memcached安装

    ===================

    可以参考http://timke.blog.163.com/blog/static/1015873062009111094715315/

    说明必须先安装libevent

    官网   http://libevent.org/  找最新的版本

    #wget https://github.com/downloads/libevent/libevent/libevent-2.0.16-stable.tar.gz

    #tar xzvf libevent-2.0.16-stable.tar.gz

    #cd libevent-2.0.16-stable

    #./configure --prefix=/usr

    #make

    #make install

    -------------------------------------------- 

    第二步 安装memcached

    # wget http://memcached.googlecode.com/files/memcached-1.4.9.tar.gz

    #tar xzvf memcached-1.4.9.tar.gz

    #cd memcached-1.4.9

    #./configure --prefix=/usr/local/memcached --with-libevent=/usr

    #make

    #make install

    启动

    #/usr/local/memcached/bin/memcached -d -m 100 -uroot -l 0.0.0.0 -p 11211 -c 512 -P /usr/local/memcached/memcached.pid

    查看详情

    #ps aux|grep mem   

    输出pid

    #cat /usr/local/memcached/memcached.pid

    查看内存使用

    #top -n 1 |grep Mem

    -------------------------------------------

    第三步  安装memcached的php扩展memcache

    #wget http://pecl.php.net/get/memcache-2.2.6.tgz

    #tar vxzf memcache-2.2.6.tgz

    #cd memcache-2.2.6

    #/usr/local/php/bin/phpize

    此处出错可以参考 http://blog.csdn.net/21aspnet/article/details/7001182

    #./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config --with-zlib-dir

    或者

    #./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config --with-zlib-dir=/usr

    #make

    #make install 

    #vi /usr/local/php/lib/php.ini

    php.ini添加

    extension=memcache.so

    <完>

    -------------------

    重启

    # /usr/local/apache2/bin/apachectl restart

    ---------------

    测试

    1. $memcache = new Memcache; //创建一个memcache对象     
    2. $memcache->connect('localhost', 11211) or die ("Could not connect"); //连接Memcached服务器     
    3. $memcache->set('key', 'test'); //设置一个变量到内存中,名称是key 值是test     
    4. $get_value = $memcache->get('key'); //从内存中取出key的值     
    5. echo $get_value;    


     

    --------------

    或者手动指定

    extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"

    1. class MemCache {  
    2.     var $mem = null;  
    3.       
    4.     private static $isLibLoad = false;  
    5.     //put your code here  
    6.     public function Com_MemCache(){  
    7.         if(!self::$isLibLoad){  
    8.             dl("memcache.so");  
    9.             self::$isLibLoad = true;  
    10.         }  
    11.           
    12.         $this->mem = new Memcache();  
    13.         $this->mem->connect("127.0.0.1", 11211);  
    14.     }  
    15.   
    16.     public function set($key,$value,$flag = null,$expire = 5000){  
    17.         $this->mem->set($key, $value, $flag, $expire);  
    18.     }  
    19.   
    20.     public function get($key){  
    21.         return $this->mem->get($key);  
    22.     }  
    23.   
    24.     function __destruct(){  
    25.         $this->mem->close();  
    26.     }  
    27. }  

    调用

    1. $cache = new MemCache();  
    2.            $mm = $cache ->get("A");  
    3.            if($mm==null){  
    4.              $cache->set('A', date('Y-m-j').' '.date('G:i:s'),null,15);  
    5.            }  
    6. echo $mm;  



     

    因为MemCache.php有 dl("memcache.so");所以在php.ini中不需要extension=memcache.so了,但是前一句extension_dir是要的。

  • 相关阅读:
    BEM(Block–Element-Modifier)
    http://element.eleme.io/#/zh-CN/component/quickstart
    Commit message 的写法规范。本文介绍Angular 规范(
    好的commit应该长啥样 https://github.com/torvalds/linux/pull/17#issuecomment-5654674
    代码管理
    if you have content fetched asynchronously on pages where SEO is important, SSR might be necessary
    Martin Fowler’s Active Record design pattern.
    The Zen of Python
    Introspection in Python How to spy on your Python objects Guide to Python introspection
    Object-Oriented Metrics: LCOM 内聚性的度量
  • 原文地址:https://www.cnblogs.com/xiaoleiel/p/8296455.html
Copyright © 2011-2022 走看看