lnmp安装 centos6.5+mysql5.6.17+nginx1.8.0+php5.5.12

LNMP安装 centos6.5+mysql5.6.17+php5.5.12+nginx1.8.0


说明: 我的系统是CentOS6.5 32bit  ,采用的是桌面化安装,在安装过程中所需要的源码包如下rpm -e httpd

1、安装mysql5.6.17

1)首先把系统默认的都卸载

[root@yuan ~]# rpm -e mysql
[root@yuan ~]# rpm -e httpd
[root@yuan ~]# rpm -e php
[root@yuan ~]# yum -y remove mysql
[root@yuan ~]# yum -y remove httpd
[root@yuan ~]# yum -y remove php

搜索残留的包
[root@yuan ~]# rpm -qa | grep http*
httpd-tools-2.2.15-29.el6.centos.i686
卸载
[root@yuan ~]# rpm -e httpd-tools --nodeps

2)更改selinux, 找到SELINUX并改为SELINUX=disabled

[root@yuan ~]# vim /etc/selinux/config
   临时关闭
[root@yuan ~]# setenforce 0

3) 创建mysql用户 mysql组

[root@yuan ~]# groupadd mysql
[root@yuan ~]# useradd -s /sbin/nologin -g mysql -M mysql

检查是否成功
[root@yuan ~]# cat /etc/passwd | grep mysql
mysql:x:501:501::/home/mysql:/sbin/nologin


4) 我把源码包都放在了/usr/local/src中了

注意: mysql5.5以后需要cmake编译
[root@yuan src]# yum -y install cmake

 5)解压并进入mysql目录

[root@yuan src]# tar zxvf mysql-5.6.17.tar.gz
[root@yuan src]# cd mysql-5.6.17

6)编译,

[root@yuan 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=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_USER=mysql -DWITH_DEBUG=0 -DWITH_SSL=system
其中需要注意这几个路径
/usr/local/mysql         ----主目录
/var/lib/mysql/mysql.sock           ---套接字文件目录
/usr/local/mysql/data         ---数据存放目录

7)make && make install (这个过程需要时间很长)

[root@yuan mysql-5.6.17]# make  && make install 

8) 修改/usr/local/mysql

[root@yuan ~]# chmod +w /usr/local/mysql/
[root@yuan ~]# chown -R mysql:mysql /usr/local/mysql/
[root@yuan ~]# cd /usr/local/mysql/support-files/
[root@yuan support-files]# mv my-default.cnf /etc/my.cnf
[root@yuan support-files]# /usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql

9) 拷贝脚本到init.d下,设置开机启动  设置PATH路径

[root@yuan support-files]# cp mysql.server /etc/init.d/mysqld
[root@yuan support-files]# chmod +x /etc/init.d/mysqld
[root@yuan support-files]# chkconfig --add mysqld 
[root@yuan support-files]# chkconfig mysqld on
[root@yuan support-files]# service mysqld start
/etc/profile最后添加
PATH=/usr/local/mysql/bin:$PATH
export PATH     并立即生效
[ root@yuan support-files]# vim /etc/profile
[root@yuan support-files]# source /etc/profile


10)设置mysql  root密码

[root@yuan support-files]# mysql -uroot -p  初始无密码直接回车
[root@yuan support-files]# /usr/local/mysql/bin/mysqladmin -uroot -p password 'asd123'


2、安装php5.5.12

1)解压php ,创建账号,编译php
[root@yuan src]# tar zxvf php-5.5.12.tar.gz 
[root@yuan src]# cd php-5.5.12

该账号是用来运行php-fpm服务,在LNMP环境中,php是以一个服务来提供服务的
[root@yuan php-5.5.12]# useradd -s /sbin/nologin php-fpm

[root@yuan php-5.5.12]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=/usr/local/mysql --with-mysql-sock=/var/lib/mysql/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --enable-zend-multibyte --disable-ipv6 --with-pear --with-curl --with-openssl

