1、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.bat:
@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.box
vagrant box add --name homestead/10.0 homestead_virtualbox.box
vagrant box list #检查
进入安装目录:D:\WorkPlace\wwwroot
创建 Vagrantfile 文件:
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启动虚拟机:
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-tools
sudo apt-get install net-tools util-linux -y
sudo nginx -s reload
netstat -lunpt
测试访问 http://127.0.0.1:8080/ ,可以看到Nginx页面。
d.传统框架启动
在命令行启动laravel
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
修改初始密码:
DB_USERNAME=homestead
DB_PASSWORD=secret
启动测试
#注意启动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。
使用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。
2、安装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
3、使用宝塔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,打不开卸载重装。
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。