軟件源代碼包存放位置:/usr/local/src
源碼包編譯安裝位置:/usr/local/軟件名字
修改源:
1、進入存放源配置的文件夾 cd /etc/yum.repos.d 2、備份默認源 mv ./CentOS-Base.repo ./CentOS-Base.repo.bak 3、使用wget下載163的源 wget http://mirrors.163.com/.help/CentOS-Base-163.repo 4、把下載下來的文件CentOS-Base-163.repo設置為默認源 mv CentOS-Base-163.repo CentOS-Base.repo
安裝git
yum install git
關於git常用命令見 http://www.cnblogs.com/whoamme/p/3531387.html
一、關閉SELINUX
vi /etc/selinux/config
#SELINUX=enforcing #注釋掉
#SELINUXTYPE=targeted #注釋掉
SELINUX=disabled #增加
:wq 保存,關閉
shutdown -r now #重啟系統
二、下載軟件包
1、下載apache
wget apache.dataguru.cn/httpd/httpd-2.4.7.tar.gz
2、下載mysql
wget http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.35.tar.gz
3、下載php 5.5.8
wget cn2.php.net/get/php-5.5.8.tar.gz/from/this/mirror
4、下載cmake(MySQL編譯工具)
wget http://www.cmake.org/files/v2.8/cmake-2.8.12.1.tar.gz
5、下載libmcrypt(PHPlibmcrypt模塊)
wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
6、下載apr(Apache庫文件)
wget mirror.bit.edu.cn/apache/apr/apr-1.5.0.tar.gz
7、下載apr-util(Apache庫文件)
wget mirror.bit.edu.cn/apache/apr/apr-util-1.5.3.tar.gz
三、安裝
預備:編譯工具及庫文件(使用CentOS yum命令安裝)
yum 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
1、安裝libmcrypt
cd /usr/local/src
tar zxvf libmcrypt-2.5.7.tar.gz #解壓
cd libmcrypt-2.5.7 #進入目錄
./configure #配置
make #編譯
make install #安裝
2、安裝cmake
cd /usr/local/src
tar zxvf cmake-2.8.7.tar.gz
cd cmake-2.8.7
./configure
make #編譯
make install #安裝
3、安裝apr
首先卸載舊版本
yum remove apr-util-devel apr apr-util-mysql apr-docs apr-devel apr-util apr-util-docs
cd /usr/local/src
tar zxvf apr-1.5.0.tar.gz
cd apr-1.5.0
./configure --prefix=/usr/local/apr
make
make install
4、安裝apr-util
tar zxvf apr-util-1.5.3.tar.gz
cd apr-util-1.5.3
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config
make
make install
5、安裝mysql
回到cmake目錄,刪除cmakecache.txt文件
rm -f CMakeCache.txt
groupadd mysql #添加mysql組
useradd -g mysql mysql -s /bin/false #創建用戶mysql並加入到mysql組,不允許mysql用戶直接登錄系統
mkdir -p /data/mysql #創建MySQL數據庫存放目錄
chown -R mysql:mysql /data/mysql #設置MySQL數據庫目錄權限
mkdir -p /usr/local/mysql #創建MySQL安裝目錄
cd /usr/local/src
tar zxvf mysql-5.5.21.tar.gz #解壓
cd mysql-5.5.21
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc #配置
make #編譯
make install #安裝
cd /usr/local/mysql
cp ./support-files/my-huge.cnf /etc/my.cnf #拷貝配置文件(注意:/etc目錄下面默認有一個my.cnf,直接覆蓋即可)
vi /etc/my.cnf #編輯配置文件,在 [mysqld] 部分增加
datadir = /data/mysql #添加MySQL數據庫路徑
./scripts/mysql_install_db --user=mysql #生成mysql系統數據庫
cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld #把Mysql加入系統啟動
chmod 755 /etc/init.d/mysqld #增加執行權限
chkconfig mysqld on #加入開機啟動
vi /etc/rc.d/init.d/mysqld #編輯
basedir = /usr/local/mysql #MySQL程序安裝路徑
datadir = /data/mysql #MySQl數據庫存放目錄
service mysqld start #啟動
vi /etc/profile #把mysql服務加入系統環境變量:在最后添加下面這一行
export PATH=$PATH:/usr/local/mysql/bin
下面這兩行把myslq的庫文件鏈接到系統默認的位置,這樣你在編譯類似PHP等軟件時可以不用指定mysql的庫文件地址。
ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
ln -s /usr/local/mysql/include/mysql /usr/include/mysql
shutdown -r now #需要重啟系統,等待系統重新啟動之后繼續在終端命令行下面操作
mysql_secure_installation #設置Mysql密碼
根據提示按Y 回車輸入2次密碼
或者直接修改密碼/usr/local/mysql/bin/mysqladmin -u root -p password "123456" #修改密碼
service mysqld restart #重啟
到此,mysql安裝完成!
6、安裝apache2
cd /usr/local/src
tar -zvxf httpd-2.4.1.tar.gz
cd httpd-2.4.1
mkdir -p /usr/local/apache2 #創建安裝目錄
./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 #配置
make #編譯
make install #安裝
/usr/local/apache2/bin/apachectl -k start #啟動
vi /usr/local/apache2/conf/httpd.conf #編輯配置文件
找到:#ServerName www.example.com:80
修改為:ServerName www.osyunwei.com: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支持偽靜態
vi /etc/profile #添加apache服務系統環境變量
在最后添加下面這一行
export PATH=$PATH:/usr/local/apache2/bin
cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd #把apache加入到系統啟動
vi /etc/init.d/httpd #編輯文件
在#!/bin/sh下面添加以下兩行
#chkconfig:2345 10 90
#descrption:Activates/Deactivates Apache Web Server
chown daemon.daemon -R /usr/local/apache2/htdocs #更改目錄所有者
chmod 700 /usr/local/apache2/htdocs -R #更改apache網站目錄權限
chkconfig httpd on #設置開機啟動
/etc/init.d/httpd start
service httpd restart
7、安裝PHP5
cd /usr/local/src
tar -zvxf php-5.3.10.tar.gz
cd php-5.3.10
mkdir -p /usr/local/php5 #建立php安裝目錄
./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 #配置
make #編譯
make install #安裝
mkdir /usr/local/php5/etc
cp php.ini-production /usr/local/php5/etc/php.ini #復制php配置文件到安裝目錄
rm -rf /etc/php.ini #刪除系統自帶的配置文件
ln -s /usr/local/php5/etc/php.ini /etc/php.ini #創建配置文件軟鏈接
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
vi /usr/local/apache2/conf/httpd.conf #編輯apache配置文件
在LoadModule php5_module modules/libphp5.so這一行下面添加、
AddType application/x-httpd-php .php (注意:php .php這個點前面有一個空格)
service httpd restart #重啟apache
service mysqld restart #重啟mysql
至此,基本的LAMP環境編譯完成,可以寫一個測試文件測試一下。
四、安裝redis服務以及php redis擴展
1、安裝tcl
wget -c http:
//prdownloads
.sourceforge.net
/tcl/tcl8
.6.1-src.
tar
.gz
tar
-zxvf tcl8.6.1-src.
tar
.gz
cd
tcl8.6.1
/unix
.
/configure
make
&&
make
install
2、安裝redis服務
wget -c http:
//download
.redis.io
/releases/redis-2
.6.16.
tar
.gz
tar
-zxvf redis-2.6.16.
tar
.gz
cd
redis-2.6.16
make(如果是linux32位,使用 make CFLAGS="-march=i686")
make
test
make
install
3、啟動redis服務:
vim
/usr/local/src/redis-2
.6.16
/redis
.conf
//
將daemonize 設置為
yes
/usr/local/bin/redis-server
/usr/local/src/redis-2
.6.16
/redis
.conf
ps
aux|
grep
redis 查看進程
測試:
[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-cli shutdown
redis-cli –help 查看更多選項
關於redis 2.4 配置文件中文說明說明:
https://github.com/silenceper/my/blob/master/config/redis2.4.chinese
redis 命令手冊:
http://redis.readthedocs.org/en/latest/
5、使用phpRedisAdmin 管理redis
git clone https:
//github
.com
/ErikDubbelboer/phpRedisAdmin
.git
cd
phpRedisAdmin
git clone https:
//github
.com
/nrk/predis
.git vendor
git clone git://github.com/nicolasff/phpredis.git