阿里云Centos6.3,LANP安装

最近准备弄一个服务器放置一些示例Demo,决定使用LANP架构,在此把安装过程记录下来。

服务器选用阿里云最低配置

cup: 单核

内存:512

带宽:1M

系统:centos6.3 64位

第一步:

yum groupinstall -y *Development Tools*  安装开发工具包 [工具包有些大,耐心..]

=====编译nginx =====


下载Nginx , nginx.org

选择一个稳定版

http://nginx.org/en/download.html

http://nginx.org/download/nginx-1.4.4.tar.gz

tar -zxvf  nginx-1.4.4.tar.gz

cd nginx-1.4.4

./configure 编译

[

        可能出现的错误

       ./configure: error: the HTTP rewrite module requires the PCRE library.

        yum解决: yum -y install pcre-devel

        从新 ./configure 编译

]

make 

make install 

注: 如有错误,使用yum解决

默认安装目录

/usr/local/nginx

主配置文件:  conf/nginx.conf

启动文件:  sbin/nginx

运行启动文件  ./nginx

ps -ef | grep nginx 查看进程

nobody    6304  6303  0 14:21 ?        00:00:00 nginx: worker process

netstat -tupln   查看端口监听情况  

tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      6303/nginx 

=====编译mysql =====


安装cmake包

wget http://www.cmake.org/files/v2.8/cmake-2.8.6.tar.gz

tar zxvf cmake-2.8.6.tar.gz

cd cmake-2.8.6/

./configure

 gmake

 gmake install  




添加用户和创建数据库目录和权限设置


useradd mysql

mkdir -p /data/mysql

chown -R root:mysql /data/mysql



 

下载安装mysql

选择一个mysql版本的源代码 http://dev.mysql.com/downloads/

wget  http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.35.tar.gz

 

tar -zxvf mysql-5.5.17.tar.gz

cd mysql-5.5.17

cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc/

gmake

gmake install


设置mysql配置文件 

cd /usr/local/mysql

cp ./support-files/my-huge.cnf /etc/my.cnf 

编辑/etc/my.cnf

vi /etc/my.cnf

在 [mysqld] 段增加

datadir = /data/mysql

wait-timeout = 30

max_connections = 512

max_connect_errors = 10000000

default-storage-engine = INNODB


在 [mysqld] 段修改

max_allowed_packet = 16M 

初始化数据库

 

./scripts/mysql_install_db --datadir=/data/mysql --basedir=/usr/local/mysql  --defaults-file=/etc/my.cnf --user=mysql

cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld

chmod 755 /etc/rc.d/init.d/mysqld

chkconfig --add mysqld


设置启动脚本变量 

编辑 /etc/rc.d/init.d/mysqld

vi /etc/rc.d/init.d/mysqld

basedir=/usr/local/mysql

datadir=/data/mysql 


设置变量环境

 echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile (永久生效) 

启动服务


service mysqld start

设置数据库管理员root密码

mysqladmin -u root password 你的密码

service mysqld restart

进入mysql

mysql -uroot -p


===== 编译php  ======



安装    RepoForge    yum源

RepoForge.org 点击 usage 

下载对应centos 版本

EL 6: i686, x86_64

EL 5: i386, x86_64, ppc

EL 4: i386, x86_64, ppc

EL 3: i386, x86_64


rpm -q centos-release  查看版本

cd ~

wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm

rpm -ivh rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm 

从新更新yum 源

yum clean all

yum list


查看yum安装的php程序

yum list | grep php

如果有,把安装的php卸载干净

yum remove php php-devel php-mysql  php-mysqli php-pdo php-gd php-mbstring  …. 


预先安装php工具包

yum install -y libxml2-devel libjpeg-devel libpng-devel freetype-devel openssl-devel libcurl-devel libmcrypt-devel


下载php源代码

php.net  => downloads

 wget http://cn2.php.net/distributions/php-5.4.24.tar.gz

 tar -zxvf php-5.4.24.tar.gz 

cd php-5.4.24


执行

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --disable-fileinfo  --with-mysql=/usr/local/mysql  --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-magic-quotes --enable-safe-mode --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlweappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --with-mime-magic


make  


#注意这里容易出现 make: *** [ext/phar/phar.php] 错误 127

#出现mysql client解决方法 

32位系统

ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/

64位系统

ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/

make 

make install


php会被安装在

--prefix=/usr/local/php

切换到该目录

cd /usr/local/php

[root@localhost php]# ls

bin  etc  include lib php sbin var

cd /usr/local/php/sbin 会有一个运行PHP程序

[root@localhost sbin]# ls

php-fpm


cd /usr/local/php/etc

启动配置文件

mv php-fpm-default.conf  php-fpm-conf

php.ini 配置文件

cp ~/php-5.4.24/php.ini-production /usr/local/php/etc/php.ini

[root@localhost etc]# ls

