preface

First of all, make sure you have MAMP installed on your MAC. I don’t want to go into the details of how to install MAMP here. There are a lot of tutorials on how to set up a Laravel virtual machine using MAMP. I hope I can help you and record it yourself.

1. Configure the Apache vm configuration in MAMP

Open your apache. Conf configuration using vscode, as shown in the following figure:/Applications/MAMP/conf/apache/httpd.conf) can be typed on the command linecode /Applications/MAMP/conf/apache/httpd.conf. Or drag it directly into VScode:find<Directory />, modify as follows:Code block posted, easy to copy and paste:

<Directory />
    Options Indexes FollowSymLinks
    AllowOverride All
</Directory>
Copy the code

find#Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.confThen put the#Remove:


Then enter it again at the terminalcode /Applications/MAMP/conf/apache/extra/httpd-vhosts.confComment on the original code:


Then open and enter the configuration of the VIRTUAL machine:The code is posted for easy replication:

<VirtualHost *:80>
  The email address of the site administrator, which is displayed when the site generates an error of 500 (internal server error)
  ServerAdmin 136072944@qq.com
  # Site to bind to the domain name
  ServerName justinlaravel.com
  ServerAlias localhost
  # The root directory of the site
  DocumentRoot "/Applications/laraveldemo/public"// This is your Laravel project public as the site root Directory DirectoryIndex index.php // default start <Directory"/Applications/laraveldemo/public">
    Options +Indexes +Includes +FollowSymLinks +MultiViews
    AllowOverride All
    allow from All
  </Directory>
</VirtualHost>
Copy the code

The Apache configuration is complete.

2. Configure hosts

Enter at the terminalcode /etc/hosts Map your configuration domain name.

Php.ini configuration:

Open the PHP configuration file php.ini. If you want to know which version of PHP you are using, you can see it as follows:You can see that we are using version 7.4.12, and then we open the configuration directory for this version php.ini/ Applications/MAMP/bin/PHP/php7.4.12 / conf/PHP iniFind:

#extension=php_openssl.dll
#extension=php_pdo_mysql.dll
#extension=php_mbstring.dll
#extension=php_fileinfo.dll
#extension=php_curl. DLL
Copy the code

If you don’t find any of these, don’t panic. We can just type these lines of code, as follows:

extension=php_openssl.dll extension=php_pdo_mysql.dll extension=php_mbstring.dll extension=php_fileinfo.dll Extension =php_curl. DLL (for sending requests)Copy the code

Remember to save all files after operation. After the configuration, restart MAMP.

Fourth, hit the pit

When the page http://justinlaravel.com/, may be not found or the circumstance of 403, when the PHP path problem, make sure that your terminal PHP version needs and your chosen MAMP version is consistent, because you change the configuration of the is the version of the, It is possible that other versions have not changed, so these situations will occur. On the terminal, enter php-v to view the version:

You can see that we have a very different version here, and this is where you have to configure the environment variable, which I’m using ZSH, at the terminalcode .bash_profile, and enter the following code:

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

We add this version to the environment variable, save it, and then enter the command in the terminal:source .bash_profile, and then inputphp -v:Now that we’re consistent, let’s restart MAMP. Then witness the miracle:

Laravel is already running, and running in virtual machine mode. Next, I will test the routing situation as follows. Enter the following code under routes web.php:

Route::get('/home1/{id}'.function ($id) {
    return The entered id is:.$id;
});
Copy the code

Witness effect:There is no problem. At this point our MAC laravel virtual machine boot mode has been set up.

On the way to learning PHP, if you find this article helpful to you, then please pay attention to like comment 3 times, thank you, your must be another support of my blog.