说明: 这一步可能出现这样那样的错误,不要担心将错误信息在望上搜索一班都能能够解决
出现错误:    configure: error: jpeglib.h not found.
解决:   [root@yuan php-5.5.12]# yum install libjpeg-devel 

出现错误:    configure: error: mcrypt.h not found. Please reinstall libmcrypt.
解决:  下载libmcrypt-2.5.8.tar.gz
#tar zxvf libmcrypt-2.5.8.tar.gz
#cd libmcrypt-2.5.8
#./configure --prefix=/usr/local/libmcrypt
#make 
#make install

出现:  configure: WARNING: unrecognized options: --enable-zend-multibyte   
解决:  忽略

[root@yuan php-5.5.12]# make && make install 


转:http://www.cnblogs.com/kristain/articles/3809243.html

在CentOS编译PHP5的时候有时会遇到以下的一些错误信息,基本上都可以通过yum安装相应的库来解决。以下是具体的一些解决办法:

checking for BZip2 support… yes checking for BZip2 in default path… not found configure: error: Please reinstall the BZip2 distribution

Fix: yum install bzip2-devel

checking for cURL support… yes checking if we should use cURL for url streams… no checking for cURL in default path… not found configure: error: Please reinstall the libcurl distribution – easy.h should be in/include/curl/

Fix: yum install curl-devel

 

checking for curl_multi_strerror in -lcurl… yes checking for QDBM support… no checking for GDBM support… no checking for NDBM support… no configure: error: DBA: Could not find necessary header file(s).

Fix: yum install db4-devel

checking for fabsf… yes checking for floorf… yes configure: error: jpeglib.h not found.

Fix: yum install libjpeg-devel

checking for fabsf… yes checking for floorf… yes checking for jpeg_read_header in -ljpeg… yes configure: error: png.h not found.

Fix: yum install libpng-devel

checking for png_write_image in -lpng… yes If configure fails try –with-xpm-dir=

 

configure: error: freetype.h not found.

 

Fix: Reconfigure your PHP with the following option. --with-xpm-dir=/usr yum install freetype-devel

checking for png_write_image in -lpng… yes configure: error: libXpm.(a|so) not found.

Fix: yum install libXpm-devel

checking for bind_textdomain_codeset in -lc… yes checking for GNU MP support… yes configure: error: Unable to locate gmp.h

Fix: yum install gmp-devel

checking for utf8_mime2text signature… new checking for U8T_DECOMPOSE… configure: error: utf8_mime2text() has new signature, but U8T_CANONICAL is missing. This should not happen. Check config.log for additional information.

Fix: yum install libc-client-devel

checking for LDAP support… yes, shared checking for LDAP Cyrus SASL support… yes configure: error: Cannot find ldap.h

Fix: yum install openldap-devel

checking for mysql_set_character_set in -lmysqlclient… yes checking for mysql_stmt_next_result in -lmysqlclient… no checking for Oracle Database OCI8 support… no checking for unixODBC support… configure: error: ODBC header file ‘/usr/include/sqlext.h’ not found!

Fix:

yum install unixODBC-devel

checking for PostgreSQL support for PDO… yes, shared checking for pg_config… not found configure: error: Cannot find libpq-fe.h. Please specify correct PostgreSQL installation path

Fix: yum install postgresql-devel

checking for sqlite 3 support for PDO… yes, shared checking for PDO includes… (cached) /usr/local/src/php-5.3.7/ext checking for sqlite3 files in default path… not found configure: error: Please reinstall the sqlite3 distribution

Fix: yum install sqlite-devel

checking for utsname.domainname… yes checking for PSPELL support… yes configure: error: Cannot find pspell

Fix: yum install aspell-devel

checking whether to enable UCD SNMP hack… yes checking for default_store.h… no

checking for kstat_read in -lkstat… no checking for snmp_parse_oid in -lsnmp… no checking for init_snmp in -lsnmp… no configure: error: SNMP sanity check failed. Please check config.log for more information.

Fix: yum install net-snmp-devel

