`

Linux(centOS)手动安装删除Apache+MySQL+PHP+Memcached原创无错版

 
阅读更多

最后更新时间:2012.3.21

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

第一步:Apache安装(已更新到2.2.22)

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

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

英文文档:http://httpd.apache.org/docs/2.2/

中文文档:http://www.php100.com/manual/apache2/index.html

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

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

#tar zxvf httpd-2.2.22.tar.gz

#cd ./httpd-2.2.22

#./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
-----------------------------------------------

如果出现“No recognized SSL/TLS toolkit detected”错误

#yum -y install openssl openssl-devel

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

如果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

如果报错说:

Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName

需要修改/usr/local/apache2/httpd.conf在

#serverName www.example.com:80

这个位置修改为:

serverName localhost:80

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

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

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

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

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

这就说明安装成功了。

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

这样就说明成功了!

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

防火墙配置

注意如果你希望在本地机器例如xp访问虚拟机的网页,如果是centos6需要修改防火墙启动80端口

/etc/sysconfig

[root@centos6 ~]# vim /etc/sysconfig/iptables

添加下面一行,打开防火墙80端口:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

重启防火墙

#/etc/init.d/iptables restart

查看CentOS防火墙信息:/etc/init.d/iptables status

关闭CentOS防火墙服务:/etc/init.d/iptables stop

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

开机加入自动启动服务

编辑rc.local文件
#vi /etc/rc.d/rc.local

加入如下启动命令
/usr/sbin/apachectl start
/etc/rc.d/init.d/mysqld start
/etc/rc.d/init.d/smb start
/usr/local/subversion/bin/svnserve -d

注意:我的这个路径是yum安装这些服务得到的路径,填写时要根据自己的安装路径,找不到可以借助whereis命令,主要是找到apachectl 、mysqld 、smb 这三个启动文件。

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

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

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

ab测试

#ab -n 1000 -c 10http://localhost/

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

卸载apache

如果是源码安装

#rm -rf 你的apache安装路径

同样作用于其他

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

httpd启用虚拟主机
#Include conf/extra/httpd-vhosts.conf

httpd-vhosts.conf
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "/www/"
<Directory />
#拒绝所有请求
# Deny from all
#是否显示列表
# Options Indexes FollowSymLinks
#是否启用rewrite
# AllowOverride all

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

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安装(已更新到5.4.0版)

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

www.php.net找最新的版本

5.4安装

#wget http://cn2.php.net/get/php-5.4.0.tar.gz/from/cn.php.net/mirror

#tar zxvf php-5.4.0.tar.gz

#cd php-5.4.0

如果是5.3.8

#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

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

安装失败如果提示:Cannot load /usr/local/apache2/modules/libphp5.so into server:

原因:是Linux有一个SELinux保护模式引起的。

解决办法:
1关闭SELINUX的方法:
vi /etc/selinux/config 将SELINUX=enforcing 改成SELINUX=disabled 需要重启
这个方法可能会对服务器带来风险。


2不关闭SELINUX的方法:
# setenforce 0
# chcon -c -v -R -u system_u -r object_r -t textrel_shlib_t /usr/local/apache/modules/libphp5.so
# service httpd restart
# setenforce 1

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

复制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

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

执行php文件

#/usr/local/php/bin/php xx.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

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

测试


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

或者手动指定

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

调用



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

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics