Mysql Php Apache For Mac Os



  1. Windows Apache Php Mysql
  2. Apache Mysql Php Windows 10
  3. Mac Os Php

macOS Update: While these instructions still work, there are new posts for recent versions of macOS, the latest being Install Apache, PHP, and MySQL on macOS Mojave.

PHP Update: Mac OS X El Capitan comes pre-installed with PHP version 5.5 which has reached its end of life. After you complete this post, you should upgrade PHP on Mac OS X.

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. 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.

Note: This post is for new installations. If you have installed Apache, PHP, and MySQL for Mac OS X Yosemite, read my post on Updating Apache, PHP, and MySQL for Mac OS X El Capitan.

Mac OS X runs atop UNIX. So most UNIX software installs easily on Mac OS X. Furthermore, Apache and PHP come packaged with Mac OS X. To create a local web server, all you need to do is configure Apache and install MySQL.

I am aware of the web server software available for Mac OS X, notably MAMP. These get you started quickly. But they forego the learning experience and, as most developers report, can become difficult to manage.

Running Commands

Mysql php apache for mac os 10.13

First, 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 Mac OS X

Verify It works! by accessing http://localhost

Enable PHP for Apache

First, make a backup of the default Apache configuration. This is good practice and serves as a comparison against future versions of Mac OS X.

Now edit the Apache configuration. Feel free to use TextEdit if you are not familiar with vi.

Uncomment the following line (remove #):

Restart Apache:

You can verify PHP is enabled by creating a phpinfo() page in your DocumentRoot.

The default DocumentRoot for Mac OS X El Capitan is /Library/WebServer/Documents. You can verify this from your Apache configuration.

Now create the phpinfo() page in your DocumentRoot:

Verify PHP by accessing http://localhost/phpinfo.php

Install MySQL on Mac OS X El Capitan

Download and install the latest MySQL generally available release DMG for Mac OS X.

The README suggests creating aliases for mysql and mysqladmin. However there are other commands that are helpful such as mysqldump. Instead, you can update your path to include /usr/local/mysql/bin.

Note: You will need to open a new Terminal window or run the command above for your path to update.

Finally, you should run mysql_secure_installation. While this isn't necessary, it's good practice to secure your database.

Connect PHP and MySQL

You need to ensure PHP and MySQL can communicate with one another. There are several options to do so. I do the following:

Additional Configuration (optional)

The default configuration for Apache 2.4 on Mac OS X seemed pretty lean. For example, common modules like mod_rewrite were disabled. You may consider enabling this now to avoid forgetting they are disabled in the future.

I edited my Apache Configuration:

I uncommented the following lines (remove #):

If you develop multiple projects and would like each to have a unique url, you can configure Apache VirtualHosts for Mac OS X.

If you would like to install PHPMyAdmin, return to my original post on installing Apache, PHP, and MySQL on Mac OS X.

Find this interesting? Let's continue the conversation on Twitter.

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

Abbyy finereader 11 for mac.
Uncomment the following line

Restart Apache:


You can verify PHP is enabled by creating a phpinfo() page in your DocumentRoot.

Windows Apache Php Mysql

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.


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

Recommended setup:
Strong Password? Yes
Change the root password? Yes
Remove anonymous users? yes
Disallow root login remotely? Yes
Remove test database? Yes
Reload privileges tables now? Yes

We can set a command shortcut for mysql:

Now, to access mysql console, we can run below short command:


Useful mysql commands

Connect PHP and MySQL

Create symlink to ensure PHP and MySQL can communicate each other.

Apache Mysql Php Windows 10

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.

Mac Os Php


Add the following configuration:


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.

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.