在Centos下编译安装前Nginx,处理小型程序。大程序交给Apache。

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

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

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

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

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

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

Apache下载地址:http://httpd.apache.org/download.cgi

[root@meeli02 yaoleisoft]#wget http://apache.dataguru.cn//httpd/httpd-2.2.24.tar.gz

[root@meeli02 yaoleisoft]# tar zxvf httpd-2.2.24.tar.gz

[root@meeli02 yaoleisoft]# cd ./httpd-2.2.24

[root@meeli02 httpd-2.2.24]# ./configure --prefix=/usr/local/webserver/apache2/ --enable-proxy --enable-ssl --enable-cgi --enable-rewrite --enable-so --enable-module=so

[root@meeli02 httpd-2.2.24]#make

[root@meeli02 httpd-2.2.24]#make install

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

启动

[root@meeli02 webserver]# /usr/local/webserver/apache2/bin/apachectl start

[root@meeli02 webserver]# vim /usr/local/webserver/apache2/conf/httpd.conf

重启

[root@meeli02 webserver]# /usr/local/webserver/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/conf/httpd.conf在

#serverName www.example.com:80

这个位置修改为:

serverName localhost:80

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

防火墙设置

[root@meeli02 home]# /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT

[root@meeli02 home]# /sbin/iptables -I INPUT -p tcp --dport 22 -j ACCEPT

[root@meeli02 home]# /etc/rc.d/init.d/iptables save

查看防火墙状态:

[root@meeli02 home]# service iptables status

停止防火墙:

[root@localhost ~]# service   iptables stop

启动防火墙:

[root@localhost ~]# service   iptables start

重启防火墙:

[root@localhost ~]# service   iptables restart

永久关闭防火墙:

[root@localhost ~]# chkconfig   iptables off

永久关闭后启用:

[root@localhost ~]# chkconfig   iptables on

80端口被其他程序占用,
 fuser -k -n tcp 80
再重新启动。
----------------------------------------------

卸载apache

如果是源码安装

#rm   -rf   你的apache安装路径

同样作用于其他

YUM方式安装的,这样卸载

#yum remove httpd

否则要用

#rpm -qa|grep httpd

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

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

第二步 Mysql安装MySQL 5.5.3-m3

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

[root@meeli02 home]# /usr/sbin/groupadd mysql
[root@meeli02 home]# /usr/sbin/useradd -g mysql mysql
[root@meeli02 home]# tar zxvf mysql-5.5.3-m3.tar.gz

[root@meeli02 home]# cd mysql-5.5.3-m3/

[root@meeli02 mysql-5.5.3-m3]# ./configure --prefix=/usr/local/webserver/mysql/ --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-plugins=partition,innobase,myisammrg
[root@meeli02 mysql-5.5.3-m3]# make && make install
[root@meeli02 mysql-5.5.3-m3]# chmod +w /usr/local/webserver/mysql
[root@meeli02 mysql-5.5.3-m3]# chown -R mysql:mysql /usr/local/webserver/mysql
[root@meeli02 mysql-5.5.3-m3]# cd ../

mkdir -p /home/mysql/3306/data/
mkdir -p /home/mysql/3306/binlog/
mkdir -p /home/mysql/3306/relaylog/
chown -R mysql:mysql /home/mysql/

以mysql用户帐号的身份建立数据表:

[root@meeli02 mysql]# /usr/local/webserver/mysql/bin/mysql_install_db --basedir=/usr/local/webserver/mysql --datadir=/home/mysql/3306/data --user=mysql

创建my.cnf配置文件:vi /data0/mysql/3306/my.cnf

创建管理MySQL数据库的shell脚本:vi /data0/mysql/3306/mysql


赋予shell脚本可执行权限:

chmod +x /home/mysql/3306/mysql

启动MySQL:

[root@meeli02 3306]# /home/mysql/3306/mysql start

通过命令行登录管理MySQL服务器(提示输入密码时直接回车):

/usr/local/webserver/mysql/bin/mysql -u root -p -S /tmp/mysql.sock

输入以下SQL语句,创建一个具有root权限的用户(admin)和密码(12345678):

GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' IDENTIFIED BY 'zxcv123';
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'127.0.0.1' IDENTIFIED BY 'zxcv123';

停止MySQL:

/home/mysql/3306/mysql stop

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

第三步 PHP安装(已更新到5.4.16版)

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

jpegsrc.v7.tar.gz

libpng-1.2.39.tar.gz

zlib-1.2.3.tar.gz

freetype-2.3.9.tar.gz

包安装介绍:http://blog.163.com/yuang_yu_ping/blog/static/469328762011532516810/

./configure --prefix=/usr/local/webserver/php --with-apxs2=/usr/local/webserver/apache2/bin/apxs --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-config-file-path=/usr/local/webserver/php/etc --with-zlib --with-libxml-dir --with-gd --with-freetype-dir --with-jpeg-dir --with-png-dir --with-ttf --with-openssl --with-mcrypt --enable-sockets --enable-bcmath --enable-calendar --enable-exif --enable-libxml --enable-magic-quotes --enable-mbstring --with-bz2 --with-curl --with-xmlrpc --with-gettext --enable-suhosin --disable-debug --enable-zip --enable-gd-native-ttf --enable-shmop --disable-rpath --enable-sysvsem --enable-sysvshm --enable-inline-optimization --with-curlwrappers --enable-mbregex --with-mhash --with-ldap --with-ldap-sasl --enable-soap [root@meeli02 php-5.4.8]# make ZEND_EXTRA_LIBS='-liconv' && make install
第二次编译增加 fpm
./configure --prefix=/usr/local/webserver/php --with-apxs2=/usr/local/webserver/apache2/bin/apxs --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-config-file-path=/usr/local/webserver/php/etc --with-zlib --with-libxml-dir --with-gd --with-freetype-dir --with-jpeg-dir --with-png-dir --with-ttf --with-openssl --with-mcrypt --enable-sockets --enable-bcmath --enable-calendar --enable-exif --enable-libxml --enable-magic-quotes --enable-mbstring --with-bz2 --with-curl --with-xmlrpc --with-gettext --enable-suhosin --disable-debug --enable-zip --enable-gd-native-ttf --enable-shmop --disable-rpath --enable-sysvsem --enable-sysvshm --enable-inline-optimization --with-curlwrappers --enable-mbregex --with-mhash --with-ldap --with-ldap-sasl --enable-soap --enable-fastcgi --enable-fpm --enable-force-cgi-redirect
[root@meeli02 php-5.4.8]# make ZEND_EXTRA_LIBS='-liconv' && make install

5.5为php-fpm提供Sysv init脚本,并将其添加至服务列表 切换到编译包

#cd /home/yaoleisoft/php-5.4.8/sapi/fpm
[root@meeli02 fpm]# cp init.d.php-fpm /etc/init.d/php-fpm
[root@meeli02 fpm]# chmod +x /etc/init.d/php-fpm [root@meeli02 fpm]# /etc/init.d/php-fpm start
# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
# chmod +x /etc/rc.d/init.d/php-fpm
# chkconfig --add php-fpm
# chkconfig php-fpm on

5.6为php-fpm提供配置文件

# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

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

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

如果提示: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

修改www的默认文件地址DocumentRoot

注意还要修改Directoty的路径和上面的一样

重启httpd

测试php文件

phpinfo()

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

执行php文件

#/usr/local/php/bin/php    xx.php

php 时区设置 :http://www.cnblogs.com/kakaxi/archive/2011/08/05/2128442.html

加速器:

PHP安装eAccelerator

安装(fastcgi模式)的时候,常常有这样一句命令:/usr/local/webserver/php/bin/phpize一、phpize是干嘛的?phpize是什么东西呢?php官方的说明:http://php.net/manual/en/install.pecl.phpize.php

phpize是用来扩展php扩展模块的,通过phpize可以建立php的外挂模块

比如你想在原来编译好的php中加入memcached或者ImageMagick等扩展模块,可以使用phpize,通过以下几步工作。

二、如何使用phpize?

当php编译完成后,php的bin目录下会有phpize这个脚本文件。在编译你要添加的扩展模块之前,执行以下phpize就可以了;

比如现在想在php中加入memcache扩展模块:我们要做的只是如下几步

————————————————————————

tar zxvf memcache-2.2.5.tgz

cd memcache-2.2.5/

/usr/local/webserver/php/bin/phpize

./configure –with-php-config=/usr/local/webserver/php/bin/php-config

make

make install

————————————————————————

注意./configure 后面可以指定的是php-config文件的路径

这样编译就完成了,还需要做的是在php.ini文件中加入extension值

extension = “memcache.so”

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

注意:Cannot find config.m4.

这个错误是一个很傻的错误,解压以后需要cd到文件夹,不然phpize就会报错

动态编译PHP的memcache扩展库,在执行/usr/localphp/bin/phpize时出现了错误,
Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable is set correctly and then rerun this script.
很明显缺少文件,需要安装。网上找了下资料。
# wget http://ftp.gnu.org/gnu/m4/m4-1.4.9.tar.gz
# tar -zvxf m4-1.4.9.tar.gz
# cd m4-1.4.9/
# ./configure && make && make install
# cd ../
# wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.62.tar.gz
# tar -zvxf autoconf-2.62.tar.gz
# cd autoconf-2.62/
# ./configure && make && make install
然后执行以下命令进行安装
#/usr/local/php/bin/phpize
#./configure –prefix=/usr/local/memcached –with-libevent=/usr/local/libevent –with-php-config=/usr/local/php/bin/php-config
#make && make install

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

