Skip to content

Instantly share code, notes, and snippets.

@zhuzhichao
Last active July 23, 2020 04:34
Show Gist options
  • Save zhuzhichao/32b8aa25d111ef78987f48f5a0addb42 to your computer and use it in GitHub Desktop.
Save zhuzhichao/32b8aa25d111ef78987f48f5a0addb42 to your computer and use it in GitHub Desktop.

CentOS 7 服务器部署 php/nginx/node/laravel

以下命令,非特别说明,都是在 root 下执行

安装工具包

yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum -y install yum-utils
yum-config-manager --enable remi-php74
yum update
yum install git htop
yum install gcc+ gcc-c++

新增 www 用户

useradd www
groupadd  www-data
usermod -g www-data www

进入 www 用户

su - www

退出 www 用户到 root

exit

安装 php nginx

  1. 安装,一定要检查终端输出的表格中,php 是否为 7.4 版本

yum install nginx php php-fpm php-common php-xml php-mbstring php-json php-zip php-pecl-redis5 php-mysqlnd php-opcache php-mcrypt php-xml

  1. 开机启动
systemctl start php-fpm nginx
systemctl enable php-fpm nginx
systemctl status php-fpm nginx
  1. composer
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php --install-dir=/usr/local/bin --filename=composer

配置 php

vi /etc/php-fpm.d/www.conf

user = www
group = www-data

listen = /run/php-fpm/www.sock

listen.owner = nginx
listen.group = nginx
listen.mode = 066

配置 NGINX

vi /etc/nginx/conf.d/mysite.com.conf

server {
    listen      80;
       server_name mysite.com;
       root        /var/www/html/mysite.com/public;
       index       index.php;

       charset utf-8;
       gzip on;
    gzip_types text/css application/javascript text/javascript application/x-javascript  image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon;
        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }

        location ~ \.php {
                include fastcgi.conf;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/run/php-fpm/www.sock;
        }
        location ~ /\.ht {
                deny all;
        }
}

拉取代码

mkdir /www
mkdir /www/wwwroot

下面是切换到 www 用户

su - www

下面是在 www 用户下执行的,其中 cat 里面获取的内容放到 github 上

ssh-keygen
cat ~/.ssh/id_rsa.pub
cd /www/wwwroot
git clone git@github.com:a/b.git

在 www 用户下执行下面两行

crontab -e

* * * * * cd /www/wwwroor/you-web && /usr/bin/php artisan schedule:run >> /dev/null 2>&1

node

curl -sL https://rpm.nodesource.com/setup_14.x | bash -
yum install -y nodejs

curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
yum install yarn

代理

全局

export http_proxy="http://36.0.0.1:6152"

export http_proxy="http://36.0.0.1:6152"

取消全局代理

unset http_proxy

unset https_proxy

git 代理

git config --global http.proxy socks5://36.0.0.1:6153

git config --global https.proxy socks5://36.0.0.1:6153

取消 git 代理

git config --global --unset http.proxy

git config --global --unset https.proxy

npm config delete proxy

端口

关闭端口号:

iptables -A OUTPUT -p tcp --dport 端口号-j DROP

打开端口号:

iptables -A INPUT -ptcp --dport 端口号-j ACCEPT

netstat -an | grep 8080 (查看是否打开8080端口)

常用命令

vi /etc/php-fpm.d/www.conf
vi /etc/nginx/conf.d/novel.conf
systemctl restart nginx
systemctl restart php-fpm


git remote set-url origin git@github.com:a/b.git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment