I mainly do web development on my 15 in Macbook Pro. Mac runs on base Unix foundation so mainly you could install almost all Linux/Unix software on Mac very easily.
Running PHP on the macOS / Mac OS X Apache Web Server. PHP 5 is installed in macOS / OS X by default, but the built-in Apache web server may not be configured to automatically run PHP. To enable PHP, the apache configuration file needs to be modified. This file is located in the following location.
Microsoft offers IIS (Internet Information Server), which is the second most popular Web server on the Internet, with approximately 27 percent of Web sites. Sun Microsystems offers a Web server, which serves less than 3 percent of the Internet. Other Web servers are available, but they have even smaller user bases. Installing MySQL. 4/12/2017 In this article, I am going to share my experience for how to install NGINX, PHP and MySQL on your Mac. This article is for someone interesting to set-up web development environment, especially for the first time. Reson I choose Nginx over Apache web server is its light-weight resource utilization and its ability to scale easily. MAMP – as the name suggests – is a particular PHP local server developed for MAC operating systems. Its acronym stands for MAC, Apache, MySQL and PHP. It gives MAC users a great local platform to test and host their applications on. 2) Install apache 2.0 The homebrew package installer can be used to install Apache 2.0 on MacOS. The installer installs the Apache HTTP server on the location /usr/local/Cellar/httpd. 3) Start apache Apache provides a service named as apachectl which needs to be started in order to start Apache. The command needs super user privileges to be executed hence we have to use sudo to get the.
Mac OS X comes by default with ApacheWeb Server and PHP. In this tutorial we will go over steps on how to enable those on Mac.
Let’s get started:
Enable Apache Web Server
Step-1
Open terminal App and run below command:
Step-2
Open browser and check with URL:
http://localhost
Enable PHP Module and verify Perl module
Step-1
Open
Terminal
App. Mac OS X comes by default with Perl library
. Just type below commands to check Perl and PHP Setup.Terminal Commands
2 4 6 8 10 12 14 16 18 | /usr/bin/perl bash-3.2# pwd total120 -rw-r--r--1root wheel13077Sep92014magic drwxr-xr-x14root wheel476Sep92014extra -rw-r--r--1root wheel20786Sep92014httpd.conf -rw-r--r--1root wheel20786Jun913:55httpd.conf.bak bash-3.2# vi httpd.conf |
Step-2
Open file
httpd.conf
file. You may use any Text Editor
also.Uncomment the following line (remove #):
LoadModule php5_module libexec/apache2/libphp5.so
Step-3
Restart Apache Web Server: Push for mac.
Step-4
- Find
DocumentRoot
fromhttpd.conf
file. In my case it’s/Users/crunchify/Documents/Blogs/MAMP
as I’m using MAMP on my Mac. - You may have diff folder something like
/Library/WebServer/Documents/
. - Create below file
crunchify-php-on-mac.php
under your DocumentRoot folder. - If you don’t see folder
Web Server
then just create it ?
Php Web Server For Macs
crunchify-php-on-mac.php
2 4 6 8 | <head> </head> <?phpecho'<p>Hello World - PHP Testcase on Mac OS X by Crunchify.com..</p><br>Have a fun. Enjoy.';?> </html> |
Step-5
Now visit this URL:
http://localhost/crunchify-php-on-mac.php
and you should see php file loaded successfully on browser.How to Kill Apache httpd process on Mac?
Just incase if you need to kill apache httpd process on Mac then you could use below commands.
2 | sudo launchctl unload/System/Library/LaunchDaemons/org.apache.httpd.plist |
Enjoy and Happy coding…
![Mac Mac](/uploads/1/1/9/7/119747898/825390458.jpg)
Join the Discussion
If you liked this article, then please share it on social media or leave us your comments. Limited time 3 months free WPEngine hosting.
Other Popular Articles..
I recently purchased brand new MacBook Pro and I had to install NGINX, PHP and MySQL in my MacBook Pro. In this article, I am going to share my experience for how to install NGINX, PHP and MySQL on your Mac. This article is for someone interesting to set-up web development environment, especially for the first time.
Reson I choose Nginx over Apache web server is its light-weight resource utilization and its ability to scale easily. Also, Niginx has grown its popularity during last few years. Furthermore, Nginx is often selected by administrators for its resource efficiency and responsiveness under the heavy load.
My MacBook Pro installed Mac OS High Sierra and it was shipped with pre-installed PHP package. So, depending on your web development environment setup, you may need to upgrade default PHP version to the latest version.
Normally, Mac OS X doesn’t ship with its own copy of MySQL. So, you will have to install MySQL on your local machine.
Also, remember this article only explain to install these required packages on your local machine. Alternatively, you can set up similar development environment by using Docker or Vagrant. I will write another post in this regarding.
Now let’s have a look how to install NGINX, PHP and MySQL on Mac OS local environment.
Install NGINX
I prefer to use Homebrew package manager to install required additional packages on my Mac OS X.
If you haven’t install Homebrew on your Mac, you just need to copy paste following command on your terminal and Homebrew will install on your Mac automatically. Remember you need an Internet connection to download these packages.
Once you installed Homebrew, you can install NGINX by using the following command.
Nginx will set following document root by default. But you can change to any path using nginx.conf file.
NGINX default document root
/usr/local/var/www
Configure NGINX virtual hosts
I have included my pre-configured virtual hosts as a zip file.
Php Development Server
So you can download my pre-configured NGINX virtual host files here.
Once you download the zip file, unzip the contents and then you just need to copy into the following path. Furthermore, my NGINX virtual hosts specially configured for developing Magento 1, Magento 2 and WordPress projects in my local.
Step 1 – Rename existing “nginx” folder /usr/local/etc/
3d maya for mac. Step 2 – Copy downloaded “nginx” folder in to /usr/local/etc/
Step 3 – Change your system username
All the pre-configured NGINX virtual hosts are located under the following path.
/usr/local/etc/nginx/servers
You will find four configuration files under the above path.
- 00_upstream.conf – For Fast CGI upstream
- 10_localhost.com.conf – For Magento 1 hosts
- 20_localhost.com.conf – For Magento 2 hosts
- magestyle.conf – For WordPress and general hosts
Also, you will notice, each virtual host’s document root is defined under the above configuration files.
Update your host file
Also, you will need to update your host file for the custom virtual host names. So you can have a look my host file as an example.
![Php local server Php local server](https://phpvideoacademy.com/img/2018/11/Building-a-web-server-with-Linux-Nginx-MySQL-PHP-7.0-LEMP-stack-in-Ubuntu-16.04.jpg)
NGINX server state management
Start NGINX Server
Reload NGINX Server
Stop NGINX Server
Test and verify NGINX services
My local configuration examples:
For Magento 1 projects
Local Document Root – /Users/chatura/htdocs/m1-local
Host name – http://m1-local.localhost.com/
Php Web Server For Mac Os
Configuration file path – /usr/local/etc/nginx/servers/10_localhost.com.conf
For Magento2 projects
Local Document Root – /Users/chatura/htdocs/m2-local/web
Host name – http://m2-local.m2.localhost.com/
Configuration file path – /usr/local/etc/nginx/servers/20_localhost.com.conf
For WordPress and other projects
Local Document Root -/Users/chatura/htdocs/wp-test
Host name – http://wp-test.localhost.com/
Local Document Root – /usr/local/etc/nginx/servers/magestyle.conf
Install PHP
If you follow the following steps, you can replace default PHP with Homebrew PHP version. Also, you can easily upgrade or switch your PHP version according your project requirement.
Especially I am going use my development setup for Magento 2 development. So I followed the Magento technology stack documentation before decide which PHP version I need to install. So I am going to install PHP 7.1 version in my local environment as per the Magento 2 latest technology stack.
Use following “brew tap” command to allow Homebrew to tap into Homebrew PHP to formulae. Once you’ve done this, you’ve expanded your options of installable PHP versions. So these additional Git repos will be saved inside the (usr/local/Library/Taps) directory,
To check list of available configuration options
Install PHP without Apache and with PHP FPM
Local Php Web Server
Install additonal PHP extensions
Setup PHP CLI binary
In addition, if you want to use the PHP command line tools, you need to update the $PATH environment variable of your shell profile.
If you use the default Bash shell:
If you use ZSH:
If you are not sure which one you use, run following code in your terminal. I am using ZSH and it returns “/bin/zsh”
Configure PHP using PHP-FPM
PHP-FPM is a modern way of running PHP with a process manager and the FastCGI protocol. Also, this enables high performance as well as easy switching between various versions of PHP.
Note: Also you can install many PHP version with Homebrew package manager. You just need to link required PHP version and unlink other PHP versions.
Check Installed PHP version and php.ini file
PHP service management
Install MySQL
Let’s install MySQL server.
Also, you can use the following command to MySQL server gets automatically started and stopped when the Mac is shutdown/powered on.
So, you can start MySQL start service manually using the following command for now.
MySQL service management
Test MySQL connection
I hope this article will help you to install Nginx, PHP, MySQL on your Mac OS. Let me know in case you’re stuck at some point or have general feedback. Please feel free to comment below.