站点图标 IDC铺

Centos编译安装 LAMP (apache-2.4.7 + mysql-5.5.35 + php 5.4.8)

Centos编译安装 LAMP (apache-2.4.7 + mysql-5.5.35 + php 5.4.8)+ Redis 软件源代码包存放位置:/usr/local/src 源码包编译安装位置:/usr/local/软件名字 修改yum源: 1、[root@localhost ~]# cd /etc/yum.repos.d 进入存放源配置的文件夹 2、[root@localhost yum.repos.d]# mv ./CentOS-Base.repo ./CentOS-Base.repo.bak 备份默认源 3、[root@localhost yum.repos.d]# wget http://mirrors.163.com/.help/CentOS6-Base-163.repo 使用wget下载163的源 4、[root@localhost yum.repos.d]# mv CentOS6-Base-163.repo CentOS6-Base.repo 把下载下来的文件CentOS-Base-163.repo设置为默认源 5、[root@localhost ~]# yum -y install git 把git安装上去 关于git常用命令见 http://www.cnblogs.com/whoamme/p/3531387.html 6、[root@localhost ~]# yum -y install ntpdate 下载ntpdate时间同步包 7、[root@localhost ~]# ntpdate cn.pool.ntp.org 开始同步时间 一、关闭SELinux [root@localhost ~]# vim /etc/selinux/config SELINUX=enforcing 修改为SELINUX=disabled SELINUXTYPE=targeted 这一行 注释掉 :wq! 保存 关闭 退出! [root@localhost ~]# reboot 修改SELinux后 要重启系统 二、下载软件包 httpd-2.4.7.tar.gz:http://yunpan.cn/cdX8hJdN8zCgw 访问密码 f38d mysql-5.5.35.tar.gz:http://yunpan.cn/cdX8hTFfU2zdJ 访问密码 c582 php 5.5.8:http://yunpan.cn/cdX8CSaM2PYKQ 访问密码 fb65 cmake-2.8.12.1.tar.gz(MySQL编译工具):http://yunpan.cn/cdX8pSa5miKie 访问密码 2019 libmcrypt-2.5.7.tar.gz(PHPlibmcrypt模块):http://yunpan.cn/cdX8i4WpqggFx 访问密码 6fbc apr-1.5.0.tar.gz(Apache库文件):http://yunpan.cn/cdX8UhbMigq9T 访问密码 8048 apr-util-1.5.3.tar.gz(Apache库文件):http://yunpan.cn/cdX8zvzNHDu8r 访问密码 622f 预备:编译工具及库文件(使用CentOS yum命令安装) [root@localhost ~]# yum -y install make apr* autoconf automake gcc gcc-c++ zlib-devel openssl openssl-devel pcre-devel gd kernel keyutils patch perl kernel-headers compat* mpfr cpp glibc libgomp libstdc++-devel ppl cloog-ppl keyutils-libs-devel libcom_err-devel libsepol-devel libselinux-devel krb5-devel zlib-devel libXpm* freetype libjpeg* libpng* php-common php-gd ncurses* libtool* libxml2 libxml2-devel patch 三、安装libmcrypt [root@localhost ~]# yum -y install gcc-c++ [root@localhost ~]# cd /usr/local/src [root@localhost src]# tar zxvf libmcrypt-2.5.7.tar.gz [root@localhost src]# cd libmcrypt-2.5.7 [root@localhost libmcrypt-2.5.7]# ./configure [root@localhost libmcrypt-2.5.7]# make && make install 四、安装cmake [root@localhost ~]# cd /usr/local/src [root@localhost src]# tar zxvf cmake-2.8.12.1.tar.gz [root@localhost src]# cd cmake-2.8.12.1 [root@centos cmake-2.8.12.1]# ./configure [root@localhost cmake-2.8.12.1]# make && make install 编译安装 五、安装apr [root@localhost ~]# yum remove apr-util-devel apr apr-util-mysql apr-docs apr-devel apr-util apr-util-docs -y 首先卸载旧版本 [root@localhost ~]# cd /usr/local/src [root@localhost src]# tar zxvf apr-1.5.0.tar.gz [root@localhost src]# cd apr-1.5.0 [root@localhost apr-1.5.0]# ./configure –prefix=/usr/local/apr [root@localhost apr-1.5.0]# make && make install 六、安装apr-util [root@localhost ~]# cd /usr/local/src [root@localhost src]# tar zxvf apr-util-1.5.3.tar.gz [root@localhost src]# cd apr-util-1.5.3 [root@localhost apr-util-1.5.3]# ./configure –prefix=/usr/local/apr-util –with-apr=/usr/local/apr/bin/apr-1-config [root@localhost apr-util-1.5.3]# make && make install 七、安装mysql [root@localhost ~]# groupadd mysql #添加mysql组 [root@localhost ~]# useradd -g mysql mysql -s /bin/false #创建用户mysql并加入到mysql组,不允许mysql用户直接登录系统 [root@localhost ~]# mkdir -p /data/mysql #创建MySQL数据库存放目录 [root@localhost ~]# chown -R mysql:mysql /data/mysql #设置MySQL数据库目录权限 [root@localhost ~]# mkdir -p /usr/local/mysql #创建MySQL安装目录 [root@localhost ~]# yum -y install ntp vim-enhanced gcc gcc-c++ flex bison autoconf automake bzip2-devel ncurses-devel zlib-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel libXpm-devel gettext-devel pam-devel libtool libtool-ltdl openssl openssl-devel fontconfig-devel libxml2-devel curl-devel libicu libicu-devel libmcrypt libmcrypt-devel libmhash libmhash-devel [root@localhost ~]# cd /usr/local/src/ [root@localhost src]# tar zxvf mysql-5.5.35.tar.gz [root@localhost src]# cd mysql-5.5.35 [root@localhost mysql-5.5.35]# yum -y install ncurses-devel [root@localhost mysql-5.5.35]# yum -y install bison [root@localhost mysql-5.5.35]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_unicode_ci -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_DEBUG=0 [root@localhost mysql-5.5.35]# rm -f CMakeCache* 编译安装出问题 删除重新安装的命令 [root@localhost mysql-5.5.35]# make && make install [root@localhost mysql-5.5.35]# cd /usr/local/mysql/ [root@localhost mysql]# cp ./support-files/my-huge.cnf /etc/my.cnf //拷贝配置文件(注意:/etc目录下面默认有一个my.cnf,直接覆盖即可) [root@localhost mysql]# vim /etc/my.cnf //编辑配置文件,在 [mysqld] 部分增加 datadir = /data/mysql //生成mysql系统数据库 :wq! //保存退出 [root@localhost mysql]# ./scripts/mysql_install_db –user=mysql //把Mysql加入系统启动 [root@localhost mysql]# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld //把Mysql加入系统启动 [root@localhost mysql]# chmod 755 /etc/init.d/mysqld //增加执行权限 [root@localhost mysql]# chkconfig mysqld on //加入开机启动 [root@localhost mysql]# vim /etc/rc.d/init.d/mysqld basedir=/usr/local/mysql //MySQl数据库存放目录 datadir=/data/mysql //启动 [root@localhost mysql]# service mysqld start 启动 [root@localhost mysql]# vim /etc/profile 把mysql服务加入系统环境变量:在最后添加下面这一行 export PATH=$PATH:/usr/local/mysql/bin 下面这两行把myslq的库文件链接到系统默认的位置,这样你在编译类似PHP等软件时可以不用指定mysql的库文件地址。

[root@localhost mysql]# ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql [root@localhost mysql]# ln -s /usr/local/mysql/include/mysql /usr/include/mysql [root@localhost mysql]# reboot #需要重启系统,等待系统重新启动之后继续在终端命令行下面操作 [root@localhost mysql]# mysql_secure_installation #设置Mysql密码 根据提示按Y 回车输入2次密码   或者直接修改密码/usr/local/mysql/bin/mysqladmin -u root -p password “123456” #修改密码 [root@localhost mysql]# vim /etc/my.cnf #让MySQL支持全文索引 找到[mysqld],在下面添加一行 ft_min_word_len=1 [root@localhost mysql]# service mysqld restart #重启   到此,mysql安装完成! 八、安装apache2 [root@localhost ~]# cd /usr/local/src/ [root@localhost src]# tar zxvf httpd-2.4.7.tar.gz [root@localhost src]# cd httpd-2.4.7 [root@localhost httpd-2.4.7]# mkdir -p /usr/local/apache2 创建安装目录 [root@localhost httpd-2.4.7]# yum -y install pcre-devel 缺少的安装包 用yum来安装 [root@localhost httpd-2.4.7]# ./configure –prefix=/usr/local/apache2 –with-apr=/usr/local/apr –with-apr-util=/usr/local/apr-util –with-ssl –enable-ssl –enable-module=so –enable-rewrite –enable-cgid –enable-cgi 开始配置 [root@localhost httpd-2.4.7]# make && make install [root@localhost httpd-2.4.7]# /usr/local/apache2/bin/apachectl -k start 启动(会报错,是因为httpd.conf文件里面的servername有问题) [root@localhost httpd-2.4.7]# vi /usr/local/apache2/conf/httpd.conf 找到:#ServerName www.example.com:80  修改为:ServerName localhost:80 找到:DirectoryIndex index.html  修改为:DirectoryIndex index.html index.php 找到:Options Indexes FollowSymLinks 修改为:Options FollowSymLinks #不显示目录结构 找到:AllowOverride None 修改为:AllowOverride All #开启apache支持伪静态,有两处都做修改 LoadModule rewrite_module modules/mod_rewrite.so #取消前面的注释,开启apache支持伪静态 [root@localhost httpd-2.4.7]# vim /etc/profile 在最后添加下面这一行:export PATH=$PATH:/usr/local/apache2/bin [root@localhost httpd-2.4.7]# cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd [root@localhost httpd-2.4.7]# vim /etc/init.d/httpd 在#!/bin/sh下面添加以下两行 #chkconfig:2345 10 90   #descrption:Activates/Deactivates Apache Web Server [root@localhost httpd-2.4.7]# chown daemon.daemon -R /usr/local/apache2/htdocs 更改目录所有者 [root@localhost httpd-2.4.7]# chmod 700 /usr/local/apache2/htdocs -R 更改apache网站目录权限 [root@localhost httpd-2.4.7]# chkconfig httpd on 设置开机启动 [root@localhost httpd-2.4.7]# /etc/init.d/httpd restart [root@localhost httpd-2.4.7]# service httpd restart 九、安装PHP5 [root@localhost ~]# cd /usr/local/src/ [root@localhost src]# tar zxvf php-5.4.5.tar.gz [root@localhost src]# cd php-5.4.5 [root@localhost php-5.4.5]# mkdir -p /usr/local/php5 建立php安装目录 [root@localhost php-5.4.5]# ./configure –prefix=/usr/local/php5 –with-config-file-path=/usr/local/php5/etc –with-apxs2=/usr/local/apache2/bin/apxs –with-mysql=/usr/local/mysql –with-mysqli=/usr/local/mysql/bin/mysql_config –with-mysql-sock=/tmp/mysql.sock –with-gd –with-iconv –with-freetype –with-jpeg –with-png –with-zlib –with-libxml –enable-xml –enable-discard-path –enable-magic-quotes –enable-safe-mode –enable-bcmath –enable-shmop –enable-sysvsem –enable-inline-optimization –with-curlwrappers –enable-mbregex –enable-fastcgi –enable-force-cgi-redirect –enable-mbstring –enable-ftp –enable-gd-native-ttf –with-openssl –enable-pcntl –enable-sockets –with-xmlrpc –enable-zip –enable-soap –with-pear –with-gettext –with-mime-magic –enable-suhosin –enable-session –with-mcrypt –with-jpeg –enable-fpm -with-pdo-mysql=/usr/local/mysql [root@localhost php-5.4.5]# make && make install [root@localhost php-5.4.5]# mkdir /usr/local/php5/etc [root@localhost php-5.4.5]# cp php.ini-production /usr/local/php5/etc/php.ini 复制php配置文件到安装目录 [root@localhost php-5.4.5]# rm -rf /etc/php.ini 删除系统自带的配置文件 [root@localhost php-5.4.5]# ln -s /usr/local/php5/etc/php.ini /etc/php.ini 创建配置文件软链接 [root@localhost php-5.4.5]# vi /usr/local/php5/etc/php.ini #编辑 找到:;open_basedir =  修改为:open_basedir = .:/tmp/ #防止php木马跨站,重要!! 找到:disable_functions = 修改为:disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter, ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen, disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid, posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname #列出PHP可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用。

