CentOS6.5+nginx+mysql+php(laravel)服务器环境搭建

公司准备迭代会员中心项目,要上laravel框架,替代以前的Ecshop框架,PHP工程师将部分功能页面代码提交,自己也准备着手搭建一个测试环境将项目跑起来;

一、 环境依赖安装设置

关闭防火墙

[root@node5 ~]# service iptables stop

[root@node5 ~]# chkconfig iptables off

[root@node5 ~]# vim /etc/selinux/config

SELINUX=disabled

[root@node5 ~]# yum -y groupinstall "Development Tools" "Development Libraries"

gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre pcre-devel

二、 Nginx服务安装配置

编译安装

[root@node5 src]# tar -xvf nginx-1.8.0.tar.gz

[root@node5 src]# cd nginx-1.8.0

[root@node5 nginx-1.8.0]# ./configure --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module

[root@node5 nginx-1.8.0]#make –j 2&& make install;

文件配置

[root@node5 ~]# useradd -s /sbin/nologin nginx

[root@node5 ~]# vim /usr/local/nginx/conf/nginx.conf

2 #user  nobody;       #将此行注释掉

3  user nginx nginx;     #添加新的用户

 

44         location / {

45             root   html;

46             index index.php index.html index.htm;

47                   }

 

location ~ \.php$ {                                          #将这此行取消注释

 67             root           html;

 68             fastcgi_pass   127.0.0.1:9000;

 69             fastcgi_index  index.php;

 70             fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

 71             include        fastcgi_params;

 72         }

 

Nginx管理

[root@node5 ~]# /usr/local/nginx/sbin/nginx               #启动nginx

[root@node5 ~]# /usr/local/nginx/sbin/nginx -s reload      #平滑启动nginx

添加nginx启动脚本

#!/bin/bash

# nginx Startup script for the Nginx HTTP Server

# it is v.0.0.2 version.

# 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=/var/run/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: "

    #kill -HUP `cat ${nginx_pid}`

    killproc $nginxd -HUP

    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

[root@node5 ~]# chmod +x /etc/init.d/nginx                 #添加权限

设置开机启动

[root@node5 ~]# vim /etc/rc.local                            #在下面添加一行代码

/etc/init.d/nginx start

 

三、 Mysql服务安装配置

[root@node5 ~]# yum -y install cmake ncurses-devel

[root@node5 src]# tar -xvf mysql-5.6.26.tar.gz

[root@node5 src]# cd mysql-5.6.26

[root@node5 mysql-5.6.26]# useradd -s /sbin/nologin mysql

[root@node1 mysql-5.6.26]# cmake \

 -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \

 -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \

 -DDEFAULT_CHARSET=utf8 \

 -DDEFAULT_COLLATION=utf8_general_ci \

 -DWITH_EXTRA_CHARSETS=all \

 -DWITH_MYISAM_STORAGE_ENGINE=1\

 -DWITH_INNOBASE_STORAGE_ENGINE=1\

 -DWITH_MEMORY_STORAGE_ENGINE=1\

 -DWITH_READLINE=1\

 -DENABLED_LOCAL_INFILE=1\

 -DMYSQL_DATADIR=/usr/local/mysql/data \

 -DMYSQL-USER=mysql

[root@node5 mysql-5.6.26]#make –j 2 && make install;

[root@node5 mysql-5.6.26]# chown -R mysql:mysql /usr/local/mysql/

[root@node5 mysql-5.6.26]# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf

[root@node5 mysql-5.6.26]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

[root@node5 mysql-5.6.26]# vim /etc/init.d/mysqld

46 basedir=/usr/local/mysql

47 datadir=/usr/local/mysql/data

[root@node5 mysql-5.6.26]# chkconfig mysqld on

初始化数据库

[root@node5 mysql-5.6.26]# /usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --user=mysql

[root@node5 mysql-5.6.26]# ls /usr/local/mysql/data/

auto.cnf  ibdata1  ib_logfile0  ib_logfile1  mysql  node5.err  performance_schema  test

[root@node5 mysql-5.6.26]# service mysqld start                         #启动mysql服务

[root@node5 mysql-5.6.26]# ln -s /usr/local/mysql/bin/* /bin/

[root@node5 mysql-5.6.26]# mysql_secure_installation                    #设置初始密码

 

四、 编译安装PHP服务配置

[root@node5]#yum install -y libxml2-devel libcurl-devel libjpeg-devel libpng-devel freetype freetype-devel

[root@node5 src]# tar -xvf libmcrypt-2.5.8.tar.bz2

[root@node5 src]# cd libmcrypt-2.5.8

[root@node5 libmcrypt-2.5.8]# ./configure --prefix=/usr/local/libmcrypt

[root@node5 libmcrypt-2.5.8]#make && make install;

[root@node5 src]# tar -xvf php-5.6.13.tar.bz2

[root@node5 src]# cd php-5.6.13

需要添加到库文件路径

由于系统默认规定只在/lib、/lib64、/lib/lib64下面找库文件,所以我们需要手动添加进去。

[root@node5 src]# vim /etc/ld.so.conf

include ld.so.conf.d/*.conf                          #此行原有

/usr/local/libmcrypt/lib                             #此行添加

/usr/local/mysql/lib                                #此行添加

[root@node5 src]#ldconfig

[root@node5 src]# echo 'ldconfig' >> /etc/rc.local

[root@node5 php-5.6.13]#

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-mcrypt=/usr/local/libmcrypt

[root@node5 php-5.6.13]# make -j 2 && make install;

配置php和php-fpm文件

[root@node5 php-5.6.13]# cp /usr/local/src/php-5.6.13/php.ini-production /usr/local/php/php.ini

[root@node5 php-5.6.13]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

[root@node5 php-5.6.13]# vim /usr/local/php/etc/php-fpm.conf

149 user = nginx

150 group = nginx

 

配置PHP_FPM启动脚本

[root@node5 php-5.6.13]# cp /usr/local/src/php-5.6.13/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

[root@node5 php-5.6.13]# chmod +x /etc/init.d/php-fpm

[root@node5 php-5.6.13]# /etc/init.d/php-fpm start

[root@node5 php-5.6.13]# chkconfig php-fpm on          #设为开机启动

 

五、 配置数据库和网站代码发布

数据库还原

mysql> create databases zmqdb;

[root@node5 home]# mysql -uroot -p zmqdb<zmqdb.sql

修改数据库配置连接

[root@node5 html]# vim .env

DB_CONNECTION=mysql

DB_HOST=127.0.0.1

DB_PORT=3306

DB_DATABASE=zmqdb

DB_USERNAME=root

DB_PASSWORD=******

代码配置

将代码上传到nginx网站默认目录(/usr/local/nginx/html)

[root@node5 conf]# vim /usr/local/nginx/conf/nginx.conf                              #修改路径

root       /usr/local/nginx/html/public;

设置网站访问权限

[root@node5 html]# chown -R nginx:nginx html/

[root@node5 nginx]# chmod 755 -R html/

六、 其它

后台管理访问路径:IP+/admin/login

移动端访问路径:IP+/mobile/login

框架日志目录:storage/logs/

测试的时候可以打 开项目的报错信息: [root@node5 nginx]# vim html/config/app.php

'debug'           => true

七、 测试

移动端                                                                 后台管理                         

 

posted on 2017-01-13 13:49  空空道长  阅读(556)  评论(0编辑  收藏  举报

导航