Mac MAMP builds Laravel virtual machine environment

Preface

First of all, make sure that MAMP has been installed on your mac. I won’t go into details about installing MAMP here. There is a large tutorial on the Internet, and I will talk about the pits I have encountered using the MAMP environment to build the laravel virtual machine startup method. Many, I finally succeeded in the future, I share my configuration experience, I hope to help you record it by yourself.

One, configure the apache virtual machine configuration in MAMP

Open your apache.conf configuration, you can use vscode open, as shown:
(depending on which position you put MAMP on, I was placed under Applications, catalog on the following: /Applications/MAMP/conf/apache/httpd.conf)
can be entered on the command line code /Applications/MAMP/conf/apache/httpd.conf. Or drag it directly into vscode:
Insert picture description here
find it <Directory />, modify it as follows:
Insert picture description here
paste the code block for easy copying and pasting:

<Directory />
    Options Indexes FollowSymLinks
    AllowOverride All
</Directory>

Find #Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
and #remove:
Insert picture description here


Then type in the terminal to code /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
comment the original code:
Insert picture description here


Then open the configuration of the input virtual machine: the
Insert picture description here
code is posted for easy copying:

<VirtualHost *:80>
  #站点管理员的邮箱,当站点产生500错误(服务器内部错误)的时候会显示在页面上
  ServerAdmin 136072944@qq.com
  #站点需要绑定的域名
  ServerName justinlaravel.com
  ServerAlias localhost
  #站点的根目录
  DocumentRoot "/Applications/laraveldemo/public" // 这是你laravel的项目public作为站点根目录
  DirectoryIndex index.php // 默认启动
  <Directory "/Applications/laraveldemo/public">
    Options +Indexes +Includes +FollowSymLinks +MultiViews
    AllowOverride All
    allow from All
  </Directory>
</VirtualHost>

The apache configuration is now complete.

Two, configure hosts

Type in the terminal to code /etc/hosts
Insert picture description here
map your configuration domain name.

Three, php.ini configuration:

Open the php configuration file php.ini. Here you need to know which version of php you are using, you can see it in this way, we start MAMP, as shown in the figure:
Insert picture description here
we can see that we are using version 7.4.12, and then we open the configuration of this version of php.ini, the directory /Applications/MAMP/bin/php/php7.4.12/conf/php.ini:
turn up:

#extension=php_openssl.dll
#extension=php_pdo_mysql.dll
#extension=php_mbstring.dll
#extension=php_fileinfo.dll (验证代码依赖需要该扩展)
#extension=php_curl.dll(主要用于请求的发送)

#Delete the previous ones . Don't panic if you don't find these ones. We can just enter these lines of code directly, as follows:

extension=php_openssl.dll
extension=php_pdo_mysql.dll
extension=php_mbstring.dll
extension=php_fileinfo.dll (验证代码依赖需要该扩展)
extension=php_curl.dll(主要用于请求的发送)

Remember to save all files after operation.
Remember to restart MAMP after configuration.

Four, step on the pit

When the page is entered http://justinlaravel.com/, there may be a not found403 or 403. At this time, make sure that your terminal php path is wrong. The php version needs to be consistent with the version in the MAMP you selected, because the configuration you changed is that version , It is possible that other versions have not changed, so these situations will occur. Type in the terminal to php -vview the version:

Insert picture description here
You can see the obviously different version on our side. At this time, you have to configure the environment variables. I use zsh. Enter it in the terminal code .bash_profile. After opening it, enter the following code:

#php
export PATH="/Applications/MAMP/bin/php/php7.4.12/bin:$PATH"
#php end

We add this version to the environment variable, and then save it, and then enter the command in the terminal:, source .bash_profileand then enter php -v:
Insert picture description here
this time is the same, we restart MAMP.
Then witness the miracle:
Insert picture description here

Laravel is already running, and it runs through a virtual machine. Then I tested routing follows the routescase web.phpenter the following code:

Route::get('/home1/{id}', function ($id) {
    
    
    return '输入的id是:'.$id;
});

Witness the effect: there
Insert picture description here
is no problem. So far, the startup method of our mac's laravel virtual machine has also been completed.

On the way of learning php, if you think this article is helpful to you, then please pay attention to like and comment Sanlian, thank you, you must be another support for my blog.

Guess you like

Origin blog.csdn.net/weixin_44103733/article/details/113749546