CentOS6.5编译安装LNMP环境(nginx-1.7.2, httpd-2.4.9, mysql-5.6.17, php-5.5.12)

  •   
  • 5308
  • Linux
  • 4
  • super_dodo
  • 2014/08/01

为了体验感受一下阿里云的服务。同时也尝试着学习一下CentOs环境的搭建.为了避免版本的不断的更新。一次性把版本大幅度提升。同时也考虑迎合windows下的wampserver的版本wamp2.5(Apache : 2.4.9 MySQL : 5.6.17 PHP : 5.5.12)

此次centos6.5下的安装版本为(nginx-1.7.2, httpd-2.4.9, mysql-5.6.17, php-5.5.12)

yum -y install gcc gcc-c++  make automake autoconf kernel-devel ncurses-devel libxml2-devel openssl-devel curl-devel libjpeg-devel libpng-devel pcre-devel libtool-libs freetype-devel gd zlib-devel file bison patch mlocate flex diffutils readline-devel glibc-devel glib2-devel bzip2-devel gettext-devel libcap-devel libmcrypt-devel cmake bison-devel  
  
#yum -y install make gcc-c++ cmake bison-devel ncurses-devel


[soft]  
mkdir -p /lamp/src  
cd /lamp/src  
wget http://mirrors.hust.edu.cn/apache/apr/apr-1.5.1.tar.gz  
wget http://mirrors.hust.edu.cn/apache/apr/apr-iconv-1.2.1.tar.gz  
wget http://mirrors.hust.edu.cn/apache/apr/apr-util-1.5.3.tar.gz  
wget http://apache.fayea.com/apache-mirror//httpd/httpd-2.4.9.tar.gz  
wget http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz/download  
wget http://ftp.kaist.ac.kr/mysql/Downloads/MySQL-5.6/mysql-5.6.17.tar.gz  
wget http://nginx.org/download/nginx-1.7.2.tar.gz  
wget http://ftp.exim.llorien.org/pcre/pcre-8.34.tar.gz  
wget http://mirrors.sohu.com/php/php-5.5.12.tar.gz  
wget http://superb-dca3.dl.sourceforge.net/project/phpmyadmin/phpMyAdmin/4.2.2/phpMyAdmin-4.2.2-all-languages.zip  

[apr]  
tar zxvf apr-1.5.1.tar.gz  
cd apr-1.5.1  
./configure --prefix=/usr/local/apr  
make && make install  
  