checking whether to enable XMLWriter support… yes, shared checking for xml2-config path… (cached) /usr/bin/xml2-config checking whether libxml build works… (cached) yes checking for XSL support… yes, shared configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution

Fix: yum install libxslt-devel

configure: error: xml2-config not found. Please check your libxml2 installation.

Fix: yum install libxml2-devel

checking for PCRE headers location… configure: error: Could not find pcre.h in /usr

Fix: yum install pcre-devel

configure: error: Cannot find MySQL header files under yes. Note that the MySQL client library is not bundled anymore!

Fix: yum install mysql-devel

checking for unixODBC support… configure: error: ODBC header file ‘/usr/include/sqlext.h’ not found!

Fix: yum install unixODBC-devel

checking for pg_config… not found configure: error: Cannot find libpq-fe.h. Please specify correct PostgreSQL installation path

Fix:

yum install postgresql-devel

configure: error: Cannot find pspell

Fix: yum install pspell-devel

configure: error: Could not find net-snmp-config binary. Please check your net-snmp installation.

Fix: yum install net-snmp-devel

configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution

Fix: yum install libxslt-devel

 

编译mcrypt可能会报错:configure: error: *** libmcrypt was not found

vi  /etc/ld.so.conf
最后一行添加
/usr/local/lib/
载入
ldconfig