第四步 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

注意这里选择libevent的位置即可  例如你的是在–with-libevent=/usr/local/libevent/

#make

#make install

启动

[root@meeli02 memcached-1.4.15]# /usr/local/webserver/memcached/bin/memcached -d -m 100 -uroot -l 0.0.0.0 -p 11211 -c 512 -P /usr/local/webserver/memcached/memcached.pid

/usr/local/webserver/memcached/bin/memcached -d -m 100 -u root -l 127.0.0.1 -p 11211 -c 512 -P  /usr/local/webserver/memcached/memcached.pid

#/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/webserver/php/bin/phpize

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

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

或者

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

#make

#make install

# vim /usr/local/webserver/php/etc/php.ini

php.ini添加

extension=memcache.so

<完>

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

重启

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

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

$memcache = new Memcache; //创建一个memcache对象   

$memcache->connect('localhost', 11211) or die ("Could not connect"); //连接Memcached服务器   

$memcache->set('key', 'test'); //设置一个变量到内存中,名称是key 值是test   

$get_value = $memcache->get('key'); //从内存中取出key的值   

echo $get_value;  

CentOS真是太好用了。尤其是那个yum命令,装东西真是太简单了,自己连配置都不用。所以这篇文章没什么技术含量,主要是来记录我安装过程中遇到的一些问题。和大家分享一下。

DiscuzX 1.0开始对一些常见的缓存和内存优化系统进行了支持,比如Memcached、Eaccelerator、Xcache。但是对Eaccelerator的支持貌似有一些莫名其妙的问题。比如版本太高了不行,而且不能用yum等方式安装,安装的时候要加特定的参数–enable-shared-memory,所以我虽然装好了,在phpinfo里面也能看到,但是在DX后台里面就是看不到。我想算了,那就装一个memcached用一用吧。于是,在网上搜了一些安装方法,发现大多数都是wget然后自己去配置安装的。我不是很喜欢这样,所以决定尝试yum方式安装。

先yum search一下。发现有这个包。于是yum install memcached。顺利安装好。此时,可以编辑/etc/sysconfig/memcached这个文件配置一下memcached。

1 PORT="11211"   #配置memcached使用的端口
2 USER="nobody"  #配置它启动使用的用户
3 MAXCONN="2048" #最大并发连接
4 CACHESIZE="64"  #最大使用内存,这里是指64M
5 OPTIONS=""  #其它的配置参数

配置好之后,我们再安装memcached对php的扩展module。

yum search memcache的时候,还找到了如下几个包:

php-pecl-memcache      x86_64  #这个是网上一般常用的包。

php-memcache      x86_64  #这个是我找到的一个包。

我按照网上的教程,使用php-pecl-memcache这个包的话,安装完之后,运行php -v发现有问题。提示module在编译的时候参数不对,有一个api不匹配。具体的错误信息找不到了,无法贴出来了,大体就这个意思。没办法,我猜是因为php版本过新,而php-pecl-memcache这个包稍微旧了一些的缘故。因为php我是用另外一个源更新到了5.2.6,而且刚才yum搜到的php-memcache也正是这个源提供的,于是我尝试安装了一下这个包php-memcache,一切正常,而且phpinfo里面也显示了!

这时候还没完。要启动memcached服务器才行。运行下面的命令即可。

1 memcached -d -u root -m 64 -c 1024

Memcached参数说明:

  • -d选项是启动一个守护进程
  • -m分配给Memcache使用的内存数量,单位是MB
  • -u运行Memcache的用户
  • -l监听的服务器IP地址
  • -p设置Memcache监听的端口,最好是1024以上的端口
  • -c最大运行的并发连接数,默认是1024,按照你服务器的负载量来设定
  • -P设置保存Memcache的pid文件

接下来我们设置让memcached自动启动,防止系统重启后memcached失效。

1 chkconfig --add memcached

然后检查一下是否设置成功。

1 chkconfig --list memcached

如果2~5写的是on的话说明设置成功。但是在一些CentOS版本中,–add命令无法成功,可以用下面的语句代替:

1 chkconfig memcached on

然后再次检查一下,一般不会有问题了,只要2~5设置为on,那么memcached就已经会随着系统自动启动了。

至此,memcached即可使用,在DiscuzX的后台管理面板中也可以看到并且使用了。


» 版权所有:YaoLei's Blog » Centos+Nginx+Apache+Mysql+Php
» 本文链接:https://www.yaolei.info/archives/320