Brew install php mamp

Install MAMP to mac silicon (with brew) – php 7.2/8 with imagick – 2023

Install MAMP to mac silicon with brew - php 7.2/8 imagick

Hello! This post will be helpful, how to create Mac – Apache – MySQL – PHP server for Apple Mac Silicon M1/M2 with ImageMagic extension for `PHP any version 5.6/7.0/7.1/7.2/7.4/8.0.

This solution is free and faster and suitable for everyone, without Rosetta.

In addition, I will provide a script to quickly create local sites. All this will help you conveniently develop your local sites.

1. Install apache2 with homebrew

Configuration apache2

Open /opt/homebrew/etc/httpd/httpd.conf

Now we have php 7.2 version.

Next, make sure that the following is written or edit for yourself:

If you notice, we use 8080 port, that is address your site is: http://yoursite.loc:8080. We use this port so that apache2 brew does not conflict with apache2 custom.

Читайте также:  Jquery ajax html with scripts

You can use standard files config, but I want to show another architecture to your sites. (read about it below in the next heading)

Command to restart/stop Apache2:

2. Your local sites architecture

Create MAMP folder to your home directory. My home directory is “/Users/sergey”. The MAMP folder presentation is:

addsite.sh content:

Install PHP with homebrew

First remove all php version and ImageMagick

Install pkg-config

Install php version wich you need. I will install 7.2. You can install any: 5.6/7.0/7.1/7.2/7.3/7.4/8.0/8.1/8.2. We will use the following library: shivammathur/php

Open /Users/YOUR_NAME/.zshrc file:

Just in case, make sure this file contains:

Apply changes in .zshrc

Edit php.ini

You can append follow lines to the end php.ini or edit line to line.

php.ini path is: /opt/homebrew/etc/php/7.2/php.ini. My config is:

Install ImageMagick

Now, if you use the following command:

To restart php and apache2 execute follow:

To view a list of running brew processes :

Install Mysql

With brew you can choose version. I need 5.7 version:

If you want to find where does mysql installed in system, use the following command:

to enter to mysql (if mysql already installed):

MySQL config

To know, where is you can place config mysql file, execute terminal command:

and you will find, if you scroll down a few screen:

So, you can create /opt/homebrew/etc/my.cnf and write into it:

Install PhpMyAdmin

After that you can see the following lines that have been added to /opt/homebrew/etc/httpd/httpd.conf:

PhpMyAdminConfig

We can change timeout in config file:

from $cfg[‘ExecTimeLimit’] = 300; to $cfg[‘ExecTimeLimit’] = 0;

It takes no limit time authorization.

Apache2 default

Most likely, you have already using Apache2. You can check it in your browser: http://localhost

Most likely you will see: It works.

httpd.conf located at: /private/etc/apache2/httpd.conf

index.html, with content “It works. ” located at: /Library/WebServer/Documents/index.html.en

Command for stop and start default apache:

References:

  • https://stackoverflow.com/questions/50060021/homebrew-install-new-formula-php72-imagick
  • https://stackoverflow.com/questions/70237219/how-to-install-php-7-2-on-macos-big-sur-using-homebrew
  • https://bazarow.ru/blog-note/9311/

Источник

How to Setup MAMP (MacOS, Apache, MySQL, PHP) Local Server on macOS 12 Monterey M1 Mac (2021)

mamp-macos12-monterey

Apple released its 2021 latest macOS 12 Monterey on October 25, 2021. It is the time of this year again that you might need to reconfigure your macOS if you are upgrading from macOS 11 Big Sur or older versions.

Or if you have a brand new Mac with macOS 12 Monterey, the below configuration steps should help you set up your local web server on the macOS platform.

On macOS 12 Monterey, Apache is built into the system. However, when you check the built-in Apache’s httpd.conf, you will notice a line says:

#PHP was deprecated in macOS 11 and removed from macOS 12

From macOS 12 Monterey, since there is no built-in PHP, if you want to set up a MAMP (macOS, Apache, MySQL, PHP) stack, I recommend using the Homebrew version of Apache as well as PHP.

Disable macOS Built-in Apache

Since we will not be using the macOS 12 built-in version of Apache, if your built-in Apache is running, issue the following command to stop the Apache service.

Homebrew Installation

The first thing you need to do is install Homebrew to your macOS 12 Monterey system (if you have not installed Homebrew yet).

Check if you have Homebrew install or knowing the installed Homebrew version

Open Terminal and type brew -v

If returns something like:

Homebrew 3.3.0 Homebrew/homebrew-core (git revision 359f9f16171; last commit 2021-10-25)

This means you have Homebrew already installed. If you don’t see the above, follow the below steps to install the Homebrew in your system.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Open Terminal and paste the above command.

Note: if you don’t have Command Line Tools for Xcode installed, the Homebrew installer will download and install the Command Line Tools for Xcode first then it will proceed to complete the installation of Homebrew to your system.

To learn more about Homebrew, check out How to use Homebrew on macOS 12 Monterey

Export the Homebrew Path

When you try to issue a brew command, you might get the below error.

zsh: command not found: brew

If you are getting the above error, you have to export the path by issuing the following commands.

Open the Terminal and type the below command and press Enter.

export PATH="/opt/homebrew/bin:$PATH"

then type the below command and press Enter.

echo 'export PATH="/opt/homebrew/bin:$PATH"' >> $HOME/.zshrc

Close the Terminal and re-open a new Terminal window.

Installing Apache via Homebrew

Once you have Homebrew installed and properly set the export, the next step is to install the Apache using Homebrew.

Configure the Homebrew version Apache (httpd.conf file)

Type cd /opt/homebrew/etc/httpd/

Type sudo cp httpd.conf httpd.conf.bak and press enter (this step is optional if you want to keep the copy of the original config file.)

Enable the Modules and Configuration

You need to enable (uncomment the line) and modify/update the configuration in httpd.conf file.

To enable the modules, first, you need to find the modules that you want to enable.

Use control + w to bring up the search function, and look for the below modules and make sure to uncomment them. (remove the # in front of each line.)

LoadModule authn_core_module lib/httpd/modules/mod_authn_core.so
LoadModule authz_host_module lib/httpd/modules/mod_authz_host.so
LoadModule userdir_module lib/httpd/modules/mod_userdir.so
LoadModule include_module lib/httpd/modules/mod_include.so
LoadModule rewrite_module lib/httpd/modules/mod_rewrite.so
Include /opt/homebrew/etc/httpd/extra/httpd-userdir.conf

Modify the DocumentRoot

Use control + w and search for DocumentRoot . Comment out (put # in front of each line of below.

DocumentRoot "/opt/homebrew/var/www" 
DocumentRoot "/Users/USERNAME/Sites/" 

Note: USERNAME needs to be replaced with your username (e.g. developer)

Then you need to modify the options as below:

Options Indexes FollowSymLinks Multiviews MultiviewsMatch Any

The final configuration of DocumentRoot should look like below:

#DocumentRoot "/opt/homebrew/var/www" # DocumentRoot "/Users/developer/Sites/" # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn't give it to you. # # The Options directive is both complicated and important. Please see # http://httpd.apache.org/docs/2.4/mod/core.html#options # for more information. # Options Indexes FollowSymLinks Multiviews MultiviewsMatch Any # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # AllowOverride FileInfo AuthConfig Limit # AllowOverride All # # Controls who can get stuff from this server. # Require all granted ed

Modify the Listening Port

By default, it will listen to port 8080 . If you want to listen to port 80 , modify the Listen 8080 to Listen 80 .

Use Control + w and search for Listen 8080 then replace with Listen 80

This is optional. You can keep using the default Listen 8080

Note: Your macOS Local Apache Server may be active on port 80. I would recommend to keep the HomeBrew version at port 8080.

Create Sites folder under your Username

Since we defined the DocumentRoot to be /Users/USERNAME/Sites. We need to create this “ Sites ” folder under the user “ developer “.

Open Finder and navigate to the user’s folder.

Create New Folder and name it “ Sites “

Install PHP via Homebrew

Wait for the installation to complete.

Modify the httpd.conf to enable the PHP on Apache

Type cd /opt/homebrew/etc/httpd/

LoadModule php_module /opt/homebrew/opt/php/lib/httpd/modules/libphp.so SetHandler application/x-httpd-php 

Use Control + w and search for DirectoryIndex , then add index.php

Create phpinfo.php file

phpinfo.php file will be used to check if the PHP is working or not.

Type sudo nano phpinfo.php

Once the nano application is opened, add the below line.

then press control + o to save then control + x to exit nano app.

Starting Apache server

Once the configuration of Apache and PHP are completed, let’s start up the Apache server.

Type brew services restart httpd

To check if the Apache service running or not, type brew services list

You should see something like:

httpd started developer /Users/developer/Library/LaunchAgents/homebrew.mxcl.httpd.plist

If you see the “started” status, that means the Apache server is up and running.

Go to web browser and type localhost and press enter.

You should see a screen like below:

If you click the phpinfo.php, and if your PHP is working properly, you should see the PHP info page.

Install MySQL Server

Select the ARM 64-bit DMG Archive and download the installer.

Once the installer is downloaded, double click and proceed as instructed.

Once the MySQL server is successfully installed, you should be able to see it in the System Preferences.

If you are looking for macOS 11 Big Sur version of how to setup the MAMP, please see Setting Up Your Local Web Server on macOS Big Sur 11.0.1 (2020)| MAMP Setup on mac | macOS, Apache, MySQL, PHP

Latest Posts

Feel free to share this post!

Источник

Оцените статью