PHP开发程序员Tech

CentOS6.4搭配LAMP环境

2014-08-15  本文已影响510人  Lin_小旻

首先最好一直在root用户下进行安装。

一、安装mysql

     1.安装编译环境

           yum -y install gcc gcc-c++ make cmake ncurses-devel bison

      *出现错误:

          Loaded plugins: fastestmirror, refresh-packagekit, security

          Loading mirror speeds from cached hostfile

          Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=6&arch=i386&repo=os error was

          14: PYCURL ERROR 6 - "Couldn't resolve host 'mirrorlist.centos.org'"

          Error: Cannot find a valid baseurl for repo: base

      *解决方法:

vim /etc/resolv.conf把文件改成:

    nameserver 8.8.8.8

    nameserver 8.8.4.4

     2.下载源码包

         wget http://sourceforge.net/projects/mysql.mirror/files/MySQL 5.6.19/mysql-5.6.19.tar.gz(url中有空格,请复制此url后在浏览器访问,这样空格会被转意,wget才能正常连接)

     3.解压

          tar -zxvf mysql-5.6.19.tar.gz

     4.进入目录

          cd mysql-5.6.19

     5.添加用户

          useradd -s /sbin/nologin mysql

     6. 编译配置

cmake -DMYSQL_USER=mysql -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DINSTALL_DATADIR=/data/mysql/data -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1

     7. 编译安装

          make && make install

     8.复制my-default.cnf文件到etc目录下

          cp /usr/local/mysql/support-files/my-default.cnf  /etc/

     9.复制/support-files/mysql.server到/etc/init.d下,重命名为mysqld

          cp /usr/local/mysql/support-files/mysql.server /etc/init.d

          cd /etc/init.d

    mv mysql.server mysqld

     10.创建data目录

          mkdir -p /data/mysql/data

    11. 关闭防火墙

          chkconfig iptables off

          vim /etc/selinux/config

          将/etc/selinux/config 中的 SELINUX=enforcing 改成SELINUX=disabled

    12.在/etc/my.cnf中添加/编辑

          打开my.cnf:

               vim /etc/my.cnf

          修改如下:

               [client]

               socket=/tmp/mysql.sock

               [mysqld]

               basedir=/usr/local/mysql

               datadir=/data/mysql/data

               socket=/tmp/mysql.sock

    13. 加入自启动

          chkconfig --level 345 mysqld on

    14.改变mysql目录用户组和权限

       cd /usr/local

       chmod 775 -R mysql

       chown -R mysql.mysql mysql

    15.改变data目录用户组和权限

          cd /data/mysql/

          chmod 775 -R data

          chown -R mysql.mysql data

     16.初始化数据

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

     17.添加mysql环境变量

        vim /etc/profile

         PATH_LIST=(

           '/usr/local/mysql/bin'

         );  

        for _path in ${PATH_LIST[@]};do

        PATH="$PATH:$_path"

        done

        export PATH

     18.重启

          init 6

     19.启动mysql

          service mysqld start

     20. 初始化账户

          /usr/local/mysql/bin/mysqladmin -u root password 'a123456'

     21. 连接数据库

          /usr/local/mysql/bin/mysql -u root -pa123456

二、安装Apache

     1. 安装编译环境

yum -y install gcc gcc-c++ autoconf automake makelibjpeg libjpeg-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-develglib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devele2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel opensslopenssl-devel openldap openldapdevel nss_ldap openldap-clients openldap-serverslibtool* mysql-devel

2. 下载源码

wget http://sourceforge.net/projects/apachehttp.mirror/files/httpd-2.2.22.tar.gz

3. 解压并进入目录

tar -zxvf httpd-2.2.22.tar.gz

cd httpd-2.2.22

4. 编译配置

./configure --prefix=/usr/local/apache --enable-so --enable-proxy --enable-rewrite --with-mpm=worker

5. 编译安装

make && make install

6. vim /usr/local/apache/conf/httpd.conf

搜索"#ServerName",在下面添加"ServerName localhost:80"

7. 启动Apache

/usr/local/apache/bin/apachectl start

三、安装PHP

1. 安装zlib

wget http://sourceforge.net/projects/libpng/files/zlib/1.2.8/zlib-1.2.8.tar.gz

tar -zxvf zlib-1.2.8.tar.gz

cd zlib-1.2.8

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

make && make install

2. 安装libpng

wget http://download.sourceforge.net/libpng/libpng-1.6.2.tar.gz

tar -zxvf libpng-1.6.2.tar.gz

cd libpng-1.6.2

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

make && make install

建立头文件软链

ln -s /usr/local/libpng/include/pngconf.h /usr/include

ln -s /usr/local/libpng/include/png.h /usr/include

将/usr/local/libpng/bin配置到环境变量

vim /etc/profile:

在这里面添加引号那行

PATH_LIST=(

    '/usr/local/libpng/bin'

    ); 

重启

3. 安装libjpeg

wget http://www.ijg.org/files/jpegsrc.v9.tar.gz

tar -zxvf jpegsrc.v9.tar.gz

cd jpeg-9

./configure --prefix=/usr/local/jpeg --enable-shared

make && make install

4. 安装freetype

wget http://sourceforge.net/projects/freetype/files/freetype2/2.5.0/freetype-2.5.0.tar.gz

tar -zxvf freetype-2.5.0.tar.gz

