Setting up PHP, MySQL, and Apache in Mac OSX Leopard. Posted 12 August 2008 by Mike Longmire & filed under Coding. One of the best features for web developers in Mac OSX Leopard is the inclusion of PHP and Apache.By default both are inactive and require you to get them ready for business. In this tutorial we will learn to install Apache, MySQL, PHP on macOS Catalina 10.15. About macOS Catalina. Apple released macOS Catalina 10.15 on 7th October 2019 and it includes Apache and PHP. So, all we have to do is enable them. Then install MySQL.
So finally I have decided to learn PHP and I use Mac for my personal usage, so the first step was to install Apache, PHP and MySql on my Mac OS X. My Mac OS is Mountain Lion (10.8), so for earlier versions you might need to make some changes in the steps provided below.
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.
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.
Seamlessly import, organise and share your photos, videos and docs to the My Passport for Mac drive to backup your online social life. And with SuperSpeed USB, you can quickly start backing up everything in your life and keep driving forward.Social Friendly.Included WD Discovery™ software 1 lets you connect to popular social media and cloud storage services like Facebook, Dropbox and Google Drive™. 2 WD Discovery can also manage your drive through WD Drive Utilities™.Ongoing Confidence.There's no telling what's ahead in your own journey. Simply drag and drop files to and from, or setup a backup routine with Apple’s Time Machine software to help protect the contents of your digital life: photos, videos, music and documents.Plays Nicely.The My Passport™ for Mac drive includes USB-C™ and USB-A cables, so you can save tomorrow's content with the Mac computers of both today and yesterday.Locked Down.The My Passport™ for Mac drive’s built-in 256-bit AES hardware encryption with password protection helps keep your digital life's contents secure. Just activate password protection and set your own personalized password using WD Discovery™.Easy Save.My Passport™ for Mac portable storage is ready right out of the box including all necessary cables. Wd passport 2tb 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.
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
Local Document Root -/Users/chatura/htdocs/wp-test
Mac Os Php
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
Install additonal PHP extensions
Setup PHP CLI binary
Best mac os terminal font. 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.
PREREQUISITES:
In order to follow this guide, you should have a Mac computer with the Catalina OS installed.
I was using for several years MAMP, Fywheel, as well as package managers like brew, and all work pretty well, but why not using the preinstalled Apache and PHP that is shipped in almost all macOS?
In this tutorial, I will show you how to setup/install Apache, PHP, and MySQL on macOS Catalina.
Open the Terminal app and switch to the root user so you can run the commands in this post without any permission issues:
Enable Apache on macOS
Check if works by accessing: http://localhost
Enable PHP for Apache
First, let’s make a backup of the default Apache configuration
Edit the Apache configuration
Uncomment the following line
Restart Apache:
You can verify PHP is enabled by creating a phpinfo() page in your DocumentRoot.
The default DocumentRoot for macOS Catalina is /Library/WebServer/Documents. In order to verify this, we run the command below to find out our Apache configuration.
Create the phpinfo() page in your DocumentRoot:
Verify PHP by accessing http://localhost/phpinfo.php
Customizing PHP settings (php.ini)
MacOS’ PHP uses a default php.ini file based on /private/etc/php.ini.default. To customize your PHP environment, if a php.ini file doesn’t already exist at /private/etc/php.ini, copy the default template to create a main php.ini file:
Make any changes you wish to php.ini and restart apache to reload all configuration files:
If you were to run phpinfo() in a PHP file from the web server, you should now see that the Loaded Configuration File property now has the value /etc/php.ini.
A very common tweak to the default PHP configuration is to allow larger file upload sizes. The post_max_size and upload_max_filesize properties are only a few megs by default. These limits can be raised as you see fit.
Many developers also tweak the max_execution_time, max_input_time, and memory_limit settings depending on their project.
Always remember to restart apache after making changes to your PHP configuration.
Install MySQL on macOS Catalina
Download and install the latest MySQL version for your macOS.
Apache Mysql Php Windows 10
Setup Open a new terminal and run the code below this will update the mysql path on your ~/.profile
Please run mysql_secure_installation to make your MySQL secured
Now, to access mysql console, we can run below short command:
Useful mysql commands
Word for apple mac. The best MacBook for day-to-day casual users, and beautifully portable. Lagging behind the 12-inch MacBook, the MacBook Air had been slightly neglected compared to Apple's other. The MacBook Air is a slim, lightweight laptop with a 13.3in screen. Apple updated the MacBook Air in March 2020 with better processors, more storage and improved RAM. Explore the world of Mac. Check out MacBook Pro, iMac Pro, MacBook Air, iMac, and more. Visit the Apple site to learn, buy, and get support. The 2019 16-inch MacBook Pro (9/10, WIRED Recommends) brought about a return to form for Apple. It's familiar in a good way and, more important, it ushered in a new era of reliable MacBooks. Apple discontinued its 12-inch laptop in July 2019. You may be able to buy one in Apple’s Refurbished and Clearance Store, but supplies won’t last long.
Connect PHP and MySQL
Create symlink to ensure PHP and MySQL can communicate each other.
Edited my Apache Configuration:
Uncommented the following lines
Virtual Hosts
Edit the Apache configuration file:
Add the below line after this included #Include /private/etc/apache2/extra/httpd-vhosts.conf
Create the apache2 vhosts directory.
Create the default virtual host configuration file.
Add the following configuration:
Mysql Php Apache For Mac Os 10.13
The default virtual host was created for when the Apache web server can’t find a virtual host, it will use this configuration. By prefixing this file with an underscore, Apache will include it first.
Now we can create our first virtual host. The example below contains the virtual host configuration for my test site.
Mysql Php Apache For Mac Osx
Create the virtual host configuration file:
Add the following configuration:
This VirtualHost configuration allows me to access my site from http://nuno-test.test for local development.
The final step is to restart Apache:
Test our apache configuration/strong>
Start, Stop, Restart and test Apache server config
I know it is a little bit daunting but I promise that we’ll never come back to this nasty lengthy configuration file again. Four simple commands are everything that we need to remember from now on. Start, stop, restart and configuration test.
Mapping our vhosts on macOS hosts file
Add your virtual host to the bottom of the file. It should match the value you used for the ServerName configuration.
Flush macOS DNS cache:
Permissions
You may receive 403 Forbidden when you visit your local site. This is likely a permissions issue. Simply put, the Apache user (_www) group (_www) needs to have access to read, and sometimes write, to your web directory.
Conclusion
By using the macOS preinstalled Apache and PHP we can avoid installing extra software on our macOS which sometimes could lead us to conflicts/errors/miss configuration on our Mac Operating system.