社区应用 最新帖子 精华区 社区服务 会员列表 统计排行
  • 2780阅读
  • 2回复

[分享]centos apache+mysql+php+memcached+gd 安装教程

楼层直达
z3960 
级别: FLY版主
发帖
794200
飞翔币
211941
威望
215737
飞扬币
2661856
信誉值
8

第一章:安装mysql
我们先从mysql来安装,为什么呢?如果你先从PHP安装,那你就是自找麻烦,如果你抬杠从apache安装那还可以,不过个人认为mysql是基本,还是从它来安装好了。

下面所安装的全是tar包,可以自己选参数,我喜欢,如果你要用RPM也可以,不过依赖关系有些复杂,没有tar包舒服。

# useradd mysql -s /sbin/nologin
# tar xzvf mysql-5.0.18.tar.gz
# cd mysql-5.0.18
# CFLAGS="-O3 -mpentiumpro" CXX=gcc CXXFLAGS="-O3 -mpentiumpro \
-felide-constructors -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql \
--with-extra-charsets=all --with-charset=gbk \
--enable-assembler --with-mysqld-ldflags=-all-static
# make
# make install
# cp support-files/my-huge.cnf /etc/my.cnf
# cd /usr/local/mysql
# bin/mysql_install_db --user=mysql
# chown -R root .
# chown -R mysql var
# chgrp -R mysql .
# bin/mysqld_safe --user=mysql &
# /usr/local/mysql/bin/mysqladmin -u root password 'Your Pass'
有时候会提示你的client版本过低,让你升级,那么你只要下载一个和你编译的server端一样的client端的rpm包就可以了,比如我在我的RHEL3U5上安装mysql-5.0.18的时候就碰到过这样的问题,我安装了MySQL-client-standard-5.0.18-0.rhel3.i386.rpm就解决了。升级完client端我们要进入mysql做一些安全设置。

# mysql -uroot -p
输入root 的password
//蓝色为可忽略

mysql> use mysql;
mysql> delete from user where Password='';
mysql> flush privileges;
mysql> quit
# cp /usr/local/mysql/share/mysql/mysql.server /etc/rc.d/init.d
# cd /etc/rc.d/init.d
# chmod 500 mysql.server
# cd /etc/rc.d/rc3.d
# ln -s ../init.d/mysql.server S99mysql
# ln -s ../init.d/mysql.server K99mysql
到此mysql安装完成。
注意:如果要加入自启动可以在/etc/rc.d/rc.local下写入/usr/local/mysql/bin/mysqld_safe --user=mysql &

<运维> 谢文斌 - 电话-13054408341 说: (2010-08-31 15:03:04)
你安装这个步骤做。肯定没有问题的





ip:61.191.63.90
系统:centos 5.0


1,下载软件 wget url
apache          
http://apache.etoak.com/httpd/httpd-2.2.11.tar.bz2
php             http://cn.php.net/distributions/php-5.2.9.tar.bz2
mysql           http://mysql.mirror.tw/Downloads/MySQL-5.0/mysql-5.0.77.tar.gz
libevent        http://www.monkey.org/~provos/libevent-1.4.9-stable.tar.gz
memcached       http://memcached.googlecode.com/files/memcached-1.2.7.tar.gz
php memecache   http://pecl.php.net/get/memcache-2.2.5.tgz
mysql 安装
tar -zxvf mysql-5.1.33.tar.gz
cd mysql-5.1.33
./configure --prefix=/usr/local/mysql --with-client-ldflags=-all-static
以纯静态方式编译服务端和客户端  
--with-mysqld-ldflags=-all-static --enable-assembler (使用一些字符函数的汇编版本


--with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charset=all

发生错误:缺少
lstdc++
rmp -q libstdc++-devel 确实没有

yum install libstdc++-devel  
安装MYSQL出现checking for termcap functions library… configure: error: No curses/termcap library found

Filed under: 杂七杂八

如果编译时出现了以下错误:
checking for tgetent in -ltermcap… no
checking for termcap functions library… configure: error: No curses/termcap library found
说明 curses/termcap 库没有安装
去下载一个ncurses-5.6.tar.gz,
wget http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.6.tar.gz
tar zxvf ncurses-5.6.tar.gz
cd ncurses-5.6
./configure –prefix=/usr –with-shared –without-debug
make
make install clean
然后再重新编译Mysql进行安装。



设置:
groupadd mysql
useradd mysql -g mysql -d /nonexistent -s /usr/sbin/nologin
cd /usr/local/mysql
#
文件属主修改
chown -R root .
chown -R mysql var
chgrp -R mysql .

#安装初始表,授权表
bin/mysql_install_db --user=mysql
#
复制配置文件到当前目录
cp share/mysql/my-medium.cnf ./var/my.cnf
#
启动mysql
bin/mysqld_safe --user=mysql &
方式
2
cp share/mysql/mysql.server /usr/local/mysql/mysql.sh
chmod u+x mysql.sh
./mysql.sh start

修改root密码,删除空帐号
保留localhost的root帐号
mysql> use mysql;
mysql> delete from user where user!='root' or host!='localhost';
mysql> update user set password=password('newpassword') where user='root';
mysql> FLUSH PRIVILEGES;


apache 安装 模块化
tar -jxvf httpd-2.2.11.tar.bz2
cd httpd-2.2.11
./configure --prefix=/usr/local/apache2 --enable-so --enable-mods-shared=most --disable-cgi --disable-cgid --enable-expire --enable-rewrite
make && make install
修改配置文件
conf/httpd.conf 去掉前面的注释

        Include conf/extra/httpd-mpm.conf
        Include conf/extra/httpd-vhosts.conf

conf/extra/httpd-mpm.conf
        <IfModule mpm_prefork_module>
        ServerLimit 3000
        StartServers          5
        MinSpareServers       5
        MaxSpareServers      10
        MaxClients           2000
        MaxRequestsPerChild   0
        </IfModule>

conf/extra/httpd-vhosts.conf

php 安装
gd相关软件:(都采用默认路径安装)
freetype-2.3.5.tar.bz2
gd-2.0.35.tar.bz2
gettext-0.17.tar.gz
jpegsrc.v6b.tar.gz
libiconv-1.12.tar.gz
libmcrypt-2.5.8.tar.bz2
libpng-1.2.26.tar.bz2
libxml2-2.6.32.tar.gz
mcrypt-2.6.7.tar.gz
mhash-0.9.9.9.tar.bz2
zlib-1.2.3.tar.bz2

1 安装zlib
./configure
make
make install

2 安装libpng
libpng-devel
./configure
make
make install

3 安装freetype
freetype-devdel
./configure
make
make install

4 安装jpeg
tar zxvf jpegsrc.v6b.tar.gz
cd jpeg-6b/
./configure --enable-shared
make
make install
注意,这里configure一定要带--enable-shared参数,不然,不会生成共享库

报错 /usr/bin/install -c -m 644 ./cjpeg.1 /home/zz/jpeg-6b/jpeg/man/man1/cjpeg.1
在/usr/local下面建立 /bin   /include  /lib /man/man1.看哪个没有建立哪个

5 安装gettext
./configure
make
make install

6 安装libmcrypt
./configure
make
make install
遇到错误:Could not run libmcrypt test program, checking why...
yum install libmcrypt.i386
yum install libmcrypt-devel.i386
遇到错误:
configure: error: "You need at least libmhash 0.8.15 to compile this program. http://mhash.sf.net/"
wget
http://nchc.dl.sourceforge.net/sourceforge/mhash/mhash-0.9.9.9.tar.bz2
cd mhash-0.9.9
./configure
make && make install
修改/etc/ld.so.conf
添加 /usr/local/lib

7 安装 libiconv
./configure
make
make install

8 安装 libxml2
./configure
make
make insta

8.1 安装 mhash-0.0.9  
./configure


make
; make install


8.2 安装yum install libXpm-3.5
libXpm-devdel

9
安装 libmcrypt

./configure -enable-ltdl-install
make
make install

10 安装gd(要安装新的GD)
./configure --with-png=/usr/local --with-freetype --with-jpeg
make
make install


安装php
./configure --prefix=/usr/local/php5 --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir=/usr/local --with-zlib --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-gettext --enable-mbstring --with-mcrypt --with-mhash --with-iconv --with-jpeg-dir=/usr/local/lib --with-freetype-dir=/usr/local/lib --with-xpm-dir=/usr/local --with-gd=/usr/local

错误:mhash
./configure

出现错误:/usr/bin/ld: cannot find –lltdl

解决:

cd /usr/share/libtool/libltdl
./configure --prefix=/usr
make
make install

出错:configure: error: Please reinstall libmhash - I cannot find mhash.h  
安装:yum install mhash-deve


出现错误:error: xml2-config not found. Please check your libxml2
安装libxml2-devdel ;libxml2-1.2
ok


出现错误errorlibXpmo|s  
yum libxpm-devdel


出现错误:报错mysql找不到包头文件
解决:yum install mysql-devel


出现错误:/opt/software/php-5.2.9/sapi/cli/php: error while loading shared libraries: /usr/local/lib/libgd.so.2: cannot restore segment prot after reloc: Permission denied
make[1]: *** [install-pear-installer] 错误
127
make: *** [install-pear] 错误
2
解决:

        编辑/etc/selinux/config,找到这段:
        # This file controls the state of SELinux on the system.
        # SELINUX= can take one of these three values:
        # enforcing - SELinux security policy is enforced.
        # permissive - SELinux prints warnings instead of enforcing.
        # disabled - SELinux is fully disabled.
        SELINUX=enforcing


把 SELINUX=enforcing 注释掉:#SELINUX=enforcing ,然后新加一行为:

        SELINUX=disabled
        
保存,关闭。
        ......

编辑/etc/sysconfig/selinux,找到
:
        # This file controls the state of SELinux on the system.
        # SELINUX= can take one of these three values:
        # enforcing - SELinux security policy is enforced.
        # permissive - SELinux prints warnings instead of enforcing.
        # disabled - SELinux is fully disabled.
        SELINUX=enforcing


如果SELINUX已经是 SELINUX=disabled,那么就不用改了,否则就把SELINUX=enforcing 注释掉,新加一行:

        SELINUX=disabled
        
保存,退出。

如果你碰到其他类似提示:

        cannot restore segment prot after reloc: Permission denied
        
哪应该是SELinux的问题,可以考虑把它关闭。
        -------------------------------------------------------------------------------------
        
郁闷的是.我把SELinux关闭后还是不行.于是到google上search.发现这个很有用.
        在你保证SElinux 被disable后.还执行下

        chcon -t texrel_shlib_t
        
如: chcon -t texrel_shlib_t /路径/路径/名字.so   (这个文件视具体执行文件.)

以上两步.已经解决了很多server的问题了.

修改apache配置文件 httpd.conf
增加
<IfModule php5_module>
<FilesMatch "\.php$">
AddType application/x-httpd-php .php
</FilesMatch>
</IfModule>


memcached安装:
安装libevent:
libevent-1.4.9-stable
./configure –prefix=/usr
make
make install

安装memecached:
./configure --with-libevent=/usr
make && make install


安装memcache的php模块
cd memcache
/usr/local/php/bin/phpize
./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config --with-zlib-dir
make && make install

把php.ini中的extension_dir = “./”修改为
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-2007xxxx/"
添加一行来载入memcache扩展:extension=memcache.so
启动memcached:/usr/local/bin/memcached -d -p 12006 -u nobody -l 127.0.0.1 -m 128
/usr/local/bin/memcached -d -p 12007 -u nobody -l 127.0.0.1 -m 128


站点配置(注意rewrite的配置):
<VirtualHost *:80>
ServerAdmin
rendong237@126.com
DocumentRoot "/xxxx/sitecode/front/htdocs/"
ServerName      
www.xxxx.com
ServerAlias www.xxxx.com
ErrorLog "logs/xxxx.com-error_log"
CustomLog "logs/xxxx.com-access_log" common
</VirtualHost>

<Directory /xxxx/sitecode/front/htdocs/>
RewriteEngine on
RewriteRule !\.(js|ico|gif|jpg|png|css|swf|html|xml|url)$ index.php
Options -Indexes FollowSymLinks
AllowOverride None
Order deny,allow
Allow from all
</Directory>
  




./configure --prefix=/usr/local/mysql --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --enable-assembler --with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charset=all

本帖最近评分记录: 1 条评分
霸王硬上弓 飞扬币 +10 2010-11-23 社区因为有您的参与更精彩!
 
我不喜欢说话却每天说最多的话,我不喜欢笑却总笑个不停,身边的每个人都说我的生活好快乐,于是我也就认为自己真的快乐。可是为什么我会在一大群朋友中突然地就沉默,为什么在人群中看到个相似的背影就难过,看见秋天树木疯狂地掉叶子我就忘记了说话,看见天色渐晚路上暖黄色的灯火就忘记了自己原来的方向。
级别: 管理员
发帖
28282
飞翔币
1597
威望
888
飞扬币
132492
信誉值
0

只看该作者 1 发表于: 2010-11-23
现在nginx更迎合主流,centos下更好的搭档,fastcgi性能提升到最大。轻量级产品。同时在转发和负载均衡上nginx有无法比拟的优越性
不过apache的兼容性更好,其支持的模块也是相当的多的,这点是nginx不可比的

http://blog.s135.com/nginx_book/

学习nginx,这本书不错的。

级别: 管理员
发帖
28282
飞翔币
1597
威望
888
飞扬币
132492
信誉值
0

只看该作者 2 发表于: 2010-11-23
  Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/  
  
SMTP 代理服务器。 Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,它已经在该站点运行超过两年半了。Igor 将源代码以类BSD许可证的形式发布。尽管还是测试版,但是,Nginx 已经因为它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名了。
  Nginx 可以在大多数 Unix like OS 上编译运行,并有 Windows 移植版。目前 Nginx 的开发版为 0.7.x,稳定版为 0.6.x,历史稳定版为 0.5.x,建议使用 0.6 系列作为生产版本。 Nginx 的源代码使用 2-clause BSD-like license。

Nginx 是一个很牛的高性能Web和反向代理服务器, 它具有有很多非常优越的特性:
  在高连接并发的情况下,Nginx是Apache服务器不错的替代品: Nginx在美国是做虚拟主机生意的老板们经常选择的软件平台之一. 能够支持高达 50,000 个并发连接数的响应, 感谢Nginx为我们选择了 epoll and kqueue作为开发模型.
  Nginx作为负载均衡服务器: Nginx 既可以在内部直接支持 Rails 和 PHP 程序对外进行服务, 也可以支持作为 HTTP代理服务器对外进行服务. Nginx采用C进行编写, 不论是系统资源开销还是CPU使用效率都比 Perlbal 要好很多.
  作为邮件代理服务器: Nginx 同时也是一个非常优秀的邮件代理服务器(最早开发这个产品的目的之一也是作为邮件代理服务器), Last.fm 描述了成功并且美妙的使用经验.
  Nginx 是一个 安装非常的简单 , 配置文件 非常简洁(还能够支持perl语法), Bugs非常少的服务器: Nginx 启动特别容易, 并且几乎可以做到7*24不间断运行,即使运行数个月也不需要重新启动. 你还能够 不间断服务的情况下进行软件版本的升级.
  查看Nginx更多的特性: Feature Overview