iT邦幫忙

0

laravel8 10分鐘保證完成

https://1.bp.blogspot.com/-VB4ZiWHc7nk/YDTI7Ov-pmI/AAAAAAAAJqA/2vzGICKhlmUJQb1sQbyiKdfI2ZugRW96ACLcBGAsYHQ/w400-h168/qtwqedl51vqx5zkxa65d.png

軟體 版本
PHP php7.3
WebService nginx
FRAMEWORK Laravel8
OS centos7.2

1.安裝相關套件

yum update
yum install wget
yum install epel-release //更新後才可執行 sudo yum install php-mcrypt*
sudo yum install php-mcrypt* //laravel 會使用到的套件
sudo yum install php-xml //laravel-reactjs 會使用到的套件

2.安裝 nginx

rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

yum install nginx

開通80port服務
iptables -I INPUT -p tcp --dport 80 -j ACCEPT

vi /etc/nginx/conf.d/default.conf

將內容整個砍掉 ,複製貼上底下內容即可
( 注記得修改 root /usr/share/nginx/html/{app-name}/public 位置) 


server {
    listen       80;
    server_name  localhost;
    root   /usr/share/nginx/html/APP-name/public;
    index index.php index.html index.htm;
    location / {
         try_files $uri $uri/ /index.php?$query_string;
    }
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        proxy_connect_timeout 159s;
  proxy_send_timeout   600;
  proxy_read_timeout   600;
  proxy_buffer_size    64k;
  proxy_buffers     16 32k;
  proxy_busy_buffers_size 64k;
  proxy_temp_file_write_size 64k;
  proxy_pass_header Set-Cookie;
  proxy_redirect     off;
  proxy_hide_header  Vary;
  proxy_set_header   Accept-Encoding '';
  proxy_ignore_headers Cache-Control Expires;
  proxy_set_header   Referer $http_referer;
  proxy_set_header   Host   $host;
  proxy_set_header   Cookie $http_cookie;
  proxy_set_header   X-Real-IP  $remote_addr;
  proxy_set_header X-Forwarded-Host $host;
  proxy_set_header X-Forwarded-Server $host;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

3.安裝PHP7.3 ( laravel8需要php7.3 否則會報錯)
laravel對映PHP對照表

安裝 php5.4
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
  
sudo yum install php-mbstring  //laravel 會使用到的套件
yum install php php-mysql php-fpm 

更新到 php7.2
yum install epel-release yum-utils -y
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum-config-manager --enable remi-php72
yum install php php-common php-opcache php-mcrypt php-cli php-gd php-curl php-mysql -y


更新到 php7.3
sudo yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm 
sudo yum -y install epel-release yum-utils

sudo yum-config-manager --disable remi-php54
sudo yum-config-manager --enable remi-php73

4.修改PHP設定檔

修改 php設定檔
/etc/php7/fpm/php-fpm.d/www.conf
有些是放在 /etc/php-fpm.d/www.conf

如果你是用nginx就改成nginx 是apache就改apache
user = nginx
group = nginx
listen = /var/run/php7.3-fpm.sock
listen.owner = nginx
listen.group = nginx
listen.mode = 0660

5.調整nginx conf設定

location ~ \.php$ {
    try_files $uri =404;
    fastcgi_pass unix:/var/run/php7.3-fpm.sock;

fastcgi_pass 調整為 /var/run/php7.3-fpm.sock

6.安裝 composer

sudo yum install php-cli php-zip wget unzip

找一位置放置 composer-setup
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

並在此位置下 執行
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer

7.使用composer建立專案

composer create-project laravel/laravel app-name --ignore-platform-reqs
並對資料夾app-name設定權限 chmod -R 775 app-name
**app-name為您要創建的專案資料夾名稱**
php artisan --version //確認安裝版本
Laravel Framework 8.28.1

8.設定SElinux關閉

設定SELinux
vi /etc/selinux/config
由原本 #SELINUX=enforcing 改為 SELINUX=disabled
SELinux是 Security Enhanced Linux (安全加強的 Linux) 的縮寫, 
他並不是一個防火牆的軟體,而是一個『針對檔案系統權限作更細部規劃的一個模組』。

在fb一些laravel社團裡有人提到
怎樣可以快速還原安裝環境
建議把以上指定 做成 SSH腳本 放在BIN中
下次即可一鍵執行


尚未有邦友留言

立即登入留言