找到:;date.timezone =  修改为:date.timezone = PRC    找到:expose_php = On  修改为:expose_php = OFF #禁止显示php版本的信息    找到:display_errors = On  修改为:display_errors = OFF #关闭错误提示 十、配置apache支持php [root@localhost ~]# vim /usr/local/apache2/conf/httpd.conf 在LoadModule php5_module modules/libphp5.so这一行下面添加、   AddType application/x-httpd-php .php (注意:php .php这个点前面有一个空格) [root@localhost ~]# service httpd restart 重启apache [root@localhost ~]# service mysqld restart 重启mysql 至此,基本的LAMP环境编译完成,可以写一个测试文件测试一下。

十一、安装redis服务以及php redis扩展 1、安装TCL [root@localhost src]# wget -c http://prdownloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz [root@localhost src]# tar zxvf tcl8.6.1-src.tar.gz [root@localhost src]# cd tcl8.6.1/unix [root@localhost unix]# ./configure [root@localhost unix]# make && make install 2、安装redis服务 [root@localhost src]# wget -c http://download.redis.io/releases/redis-2.6.16.tar.gz [root@localhost src]# tar zxvf redis-2.6.16.tar.gz [root@localhost src]# cd redis-2.6.16 [root@localhost redis-2.6.16]# make [root@localhost redis-2.6.16]# make test [root@localhost redis-2.6.16]# make install 3、启动redis服务 [root@localhost redis-2.6.16]# vim /usr/local/src/redis-2.6.16/redis.conf //将daemonize 设置为yes [root@localhost redis-2.6.16]# /usr/local/bin/redis-server /usr/local/src/redis-2.6.16/redis.conf [root@localhost redis-2.6.16]# ps aux|grep redis 查看进程 4、使用 redis-cli 连接,当然也可以使用telnet [root@localhost redis-2.6.16]# redis-cli redis 127.0.0.1:6379> set name silenceper OK redis 127.0.0.1:6379> get name “silenceper” redis 127.0.0.1:6379> 关于redis 2.4 配置文件中文说明说明:https://github.com/silenceper/my/blob/master/config/redis2.4.chinese redis 命令手册:http://redis.readthedocs.org/en/latest/ 5、使用phpRedisAdmin 管理redis   [root@localhost src]# git clone https://github.com/ErikDubbelboer/phpRedisAdmin.git [root@localhost src]# cd phpRedisAdmin/ [root@localhost phpRedisAdmin]# git clone https://github.com/nrk/predis.git vendor 6、安装php redis扩展 [root@localhost src]# git clone git://github.com/nicolasff/phpredis.git [root@localhost src]# cd phpredis/ [root@localhost phpredis]# /usr/local/php5/bin/phpize [root@localhost phpredis]# ./configure –with-php-config=/usr/local/php5/bin/php-config –enable-redis [root@localhost phpredis]# make && make install 7、配置php.ini [root@localhost ~]# vim /usr/local/php5/etc/php.ini 修改 extension_dir = “/usr/local/php5/lib/php/extensions/no-debug-zts-20121212/”   添加 extension=redis.so //开启redis扩展 8、重启apache服务 [root@localhost src]# /usr/local/php5/bin/php -m //可以看到有了redis 扩展了 。

退出移动版