[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  
make && make install  
  
[apr-iconv]  
tar zxvf apr-iconv-1.2.1.tar.gz  
cd apr-iconv-1.2.1  
./configure --prefix=/usr/local/apr-iconv --with-apr=/usr/local/apr/bin/apr-1-config  
make && make install  
  
[pcre]  
tar zxvf pcre-8.34.tar.gz  
cd pcre-8.34  
./configure --prefix=/usr/local/pcre  
make && make install  
  
[apache]  
tar zxvf httpd-2.4.9.tar.gz  
cd httpd-2.4.9  
./configure --prefix=/usr/local/apache2 \  
    --with-apr=/usr/local/apr \  
    --with-apr-util=/usr/local/apr-util \  
    --with-apr-iconv=/usr/local/apr-iconv \  
    --with-pcre=/usr/local/pcre \  
    --with-ssl \  
    --enable-ssl \  
    --enable-so \  
    --enable-deflate=shared \  
    --enable-expires=shared \  
    --enable-headers=shared \  
    --enable-rewrite=shared \  
    --enable-static-support  
make && make install  
  
#将apache添加到系统服务中    
cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd    
vi /etc/init.d/httpd  
#在#!/bin/sh后添加下面两行(包含"#")    
# chkconfig:2345 85 15    
# description:Apache    
#添加执行权限    
chmod 755 /etc/init.d/httpd    
#添加到系统服务中    
chkconfig --add httpd    
#开启apache    
service httpd start  
  
#如果出现下面的错误,    
#httpd: Could not reliably determine the server's fully qualified domain name,  \  
#using ::1 for ServerName    
#修改配置文件    
vi /usr/local/apache2/conf/httpd.conf  
  
#查找ServerName,将注释去掉    
ServerName www.example.com:80    
  
#搜索<IfModule dir_module>, 修改为  
DirectoryIndex index.html index.php  
  
#搜索 AddType application/x-gzip .gz .tgz在后面添加    
AddType application/x-httpd-php .html .php    
  
#搜索Options Indexes FollowSymLinks项并注释    
#Options Indexes FollowSymLinks  
  
#重启apache    
service httpd restart  
  
[mysql]  
tar zxvf mysql-5.6.17.tar.gz  
cd mysql-5.6.17  
cmake \  
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \  
-DMYSQL_DATADIR=/usr/local/mysql/data \  
-DSYSCONFDIR=/etc \  
-DWITH_MYISAM_STORAGE_ENGINE=1 \  
-DWITH_INNOBASE_STORAGE_ENGINE=1 \  
-DWITH_MEMORY_STORAGE_ENGINE=1 \  
-DWITH_READLINE=1 \  
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \  
-DMYSQL_TCP_PORT=3306 \  
-DENABLED_LOCAL_INFILE=1 \  
-DWITH_PARTITION_STORAGE_ENGINE=1 \  
-DEXTRA_CHARSETS=all \  
-DDEFAULT_CHARSET=utf8mb4 \  
-DDEFAULT_COLLATION=utf8_general_ci  
  
make && make install  
  
groupadd mysql  
useradd -M -s /sbin/nologin -g mysql mysql  
chown -R mysql:mysql /usr/local/mysql  
cd /usr/local/mysql  
scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql  
  
#生成配置文件  
mv /usr/local/mysql/my.cnf /etc/  
#添加服务,拷贝服务脚本到init.d目录,并设置开机启动  
cp support-files/mysql.server /etc/init.d/mysqld  
chkconfig mysqld on  
#启动MySQL  
service mysqld start  
  
修改/etc/profile文件,在文件末尾添加  
vi /etc/profile  
PATH=/usr/local/mysql/bin:$PATH  

export PATH  
source /etc/profile  
  
#修改密码  
mysql -uroot  
mysql> SET PASSWORD = PASSWORD('123456');  
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;  
  
#删除匿名用户  
mysql -uroot -p123456  
USE mysql  
DELETE FROM user WHERE user = '';  
  
[libmcrypt]  
tar -zxvf libmcrypt-2.5.8.tar.gz  
cd libmcrypt-2.5.8  
./configure --prefix=/usr/local/libmcrypt  
make && make install  
  
  
tar zxvf php-5.5.12.tar.gz  
cd php-5.5.12  
./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=/usr/local/mysql/tmp/mysql.sock \  
--with-pdo-mysql=/usr/local/mysql \  
--with-mcrypt=/usr/local/libmcrypt \  
--with-gd \  
--with-iconv \  
--with-freetype-dir \  
--with-jpeg-dir \  
--with-png-dir \  
--with-zlib-dir \  
--with-libxml-dir \  
--enable-xml \  
--enable-bcmath \  
--enable-shmop \  
--enable-sysvsem \  
--enable-inline-optimization \  
--with-curl \  
--enable-mbregex \  
--enable-mbstring \  
--enable-ftp \  
--enable-gd-native-ttf \  
--with-openssl \  
--enable-pcntl \  
--enable-sockets \  
--with-xmlrpc \  
--enable-zip \  
--enable-soap \  
--without-pear \  
--with-gettext \  
--enable-session \  
--enable-fpm \  
--with-fpm-user=nobody \  
--with-fpm-group=nobody  
  
make && make install  
  
cp php.ini-production /usr/local/php5/etc/php.ini  
cp /usr/local/php5/etc/php-fpm.conf.default /usr/local/php5/etc/php-fpm.conf  
  
## 修改配置文件  
vi /usr/local/php5/etc/php-fpm.conf  
## 指定pid位置  
# 去掉注释  
pid=run/php-fpm.pid  
  
# 添加到服务  
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm  
chmod +x /etc/init.d/php-fpm  
chkconfig --add php-fpm  
chkconfig php-fpm on  
service php-fpm start  
  
-------------------------------------------------------  
  
## php-fpm 关闭  
kill -QUIT `cat /usr/local/php5/var/run/php-fpm.pid`  
## php-fpm 重启  
kill -USR2 `cat /usr/local/php5/var/run/php-fpm.pid`  
## 查看php-fpm进程数  
ps -ef | grep php-fpm  
## 如果找不到php-fpm.pid文件, 也可用ps查出pid直接使用  
  
[nginx]  
#useradd -M -s /sbin/nologin www  
groupadd www  
useradd -g www www  
  
tar zxvf nginx-1.7.2.tar.gz  
cd nginx-1.7.2  
  
./configure \  
--sbin-path=/usr/local/nginx/sbin/nginx \  
--conf-path=/usr/local/nginx/conf/nginx.conf \  
--pid-path=/usr/local/nginx/nginx.pid \  
--user=www \  
--group=www \  
--with-http_ssl_module \  
--with-http_realip_module \  
--with-http_addition_module \  
--with-http_gzip_static_module \  
--with-http_sub_module \  
--with-http_dav_module \  
--with-http_flv_module \  
--with-http_stub_status_module \  
--without-http_charset_module \  
--with-pcre=../pcre-8.34  
  
make && make install  
  
# 添加到服务, 将下面的代码添加到  
vi /etc/init.d/nginx  
  
#!/bin/bash  
# nginx Startup script for the Nginx HTTP Server  
#    
# chkconfig: - 85 15   
# description: Nginx is a high-performance web and proxy server.  
# It has a lot of features, but it's not for everyone.  
# processname: nginx  
# pidfile: /var/run/nginx.pid  
# config: /usr/local/nginx/conf/nginx.conf  
nginxd=/usr/local/nginx/sbin/nginx  
nginx_config=/usr/local/nginx/conf/nginx.conf  
nginx_pid=/usr/local/nginx/nginx.pid  
   
RETVAL=0  
prog="nginx"  
  
# Source function library.  
. /etc/rc.d/init.d/functions  
  
# Source networking configuration.  
. /etc/sysconfig/network  
  
# Check that networking is up.    
[ ${NETWORKING} = "no" ] && exit 0  
   
[ -x $nginxd ] || exit 0  
  
# Start nginx daemons functions.  
start() {  
   
if [ -e $nginx_pid ];then  
   echo "nginx already running...."  
   exit 1  
fi  
   
  echo -n $"Starting $prog: "  
  daemon $nginxd -c ${nginx_config}  
  RETVAL=$?  
  echo  
  [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx  
  return $RETVAL  
}    
  
# Stop nginx daemons functions.  
stop() {  
    echo -n $"Stopping $prog: "  
    killproc $nginxd  
    RETVAL=$?  
    echo  
    [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid  
}  
  
# reload nginx service functions.  
reload() {  
    echo -n $"Reloading $prog: "  
$nginxd -s reload  
    #if your nginx version is below 0.8, please use this command: "kill -HUP `cat ${nginx_pid}`"  
    RETVAL=$?  
    echo  
}    
   
# See how we were called.  
case "$1" in  
start)  
    start  
    ;;  
  
stop)  
    stop  
    ;;  
  
reload)  
    reload  
    ;;  
  
