phpstorm使用

一、win10環境搭建

a.配置本機composer命令行環境

下載php:https://windows.php.net/downloads/releases/php-7.4.8-nts-Win32-vc15-x64.zip
以及composer:https://github.com/composer/composer/releases/download/1.10.9/composer.phar、配置環境變量,
方便使用composer命令行環境 編寫composer.batphp

@php "%~dp0composer.phar" config -g repo.packagist composer https://mirrors.aliyun.com/composer/

b.vagrant安裝環境

首先測試homestead:初始化homestead環境,迅雷下載:https://vagrantcloud.com/laravel/boxes/homestead/versions/10.0.0/providers/virtualbox.boxhtml

vagrant box add --name homestead/10.0 homestead_virtualbox.box
vagrant box list #檢查

進入安裝目錄:D:\WorkPlace\wwwroot
建立 Vagrantfile 文件:node

Vagrant.configure("2") do |config|
  config.vm.box = "homestead/10.0"
  config.vm.hostname = "homestead"
  config.vm.network "forwarded_port", guest: 80, host: 80, host_ip: "127.0.0.1"
  config.vm.network "forwarded_port", guest: 8080, host: 8080, host_ip: "127.0.0.1"
  config.vm.network "forwarded_port", guest: 9501, host: 9501, host_ip: "127.0.0.1"
  config.ssh.password = "123456"
  config.vm.provider "virtualbox" do |vb|
    vb.memory = "2048"
    vb.cpus = 4
  end
end

切換根目錄到爲當前根目錄、或根目錄的子目錄,使用PHPstorm啓動虛擬機:linux

vagrant up

c.nginx和網絡工具