cd freetype-2.5.0

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

make && make install

5. 安装gd2

wget https://bitbucket.org/libgd/gd-libgd/downloads/libgd-2.1.0.tar.gz

tar -zxvf libgd-2.1.0.tar.gz

cd libgd-2.1.0

./configure --with-freetype=/usr/local/freetype --with-zlib=/usr/local/zlib --with-png=/usr/local/libpng --with-jpeg=/usr/local/jpeg --prefix=/usr/local/gd2

make && make install

6. 安装XPM

yum -y install *Xpm*

7. 安装libcurl-devel

yum -y install curl curl-devel

8. 安装PHP5.5.13

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

tar -zxvf /php-5.5.13.tar.gz

cd php-5.5.13

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc/ --with-gd=/usr/local/gd2 --with-apxs2=/usr/local/apache/bin/apxs --enable-mbregex --enable-bcmath --with-mysql --with-zlib-dir=/usr/local/zlib --enable-mbstring=all --with-pdo-mysql --with-freetype-dir=/usr/local/freetype --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr/local/libpng --with-xpm-dir=/usr/lib --with-openssl --with-curl --enable-pcntl

make && make install

9. 复制配置文件

cp php.ini-development /usr/local/php/etc/php.ini

10. vim /usr/local/php/etc/php.ini在这里进行你需要的配置修改

11. 将/usr/local/php/bin配置到环境变量

vim /etc/profile:

在这里面添加引号那行

PATH_LIST=(

    '/usr/local/php/bin'

    );  

12. vim /usr/local/apache/conf/httpd.conf

找到AddType application/x-gzip .gz .tgz,在下面添加

AddType application/x-httpd-php .php .phtml .inc .php3  

重启Apache

/usr/local/apache/bin/apachectl restart

四、安装memcached

1、安装libevent

     wget http://cloud.github.com/downloads/libevent/libevent/libevent-2.0.20-stable.tar.gz

     tar -zxvf libevent-2.0.20-stable.tar.gz

     cd libevent-2.0.20-stable

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

     make && make install

2、安装memcached

     wget http://www.memcached.org/files/memcached-1.4.20.tar.gz

      tar -zxvf memcached-1.4.20.tar.gz

      cd memcached-1.4.20

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

     make && make install

     添加环境标量  /usr/local/memcached/bin  到 /etc/profile

3、启动memcached守护进程

     memcached -d -m 64 -u root -l 127.0.0.1 -p 12000 -c 128 -P /tmp/memcached.pid

4、查看memcached状态

     telnet $host $port(如果系统中找不到telnet请看附录1)

     stats

5、安装libmemcached

  wget https://launchpad.net/libmemcached/1.0/1.0.16/+download/libmemcached-1.0.16.tar.gz

  tar -zxvf libmemcached-1.0.16.tar.gz

    cd libmemcached-1.0.16

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

     make && make install

   注:1.0.17无法完成扩展编译,应使用1.0.16版本

     6、安装memcahced php扩展

       wget http://pecl.php.net/get/memcached-2.2.0.tgz

       tar -zxvf memcached-2.2.0.tgz

cd memcached-2.2.0

phpize

     ./configure --with-php-config=/usr/local/php/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached --disable-memcached-sasl

          make && make test && make install

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

extension_dir = “./” 修改为:extension_dir = “/usr/local/php/lib/php/extensions/no-debug-non-zts-xxxxx/” 

       增加extension=memcached.so

五、安装redis

1. 安装Redis

wget http://download.redis.io/releases/redis-2.8.10.tar.gz

tar -zxvf redis-2.8.10.tar.gz && cd redis-2.8.10

make & make install

2. 将配置文件复制到/etc/目录下

cp redis.conf /etc/

3. 修改redis后台运行配置

vim /etc/redis.conf

将daemonize no修改为daemonize yes

4. 启动Redis

/usr/local/bin/redis-server /etc/redis.conf

执行ps -ef | grep redis|grep -v grep

显示类似下面的信息则说明启动成功

root 27243 1 0 16:46 ? 00:00:00 /usr/local/bin/redis-server /etc/redis.conf

5. 安装PHP Redis扩展

wget https://github.com/nicolasff/phpredis/archive/master.zip

unzip master && cd phpredis-master

/usr/local/php/bin/phpize

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

make && make install

6. 添加redis.so至php.ini

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

添加:

extension=redis.so

7. 重启apache 查看phpinfo()中的redis模块

附录1:

telnet: command not found:

 最近在使用telnet命令时,telnet: command not found,使用rpm -qa | grep telnet 查看,原来是没有安装telnet ,使用yum install telnet-server安装,却报This system is not registered with RHN.错误,原因是因为红帽中没有注册RHN。解决办法:更改yum的源,即更换/etc/yum.repos.d /rhel-debuginfo.repo 这个文件。进入/etc/yum.repos.d/目录,终端中输入wget http://docs.linuxtone.org/soft/lemp/CentOS-Base.repo即可在此目录下得到CentOS- Base.repo文件,这是centos的源文件,只需将其重命名为rhel-debuginfo.repo即可。yum install telnet-server telnet,安装完成后,编辑 # vim /etc/xinetd.d/telnet

找到 disable = yes 一行,将其改为: disable = no。重启服务:service xinetd restart。telnet使用成功。

上一篇下一篇

猜你喜欢

热点阅读