restart)  
    stop  
    start  
    ;;  
  
status)  
    status $prog  
        RETVAL=$?  
        ;;  
*)  
    echo $"Usage: $prog {start|stop|restart|reload|status|help}"  
    exit 1  
esac  
  
exit $RETVAL  
  
# 添加执行权限  
chmod +x /etc/init.d/nginx  
# 增加到系统服务中  
chkconfig --level 345 nginx on  
  
#虚拟主机配置  
server {  
    listen 80;  
    server_name test.dev;  
    access_log logs/test_dev.access.log;  
  
    root /var/www/html/test;  
  
    server_name_in_redirect off;  
  
    location / {  
        index index.html index.php;  
    }  
  
    location ~ \.php$ {  
        fastcgi_pass   127.0.0.1:9000;  
        fastcgi_index  index.php;  
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;  
        include        fastcgi_params;  
    }  
}  
  
[phpMyAdmin]  
cp phpMyAdmin-4.2.2-all-languages.zip /www/  
cd /www/  
unzip phpMyAdmin-4.2.2-all-languages.zip  
mv phpMyAdmin-4.2.2-all-languages.zip phpMyAdmin  
cd phpMyAdmin  
cp config.sample.inc.php config.inc.php  
vi config.inc.php  
#搜索localhost改为  
$cfg['Servers'][$i]['host'] = '127.0.0.1';  


apache和nginx的目录配置和使用请查阅相关材料。我仅使用nginx.所以把apache关闭并设置成开机不自动启动。

同时我吧apache和nginx的网站目录都指向到 /www/ 这样方便管理。

网站的域名,网站根目录名以及数据库的名都尽可能的保持一致。有利于管理和查找。

网站的安全性也应该重视。

QQ截图20140801101548

参考地址:http://blog.csdn.net/ihelloworld/article/details/27684809
参考地址:http://jingyan.baidu.com/article/915fc414cc28ec51394b2032.html

两姓联姻,一堂缔约,良缘永结,匹配同称。看此日桃花灼灼,宜室宜家;卜他年瓜瓞绵绵,尔昌尔炽。谨以白头之约,书向鸿笺,好将红叶之盟,载明鸳谱。此证。——民国时期结婚证