php-fpm.conf  php.ini

cd  /usr/local/php/sbin

执行  ./php-fpm  没有报错代表执行成功


ps aux | grep php  查看进程


root     21609  0.0  0.4 201908  4328 ?        Ss   23:02   0:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)

nobody   21610  0.0  0.4 201912  4520 ?        S    23:02   0:00 php-fpm: pool www

nobody   21611  0.0  0.5 201912  5588 ?        S    23:02   0:00 php-fpm: pool www

root     21658  0.0  0.0 103244   864 pts/0    S+   23:24   0:00 grep php


netstat -tupln  查看端口监听

默认会监听9000端口,通过配置项  php-fpm-conf 指定

tcp        0      0 127.0.0.1:9000     0.0.0.0:*     LISTEN      21609/php-fpm


修改nginx配置

vim /usr/local/nginx/conf/nginx.conf

修改默认配置项为

location ~ \.php$ {

     root           html;

     fastcgi_pass   127.0.0.1:9000; //端口

     fastcgi_index  index.php;

     fastcgi_param  SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;  //网站跟地址

     include        fastcgi_params;

}

重启nginx 

killall nginx   

cd  /usr/local/nginx/sbin/   

./nginx


新建php文件

vim /usr/local/nginx/html/index.php

输入

<?php

phpinfo();

访问 http://你的ip地址/index.php

访问正常, 配置成功!

* 重启php-fpm出现无法加载配置文件的时候指定 *

./php-fpm --fpm-config /usr/local/php/etc/php-fpm.conf -c /usr/local/php/etc/php.ini


=====eaccelerator加速=====



安装 eaccelerator加速

下载eaccelerator

官网:http://eaccelerator.net/

github:https://github.com/eaccelerator/eaccelerator


unzip eaccelerator-master.zip

cd eaccelerator-master


/usr/local/php/bin/phpize 

编译时指定php-config 位置

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

make 

make install

在php.ini 添加eaccelerator配置

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


;eaccelerator配置段开始

extension="eaccelerator.so"

eaccelerator.shm_size="16"

eaccelerator.cache_dir="/tmp/eaccelerator"

eaccelerator.enable="1"

eaccelerator.optimizer="1"

eaccelerator.check_mtime="1"

eaccelerator.debug="0"

eaccelerator.filter=""

eaccelerator.shm_ttl="0"

eaccelerator.shm_prune_period="0"

eaccelerator.shm_only="0"

;eaccelerator配置段结束

创建缓存目录

mkdir 0777 /tmp/eaccelerator


访问刚才的 index.php,出现下面信息代表安装成功 



=====安装redis以及php-redis扩展=====


安装redis

下载redis


wget http://redis.googlecode.com/files/redis-2.4.11.tar.gz

tar -zxvf redis-2.4.11.tar.gz 

cd redis-2.4.11

make 

make install 

cp redis.conf /etc/redis.conf

vim /etc/redis.conf 

daemonize no 改为 daemonize yes  让redis后台运行


下载php-redis扩展

https://github.com/owlient/phpredis

unzip master-redis.zip

cd phpredis-master/

/usr/local/php/bin/phpize

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

make 

make install


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

extension=redis.so


=====安装memcache以及php-memcache扩展=====



安装memcached扩展

由于memcached安装时,需要使用libevent类库,所以先安装libevent

wget http://www.monkey.org/~provos/libevent-2.0.12-stable.tar.gz

tar -zxvf libevent-2.0.12-stable.tar.gz


cd libevent-2.0.12-stable

 ./configure

make

make install

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

tar -zxvf memcached-1.4.5.tar.gz 

cd memcached-1.4.5

./configure  --prefix=/usr/local/memcached

make 

make install 



cd /usr/local/memcached/bin

./memcached

* 出现的错误 *

出现“memcached: error while loading shared libraries:libevent-2.0.so.5: cannot

open shared object file: No such file or directory”之类的信息,表示memcached 找不到

libevent 的位置

所以,请先使用whereis libevent 得到位置,然后连接到memcached 所寻找的路径

首先查看,libevent 在哪里

# whereis libevent

libevent: /usr/local/lib/libevent.la /usr/local/lib/libevent.so /usr/local/lib/libevent.a

然后,再看memcached 从哪里找它

# LD_DEBUG=libs memcached -v 2>&1 > /dev/null | less

可以看到:是/usr/lib64/libevent-2.0.so.5,所以,创建软链

ln -s /usr/local/lib/libevent-2.0.so.5 /usr/lib64/libevent-2.0.so.5

./memcached -u root -d



安装php-memcache 扩展

下载:http://pecl.php.net/package/memcache

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

cd memcache-2.2.4

/usr/local/php/bin/phpize

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

make 

make install 

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

extension=memcache.so



本次所用到的软件下载

http://pan.baidu.com/s/1o6hSPJ0


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值