设为首页 收藏本站
查看: 1149|回复: 0

LNMP搭建与环境配置

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-11-30 09:05:23 | 显示全部楼层 |阅读模式
系统版本centos6.5


一、安装MySQL

1.下载MySQL

wget http://mirrors.sohu.com/mysql/My ... bc2.5-x86_64.tar.gz

2.解压MySQL

tar -zxvf mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz

3.将解压出的数据移到/usr/local/mysql

mv mysql-5.6.26-linux-glibc2.5-x86_64 /usr/local/mysql

4.建立MySQL用户

useradd -s /sbin/nologin mysql

5.初始化

[iyunv@localhost src]# cd /usr/local/mysql
[iyunv@localhost mysql]# mkdir -p /data/mysql ; chown -R mysql:mysql /data/mysql
[iyunv@localhost mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
6.修改环境配置
[iyunv@localhost mysql]# cp support-files/my-default.cnf /etc/my.cnf
[iyunv@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld
# chmod 755 /etc/init.d/mysqld
# vim /etc/init.d/mysqld
修改basedir=/usr/local/mysql
    datadir=/data/mysql
#vim /etc/my.cnf
修改basedir = /usr/local/mysql
    datadir = /data/mysql
    port = 3306
    socket = /tmp/mysql.sock
    server_id = 1
7.启动MySQL
service mysqld start

二、安装PHP

1.下载php源码包

#cd /usr/local/src/

#wget http://au1.php.net/distributions/php-5.4.44.tar.bz2

2.解压源码包,创建账号

# tar jxf php-5.4.44.tar.bz2 # useradd -s /sbin/nologin php-fpm 该账号用来运行php-fpm服务,在LNMP环境中,php是以一个服务来提供服务的。

3.配置编译选项

#cd php-5.4.44

# ./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=/tmp/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    --disable-ipv6     --with-curl

编译过程中会碰到下面这些错误:



checking for cc... no

checking for gcc... no

configure: error: in `/usr/local/src/php-5.4.37':

configure: error: no acceptable C compiler found in $PATH

See `config.log' for more details

解决办法:yum install -y gcc

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

解决办法:yum install -y libxml2-devel

③configure: error: Please reinstall the libcurl distribution -

    easy.h should be in <curl-dir>/include/curl/

解决办法:yum install -y curl-devel

④configure: error: jpeglib.h not found.

解决办法:yum install -y libjpeg libjpeg-devel

⑤configure: error: png.h not found.

解决办法:

yum install -y libpng libpng-devel

⑥configure: error: freetype-config not found.

解决办法:yum install -y freetype freetype-devel

⑦configure: error: mcrypt.h not found. Please reinstall libmcrypt.

解决办法:因为yum库是没有这个包的,所以要去下载个第三方yum源

rpm -ivh "http://www.aminglinux.com/bbs/data/attachment/forum/month_1211/epel-release-6-7.noarch.rpm"

然后yum install -y  libmcrypt-devel

3.make && make install

4.修改配置文件

[iyunv@localhost php-5.4.37]# cp php.ini-production /usr/local/php/etc/php.ini

[iyunv@localhost php-5.4.37]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

[iyunv@localhost php-5.4.37]# mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

[iyunv@localhost php-5.4.37]# chmod 755 /etc/init.d/php-fpm

5.启动php

service php-fpm start

三、安装nginx

    下载nginx源码包

#wget http://nginx.org/download/nginx-1.6.3.tar.gz

2.解压

# tar -zxvf nginx-1.6.3.tar.gz

3.cd nginx-1.6.3

# ./configure   --prefix=/usr/local/nginx   --with-pcre

可能会碰到

./configure: error: the HTTP rewrite module requires the PCRE library.

You can either disable the module by using --without-http_rewrite_module

option, or install the PCRE library into the system, or build the PCRE library

statically from the source with nginx by using --with-pcre=<path> option.

解决办法:yum install -y pcre pcre-devel

4.make && make install

5.编译启动脚本

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

保存后

# chmod 755 /etc/init.d/nginx

6.配置解析php

vim /usr/local/nginx/conf/nginx.conf

更改这一部分,将#注释去掉

location ~ \.php$ {

            root           html;

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;

            fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;

            include        fastcgi_params;

        }


7.重新加载

/usr/local/nginx/sbin/nginx -s reload

8.测试是否解析php文件

# vim /usr/local/nginx/html/1.php

<?php

    phpinfo();

?>

~

9.curl localhost/1.php或者web浏览器上http://本机ip/1.php

如果解析,LNMP搭建成功

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-145147-1-1.html 上篇帖子: lnmp 虚拟主机的配置 下篇帖子: lamp的搭建blog
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表