编译mcrypt可能会报错:/bin/rm: cannot remove `libtoolT': No such file or directory

修改 configure 文件,把RM='$RM'改为RM='$RM -f' 这里的$RM后面一定有一个空格。 如果后面没有空格,直接连接减号,就依然会报错。

2)修改配置文件

[root@yuan php-5.5.12]# cp php.ini-production /usr/local/php/etc/php.ini
[root@yuan php-5.5.12]# vim /usr/local/php/etc/php-fpm.conf
[global]
pid = /usr/local/php/var/run/php-fpm.pid
error_log = /usr/local/php/var/log/php-fpm.log
[www]
listen = /tmp/php-fcgi.sock
user = php-fpm
group = php-fpm
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024
[root@yuan php-5.5.12]# /usr/local/php/sbin/php-fpm -t

3)启动php-fpm

[root@yuan php-5.5.12]# cp /usr/local/src/php-5.5.12/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@yuan php-5.5.12]# chmod +x /etc/init.d/php-fpm
[root@yuan php-5.5.12]# service php-fpm start
Starting php-fpm  done
[root@yuan php-5.5.12]# chkconfig --add php-fpm
[root@yuan php-5.5.12]# chkconfig php-fpm on
[root@yuan php-5.5.12]# ps aux | grep php-fpm

3、Nginx编译安装

1) 配置编译选项

[root@yuan src]# tar zxvf nginx-1.8.0.tar.gz 
[root@yuan src]# cd nginx-1.8.0
[root@yuan nginx-1.8.0]# ./configure --prefix=/usr/local/nginx --with-http_realip_module --with-http_sub_module --with-http_gzip_static_module --with-http_stub_status_module  --with-pcre

出现错误: make: *** 没有规则可以创建“default”需要的目标“build”。 停止。
解决: 安装 yum -y install pcre   pcre-devel

[root@yuan nginx-1.8.0]# make && make install

2) 启动nginx

[root@yuan nginx-1.8.0]# /usr/local/nginx/sbin/nginx 
[root@yuan nginx-1.8.0]# ps aux | grep nginx


3)测试解析php

[root@yuan nginx-1.8.0]# vim /usr/local/nginx/conf/nginx.conf
找到 location = /50x.html {
            root   html;
        }  
在下面添加:
 location ~ \.php$ {
            root           html;
            fastcgi_pass  127.0.0.1:9000;#注意:这个要和php-fpm 中listen 一致
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
            include        fastcgi_params;
        }

重载测试
[root@yuan nginx-1.8.0]# /usr/local/nginx/sbin/nginx -s reload
[root@yuan nginx-1.8.0]# /usr/local/nginx/sbin/nginx -t

创建测试文件
[root@yuan nginx-1.8.0]# vim /usr/local/nginx/html/2.php

<?php
echo "hellp php!\n";
?>
测试
[root@yuan nginx-1.8.0]# curl localhost/2.php
hellp php!

4)nginx启动脚本和配置文件

[root@yuan html]# vim /etc/init.d/nginx
#!/bin/bash
# chkconfig: - 30 21
# description: http service.
# Source Function Library
. /etc/init.d/functions
# Nginx Settings


NGINX_SBIN="/usr/local/nginx/sbin/nginx"
NGINX_CONF="/usr/local/nginx/conf/nginx.conf"
NGINX_PID="/usr/local/nginx/logs/nginx.pid"
RETVAL=0
prog="Nginx"


start() {
        echo -n $"Starting $prog: "
        mkdir -p /dev/shm/nginx_temp
        daemon $NGINX_SBIN -c $NGINX_CONF
        RETVAL=$?
        echo
        return $RETVAL
}


stop() {
        echo -n $"Stopping $prog: "
        killproc -p $NGINX_PID $NGINX_SBIN -TERM
        rm -rf /dev/shm/nginx_temp
        RETVAL=$?
        echo
        return $RETVAL
}


reload(){
        echo -n $"Reloading $prog: "
        killproc -p $NGINX_PID $NGINX_SBIN -HUP
        RETVAL=$?
        echo
        return $RETVAL
}


restart(){
        stop
        start
}


configtest(){
    $NGINX_SBIN -c $NGINX_CONF -t
    return 0
}


case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  reload)
        reload
        ;;
  restart)
        restart
        ;;
  configtest)
        configtest
        ;;
  *)
        echo $"Usage: $0 {start|stop|reload|restart|configtest}"
        RETVAL=1
esac


exit $RETVAL


改权限开机启动
[root@yuan html]# chmod +x /etc/init.d/nginx
[root@yuan html]# chkconfig --add nginx
[root@yuan html]# chkconfig nginx on


5)更改nginx 配置


[root@yuan html]# mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak
[root@yuan html]# vim /usr/local/nginx/conf/nginx.conf
user nobody nobody;
worker_processes 2;
error_log /usr/local/nginx/logs/nginx_error.log crit;
pid /usr/local/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;


events
{
    use epoll;
    worker_connections 6000;
}


http
{
    include mime.types;
    default_type application/octet-stream;
    server_names_hash_bucket_size 3526;
    server_names_hash_max_size 4096;
    log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
    '$host "$request_uri" $status'
    '"$http_referer" "$http_user_agent"';
    sendfile on;
    tcp_nopush on;
    keepalive_timeout 30;
    client_header_timeout 3m;
    client_body_timeout 3m;
    send_timeout 3m;
    connection_pool_size 256;
    client_header_buffer_size 1k;
    large_client_header_buffers 8 4k;
    request_pool_size 4k;
    output_buffers 4 32k;
    postpone_output 1460;
    client_max_body_size 10m;
    client_body_buffer_size 256k;
    client_body_temp_path /usr/local/nginx/client_body_temp;
    proxy_temp_path /usr/local/nginx/proxy_temp;
    fastcgi_temp_path /usr/local/nginx/fastcgi_temp;
    fastcgi_intercept_errors on;
    tcp_nodelay on;
    gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 8k;
    gzip_comp_level 5;
    gzip_http_version 1.1;
    gzip_types text/plain application/x-javascript text/css text/htm application/xml;


server
{
    listen 80;
    server_name localhost;
    index index.html index.htm index.php;
    root /usr/local/nginx/html;


    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
    }


}
 include /usr/local/nginx/conf/vhosts/*.conf;
}


重载测试
[root@yuan html]# /usr/local/nginx/sbin/nginx -s reload
[root@yuan html]# /usr/local/nginx/sbin/nginx -t


重启nginx服务
[root@yuan html]# service nginx restart
停止 Nginx:                                               [确定]
正在启动 Nginx:                                           [确定]





至此lnmp环境搭建成功,中间有转载的别人的博客










评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值