vagrant ssh
#添加配置文件
sudo vim /etc/nginx/conf.d/nginx.conf
#限速
limit_req_zone $binary_remote_addr zone=mylimit:10m rate=100r/s;
server {
        listen       80;
        server_name  local.com;

        location / {
            root   /vagrant;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        location ~ \.php$ {
            limit_req zone=mylimit burst=1000 nodelay;
            root            /vagrant;
            fastcgi_index   index.php;
            fastcgi_pass    127.0.0.1:9000;
            fastcgi_param   SCRIPT_FILENAME  /$document_root$fastcgi_script_name;
            # --php-fpm 的工做目錄
            #fastcgi_param   SCRIPT_FILENAME   /vagrant$fstcgi_script_name;
            include         fastcgi_params;
        }
}

安裝net-toolsnginx

sudo apt-get install net-tools util-linux -y
sudo nginx -s reload
netstat -lunpt

測試訪問 http://127.0.0.1:8080/ ,能夠看到Nginx頁面。laravel

d.傳統框架啓動

在命令行啓動laravel

使用文檔git

composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
mkdir /vagrant/framework && cd /vagrant/framework
composer create-project --prefer-dist laravel/laravel && cd laravel

修改初始密碼:github

DB_USERNAME=homestead
DB_PASSWORD=secret

啓動測試docker

#注意啓動host是0.0.0.0,監聽全部
php artisan serve --host=0.0.0.0 --port=8080 &
sudo netstat -lunpt|grep 8080
#kill -9 4085

測試訪問 http://127.0.0.1:8080/ ,OK。shell

使用fpm訪問靜態PHP文件
#查看 vim /etc/php/7.4/fpm/pool.d/www.conf 轉發監聽狀況
fastcgi_pass    127.0.0.1:9000;
==> fastcgi_pass    unix:/run/php/php7.4-fpm.sock;
ps -ef|grep php-fpm #sudo kill -9
sudo /usr/sbin/php-fpm7.4

測試訪問 http://127.0.0.1:8080/index.php ,OK。

二、安裝swoole和phpmyadmin

a.openssl+swoole,hyperf安裝

composer require swoole/ide-helper -v 已經內置

swoole以及openssl擴展的安裝

cd /opt
sudo wget https://www.php.net/distributions/php-7.4.8.tar.xz
sudo tar -Jxf php-7.4.8.tar.xz

cd php-7.4.8/ext/openssl
==> sudo cp config0.m4 config.m4
sudo ./configure --with-openssl --with-php-config=/usr/bin/php-config
==> sudo apt-get install pkg-config
sudo make && make install

按照提示
sudo pecl channel-update pecl.php.net
sudo pecl install swoole
sudo vim /etc/php/7.4/cli/php.ini
啓用openssl,swoole擴展,swoole.use_shortname=0

暫時安裝不成功
使用下面成功

cd /vagrant/framework
#composer config -g --unset repos.packagist
git clone https://github.com/hyperf/hyperf-skeleton.git
cd hyperf-skeleton
composer install -vvv
cp .env.example .env
#修改數據庫信息,啓動

b.docker環境phpmyadmin

因爲本例安裝git和composer安裝pma失敗,因此採用docker鏡像。
https://docs.docker.com/engine/install/ubuntu/
注意完成reboot

docker network create mybridge --subnet=172.1.0.0/16
docker network create others --subnet=111.0.0.0/8 
# 10.0.2.15 vagrant本機IP
docker pull phpmyadmin/phpmyadmin
docker run -d --name pma \
    --restart=always \
    --network=mybridge --ip=172.1.112.11 \
    -e PMA_HOST=10.0.2.15 \
    phpmyadmin/phpmyadmin

nginx配置proxy_pass代理到這個固定地址的容器

limit_req_zone $binary_remote_addr zone=mylimit:10m rate=100r/s;
# 轉發域名1: db.dev 這裏域名轉發失敗了,直接用localhost
server {
    listen       80;
    server_name  localhost;
    limit_req zone=mylimit burst=1000 nodelay;
    location / {
        proxy_pass http://172.1.112.11:80/;
    }
}
使用 homestead / secret 登陸PHPmyadmin

三、使用寶塔Linux面板環境

寶塔有很好的UI,後期運維優點很明顯。

a.安裝寶塔

查看官網說兼容性最好的是centos8,因此使用centos8鏡像。

#vagrant add generic/centos8
下載
https://vagrantcloud.com/generic/boxes/centos8/versions/3.0.20/providers/virtualbox.box
vagrant box add --name centos8 virtualbox.box
#添加Vagrantfile文件
Vagrant.configure("2") do |config|
    config.vm.box = "centos8"
    config.vm.hostname = "centos8"
    config.vm.synced_folder "../", "/wwwroot/"

    config.vm.network "private_network", ip: "192.168.1.11"

    config.vm.provider "virtualbox" do |vb|
        vb.memory = "6072"
        vb.cpus = 4
    end
    config.ssh.password = "123456" #默認vagrant
    config.vm.provision "shell", inline: <<-SHELL
        sudo su && sed -i "s/PasswordAuthentication no/# PasswordAuthentication no/" "/etc/ssh/sshd_config" && systemctl restart sshd
    SHELL
end

6g內存是由於後面使用MySQL8.0提示須要。

yum install -y wget && wget -O install.sh http://download.bt.cn/install/install_6.0.sh && sh install.sh 27220f
----
Bt-Panel: http://153.34.17.147:8888/010ccdd8
username: qxcastvz
password: ce309bd3

完成添加端口, vagrant reload

config.vm.network "forwarded_port", guest: 8888, host: 8888, host_ip: "127.0.0.1"

打開 http://127.0.0.1:8888/010ccdd8/

b.安裝環境和插件

寶塔命令大全
修改端口重啓後,使用快速安裝 安裝lnmp。

切換主PHP版本
sudo ln -sf /www/server/php/74/bin/php /usr/bin/php
讀取權限文件夾 *
open_basedir = "/wwwroot/:/www/:/tmp/:/proc/"

在相應php版本的設置裏設置。或者直接把這個註釋掉,後面composer install的各類莫名其妙的錯誤,很大緣由是這個。

C.堡塔終端

https://download.bt.cn/ssh/BT-Term.exe安裝Redis,打不開卸載重裝。

相關文章
相關標籤/搜索