1. 1. 安装screen(可不用)
  2. yum install screen
  3. 2. 安装wget
  4. yum install wget
  5. 3. 更新yum
  6. yum update
  7. 4. 安装额外资源库
  8. yum install epel-release
  9. 5. 新建www用户,并加入所属组 dev
  10. adduser -g dev linfeng
  11. 6. 设置密码
  12. passwd linfeng
  13. 7. 添加到附加组wheel(视用户添加)
  14. usermod -G wheel linfeng

    8、将www目录的所有者改为 linfeng,所有组改为 dev
    chown -R linfeng:dev /data/www

 ——所属组会赋予项目目录www的所有者,附加组 wheel 有 sudo 的权限

 

  1. 1. 安装
  2. sudo yum install nginx
  3. 2. 启动nginx
  4. sudo systemctl start nginx
  5. 3. 设置为开机启动
  6. sudo systemctl enable nginx.service
  7. 4. 检查开机自动是否设置成功
  8. systemctl list-dependencies | grep nginx
  9. 5、检测状态:
  10. systemctl status -l nginx.service //检测服务是否激活
  11. wget http://127.0.0.1 //检测nginx是否正常运行

    6、访问服务器公网 IP 地址,看是否可以访问
  12. 注: 项目目录默认在 /var/www/
  13. 配置文件在 /etc/nginx/
    nginx配置文件为:/etc/nginx/nginx.conf
    默认虚拟主机位置为:/etc/nginx/conf.d(一般我们会在 nginx.conf 中配置到 /data/vhost下,把项目代码、虚拟主机配置等放在一起好维护。
    安装好默认的提示页地址在:/usr/share/nginx/html 之下

 

查看 nginx 的配置文件位置:

  1. nginx -t

 

 

 

三、 安装mariaDB

——由于直接 yum 安装的是 5.5 的版本,我们需要更高的版本

1、配置信息员

  1. 1、配置 yum 源码
  2. vi /etc/yum.repos.d/MariaDB.repo
  3. 2、配置阿里云的镜像
  4. [mariadb]
  5. name = MariaDB
  6. baseurl = https://mirrors.aliyun.com/mariadb/yum/10.4/centos7-amd64/
  7. gpgkey=https://mirrors.aliyun.com/mariadb/yum/RPM-GPG-KEY-MariaDB
  8. gpgcheck=1

  9. 3、清除 yum 缓存
  10. yum clean all
  11. yum makecache

 

 

2、安装Mariadb:

  1. // 安装
    yum install mariadb mariadb
    -server
  2. // 启动mariaDB
  3. systemctl start mariadb
  4. // 设置密码等配置
  5. mysql_secure_installation //会开始做一些密码等配置
  6.  
  7. // 开启自启动mariaDB
  8. systemctl enable mariadb

 

3、设置用户和权限

  1. // 登录mariaDB
  2. mysql -uroot -p123456
  3. // 创建任意主机能登录的用户名和密码
  4. CREATE USER \'username\'@\'%\' IDENTIFIED BY \'password\';
  5. // 赋予该用户权限(只能root用户赋予,新用户无权限)
  6. GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, FILE, INDEX, ALTER, SHOW DATABASES, CREATE TEMPORARY TABLES, CREATE VIEW, EVENT, TRIGGER, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, EXECUTE ON *.* TO \'username\'@\'%\' REQUIRE NONE WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0;
  7. // 刷新权限
  8. flush privileges;
  9. // 退出mysql,重启mysql服务
  10. systemctl restart mariadb.service
  11. // 修改密码(如果需要)
  12. SET password for \'root\'@\'localhost\'=password(\'newpassword\');

 

 

查看所有数据库用户权限:

  1. SELECT DISTINCT CONCAT(\'User: \'\'\',user,\'\'\'@\'\'\',host,\'\'\';\') AS query FROM mysql.user;

查看某用户权限:

  1. show grants for \'username\'@\'%\';

 

备注:卸载数据库:(如果要升级,其实就是备份数据,卸载版本,然后配置高版本yum 源,重装即可)

  1. # 备份数据库,如果升级顺利是不要实施备份还原的
  2. mysqldump -u root -p --all-databases > alldb.sql
  3. # 如果想保留自己的my.cof配置,则备份一下这个文件
  4. cp /etc/my.cnf /etc/my.cnf.bak
  5. # 停止数据库运行
  6. systemctl stop mariadb
  7. # 卸载MariaDB老版本
  8. yum remove mariadb mariadb-server

 

 

 

 

 

  1. 1. 安装php72的源
  2. rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
  3. rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
  4.  
  5. 2. 安装php72
  6. yum -y install php72w php72w-fpm
  7. 3. 安装常用拓展(7.2)
  8. yum -y install php72w-mbstring php72w-common php72w-gd php72w-mcrypt
  9. yum -y install php72w-mysql php72w-xml php72w-cli php72w-devel
  10. yum -y install php72w-pecl-memcached php72w-pecl-redis php72w-opcache
  11. // 一条命令
  12. yum -y install php72w-mbstring php72w-common php72w-gd php72w-mcrypt php72w-mysql php72w-xml php72w-cli php72w-devel php72w-pecl-memcached php72w-pecl-redis php72w-opcache
  13. 4. 重新加载php
  14. systemctl reload php-fpm //没有启动把reload改成start
  15.  
  16. 5. 验证php是否安装成功
  17. php -v
  18. 6. 验证对应的扩展是否安装成功
  19. php -m
  20. 7. 启动php-fpm
  21. service php-fpm start
  22. 8. 设置开机自启动
  23. systemctl enable php-fpm.service
  24. 9. 检查开机自启动是否设置成功
  25. systemctl list-dependencies | grep php-fpm
  26. ps -ef | grep php-fpm

 

查看 PHP-FPM 监听端口:

  1. cat /etc/php-fpm.d/www.conf |grep -i \'listen =\'

返回的是:listen = 127.0.0.1:9000,表明 PHP-FPM 默认配置的监听端口为 9000,只需修改配置,将 PHP 解析的请求转发到 127.0.0.0:9000 处理即可。

 

 

 

5、安装composer

 

  1. 1、下载composer
  2. curl -sS https://getcomposer.org/installer | php
  3. 或者
  4. # php -r "copy(\'https://install.phpcomposer.com/installer\', \'composer-setup.php\');"
  5. # php composer-setup.php
  6. 2、移动到bin之下
  7. mv composer.phar /usr/bin/composer
  8. 3、使用中国镜像包
  9. composer config -g repo.packagist composer https://packagist.phpcomposer.com
  10. 注:可以使用yum进行下载composer

 

 

 

 

6、安装git(若无)

  1. 1. 下载安装git
  2. yum -y install git
  3. 2. 检查是否安装成功
  4. git --version

 

7、安装项目laravel:

  1. composer create-project laravel/laravel --prefer-dist laravel "5.3.*" //指定安装5.3.*版本,不加则安装最新稳定版
  2. composer create-project --prefer-dist laravel/laravel laravel //安装最新稳定版

 

8、给laravel赋予权限:

  1. 以上操作针对的都是root用户,需要开放网站访问用户权限
  2. 1. /var/www/项目名 设置权限
  3. sudo chown -R :www /var/www/项目名
  4. 2、以上方法不行,则给storage目录权限
  5. chmod -R 777 storage

 

9、设置nginx配置文件:

  1. 1. 进入nginx目录下的conf.d文件夹
  2. cd /etc/nginx/conf.d/
  3.  
  4. 2. 新建一个自己网站的配置文件
  5. vim laravel.besunway.com.conf

 

—— TP5 的配置:

  1. server {
  2. listen 80;
  3. set $root /data/www/shua/public/;
  4. server_name shua.besunway.com;
  5. root $root;
  6. index index.php index.html index.htm;
  7. location / {
  8. if (!-e $request_filename) {
  9. rewrite ^(.*)$ /index.php?s=/$1 last;
  10. }
  11. }
  12. location ~ index\.php {
  13. root $root;
  14. fastcgi_pass 127.0.0.1:9000;
  15. fastcgi_index index.php;
  16. fastcgi_param SCRIPT_FILENAME $root$fastcgi_script_name;
  17. include fastcgi_params;
  18. }
  19. }

 

—— Laravel的配置:

  1. server {
  2. listen 80;
  3. set $root /data/www/shua/public/;
  4. server_name shua.besunway.com;
  5. root $root;
  6. index index.php index.html index.htm;
  7. if (!-e $request_filename) {
  8. rewrite ^/(.*) /index.php?$1 last;
  9. }
  10. location ~ index\.php {
  11. root $root;
  12. fastcgi_pass 127.0.0.1:9000;
  13. fastcgi_index index.php;
  14. fastcgi_param SCRIPT_FILENAME $root$fastcgi_script_name;
  15. include fastcgi_params;
  16. }
  17. }

 

————配置完成,重启nginx:

  1. systemctl restart nginx //或者
  2. service nginx reload

 

 

备注:

虚拟主机配置目录:/etc/nginx/conf.d/

项目一般位置:/var/www/   (若有数据盘挂载,可以自己创建并放在其他盘,如/www或者/data/www

NGINX初始网站根目录:/usr/share/nginx/html

日志目录:/var/log/nginx

使用yum安装的软件一般在/etc/ 目录下

 

 

10、设置不允许 IP 访问:

  1. // 编辑文件
  2. vim /etc/nginx/nginx.conf
  3. // 添加内容,使用IP访问,则返回403
  4. server {
  5. listen 80 default;
  6. server_name _;
  7. return 403;
  8. }
  9. // 删除默认内容
  10. server {
  11. listen 80 default_server;
  12. listen [::]:80 default_server;
  13. server_name _;
  14. root /usr/share/nginx/html;
  15. # Load configuration files for the default server block.
  16. include /etc/nginx/default.d/*.conf;
  17. location / {
  18. }
  19. error_page 404 /404.html;
  20. location = /40x.html {
  21. }
  22. error_page 500 502 503 504 /50x.html;
  23. location = /50x.html {
  24. }
  25. }

 

 

 

 

99、常用命令:

  1. 1. nginx相关命令(sudo看情况加)
  2. 1. 启动nginx
  3. sudo systemctl start nginx
  4. 或者:
  5. service nginx start
  6. 2. 重启ngnix
  7. sudo systemctl restart nginx
  8. 或者:
  9. service nginx restart
  10. 3. 关闭nginx
  11. sudo systemctl stop nginx
  12. 或者:
  13. service nginx stop
  14. 4. 查看nginx状态
  15. sudo sysemctl status nginx
  16. 或者:
  17. service nginx status
  18. 2. php服务相关命令
  19. 1. 启动php-fpm
  20. systemctl start php-fpm
  21. 或者:
  22. service php-fpm start
  23. 2. 关闭php-fpm
  24. systemctl stop php-fpm
  25. 或者:
  26. service php-fpm stop
  27. 3. 重启php-fpm
  28. systemctl restart php-fpm
  29. 或者:
  30. service php-fpm restart
  31. 4. 查看php-fpm状态
  32. systemctl status php-fpm
  33. 或者:
  34. service php-fpm status

 

 

 

 

 

 

 

 

 

 

 

 

————占位符

版权声明:本文为windyet原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/windyet/articles/9211594.html