santaclaus 发表于 2017-12-23 19:54:21

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

  公司准备迭代会员中心项目,要上laravel框架,替代以前的Ecshop框架,PHP工程师将部分功能页面代码提交,自己也准备着手搭建一个测试环境将项目跑起来;
  一、 环境依赖安装设置
  关闭防火墙
# service iptables stop
# chkconfig iptables off
# vim /etc/selinux/config
  SELINUX=disabled
# yum -y groupinstall "Development Tools" "Development Libraries"
  gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre pcre-devel
  二、 Nginx服务安装配置
  编译安装
# tar -xvf nginx-1.8.0.tar.gz
# cd 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
#make –j 2&& make install;
  文件配置
# useradd -s /sbin/nologin nginx
# vim /usr/local/nginx/conf/nginx.conf
  2 #usernobody;       #将此行注释掉
  3user 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_indexindex.php;
  70             fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;
  71             include      fastcgi_params;
  72         }
  Nginx管理
# /usr/local/nginx/sbin/nginx               #启动nginx

# /usr/local/nginx/sbin/nginx -s>  添加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() {
  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)

  >  ;;
  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               #添加权限
  设置开机启动
# vim /etc/rc.local                            #在下面添加一行代码
  /etc/init.d/nginx start
  三、 Mysql服务安装配置
# yum -y install cmake ncurses-devel
# tar -xvf mysql-5.6.26.tar.gz
# cd mysql-5.6.26
# useradd -s /sbin/nologin mysql
# 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
#make –j 2 && make install;
# chown -R mysql:mysql /usr/local/mysql/
# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
# vim /etc/init.d/mysqld
  46 basedir=/usr/local/mysql
  47 datadir=/usr/local/mysql/data
# chkconfig mysqld on
  初始化数据库
# /usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --user=mysql
# ls /usr/local/mysql/data/
  auto.cnfibdata1ib_logfile0ib_logfile1mysqlnode5.errperformance_schematest
# service mysqld start                         #启动mysql服务
# ln -s /usr/local/mysql/bin/* /bin/
# mysql_secure_installation                  #设置初始密码
  四、 编译安装PHP服务配置
#yum install -y libxml2-devel libcurl-devel libjpeg-devel libpng-devel freetype freetype-devel
# tar -xvf libmcrypt-2.5.8.tar.bz2
# cd libmcrypt-2.5.8
# ./configure --prefix=/usr/local/libmcrypt
#make && make install;
# tar -xvf php-5.6.13.tar.bz2
# cd php-5.6.13
  需要添加到库文件路径
  由于系统默认规定只在/lib、/lib64、/lib/lib64下面找库文件,所以我们需要手动添加进去。
# vim /etc/ld.so.conf
  include ld.so.conf.d/*.conf                        #此行原有
  /usr/local/libmcrypt/lib                           #此行添加
  /usr/local/mysql/lib                              #此行添加
#ldconfig
# echo 'ldconfig' >> /etc/rc.local
#
  ./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
# make -j 2 && make install;
  配置php和php-fpm文件
# cp /usr/local/src/php-5.6.13/php.ini-production /usr/local/php/php.ini
# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
# vim /usr/local/php/etc/php-fpm.conf
  149 user = nginx
  150 group = nginx
  配置PHP_FPM启动脚本
# cp /usr/local/src/php-5.6.13/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
# chmod +x /etc/init.d/php-fpm
# /etc/init.d/php-fpm start
# chkconfig php-fpm on          #设为开机启动
  五、 配置数据库和网站代码发布
  数据库还原
  mysql> create databases zmqdb;
# mysql -uroot -p zmqdb<zmqdb.sql
  修改数据库配置连接
# 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)
# vim /usr/local/nginx/conf/nginx.conf                              #修改路径
  root       /usr/local/nginx/html/public;
  设置网站访问权限
# chown -R nginx:nginx html/
# chmod 755 -R html/
  六、 其它
  后台管理访问路径:IP+/admin/login
  移动端访问路径:IP+/mobile/login
  框架日志目录:storage/logs/
  测试的时候可以打 开项目的报错信息: # vim html/config/app.php
  'debug'         => true
  七、 测试
  移动端                                                               后台管理                        
页: [1]
查看完整版本: CentOS6.5+nginx+mysql+php(laravel)服务器环境搭建