本篇内容介绍了“如何搭建PHP虚拟机开发环境”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
链接:https://pan.baidu.com/s/1fJ-8CUJXdKUrwJQQIkta0A 提取码:vjdr
链接:https://pan.baidu.com/s/1xLrLLbfVpnC97Zhw4rjJ1Q 提取码:7m7z
链接:https://pan.baidu.com/s/1VlEbl5VbI5wbjyI6YyCVyQ 提取码:zy8c 解压lt-homestead-3-0-0-2017082400.zip,并进入目录(不能有中文),执行 vagrant box add metadata.json 注意事项 vagrant box list 列出全部盒子 vagrant global-status --prune 查看活跃盒子 vagrant destroy (id:a1b2c3d4) # 销毁活跃盒子 vagrant box remove laravel/homestead --box-version 3.0.0 删除盒子
> cd D:/ > git clone https://github.com/laravel/homestead.git Homestead > cd Homestead > bash init.sh
--- ip: "192.168.10.10" memory: 2048 cpus: 2 provider: virtualbox #虚拟机平台,用virtualbox装的一定要确认这里是virtualbox authorize: ~/.ssh/id_rsa.pub #ssh的公钥 keys: - ~/.ssh/id_rsa #ssh的私钥,配置了ssh以后,登录虚拟机可以直接在终端输入homestead ssh进入 folders: #设置文件夹机映射关系 - map: E:/www #本地文件夹 to: /home/vagrant/code #虚拟机文件夹 sites: #设置域名和网站的映射关系 - map: laravel8.com #域名 to: /home/vagrant/code/laravel8/public php: "7.3" - map: tp6.com #域名 to: /home/vagrant/code/tp6/public php: "7.3" - map: devscibox.com #域名 to: /home/vagrant/code/Scibox/public php: "7.3" databases: - laravel8 - tp6 - scibox_nankai_online - scibox_bit_online features: - mysql: true - mariadb: false - postgresql: false - ohmyzsh: false - webdriver: false #services: # - enabled: # - "postgresql@12-main" # - disabled: # - "postgresql@11-main" # ports: # - send: 50000 # to: 5000 # - send: 7777 # to: 777 # protocol: udp
检查 ls -al ~/.ssh,存在就不需要生成 生成 ssh-keygen -t rsa -C "your_email@example.com"
192.168.10.10 laravel8.com (注意ip)
vagrant up(如果启动不了,就在virtualBox软件里手动删除)
命令行 | 说明 |
---|---|
vagrant init | 初始化 vagrant |
vagrant up | 启动 vagrant |
vagrant halt | 关闭 vagrant |
vagrant ssh | 通过 SSH 登录 vagrant(需要先启动 vagrant) |
vagrant provision 或者vagrant reload --provision | 重新应用更改 vagrant 配置 |
vagrant destroy | 删除 vagrant |
update-alternatives --display php 查看所有 php 版本和当前版本 sudo update-alternatives --config php 执行后,会列出当前 php 所有版本和编号,输入编号,切换到执行的版本
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/(阿里) composer config -g repo.packagist composer https://packagist.org(官方)
进入/etc/nginx/sites-available 设置同域名文件,可写sudo chmod -R 777 ./devscibox.com vim修改转发为 location / { if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=/$1 last; break; } } 重启nginx sudo service nginx restart
select @@GLOBAL.sql_mode 查询sql_mode SET GLOBAL sql_mode = 'NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'; 在navicat里设置 sudo service mysql restart 重启mysql
$ cd ~/code (此目录等效于本地www目录) $ composer create-project laravel/laravel dirname --prefer-dist "8.*.*"
ssh 用户名:vagrant 密码:vagrant mysql软件连接 host: 127.0.0.1 user: homestead pass: secret port: 33060 mysql网站连接 host: 127.0.0.1 user: homestead pass: secret port: 3306
http://laravel8.com/
######安装netstat
sudo apt-get install net-tools
xon
######查询网关ip
sudo netstat -rn | grep "^0.0.0.0 " | cut -d " " -f10
php --ini | grep 'xdebug' sudo chmod -R 777 /etc/php/7.3/cli/conf.d/20-xdebug.ini (开启写入权限)
zend_extension=xdebug.so xdebug.mode=debug xdebug.discover_client_host=1 xdebug.client_port = 9001 xdebug.max_nesting_level = 512 xdebug.scream=0 xdebug.cli_color=1 xdebug.show_local_vars=1 xdebug.remote_enable=1 xdebug.remote_autostart=1 xdebug.remote_host=10.0.2.2 xdebug.remote_host=9001 xdebug.start_with_request = yes
sudo service php7.3-fpm restart sudo nginx -s reload
{ "version": "0.2.0", "configurations": [ { "name": "Listen for XDebug", "type": "php", "request": "launch", "port": 9001 }, { "name": "Launch currently open script", "type": "php", "request": "launch", "program": "${file}", "cwd": "${fileDirname}", "port": 9001 }, { "name": "Listen for XDebug on Homestead", "type": "php", "request": "launch", "pathMappings": { "/home/vagrant/code/Scibox": "E:\\www\\Scibox" }, "port": 9001 } ] }
sudo chmod -R 777 /etc/apt/sources.list sudo vim /etc/apt/sources.list
清华 https://mirror.tuna.tsinghua.edu.cn/help/ubuntu/
sudo apt-get update
查看可安装的包 apt-cache search mysql | grep mysql-server
“如何搭建PHP虚拟机开发环境”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。