Apache Mysql And Php For Mac
2021年3月3日Download here: http://gg.gg/oirl6
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.
I have installed Apache, PHP, and MySQL on Mac OS X since Leopard. Each time doing so by hand. Each version of Mac OS X having some minor difference. This post serves as much for my own record as to outline how to install Apache, MySQL, and PHP for a local development environment on Mac OS X Mountain Lion Mavericks.
Here’s a video showing up to set up a Docker-based tool called DDEV on Mac: “How to set up a Docker-based PHP local development environment for macOS” It’s fast and straightforward. Disclaimer: I work for DDEV, and one of the things I do is interv. Configuring PHP, Apache, MySQL, and Xdebug for PHP development in MAC OS X. This tutorial shows you how to set up PHP on the MAMP (Macintosh, Apache, MySQL, PHP) package, which includes the Apache web server, the MySQL database server, and the PHP engine. MAMP is intended as a PHP development environment for the Mac, which can work seamlessly with the NetBeans IDE.
I am aware of the several packages available, notably MAMP. These packages help get you started quickly. But they forego the learning experience and, as most developers report, eventually break. Personally, the choice to do it myself has proven invaluable.
It is important to remember Mac OS X runs atop UNIX. So all of these technologies install easily on Mac OS X. Furthermore, Apache and PHP are included by default. In the end, you only install MySQL then simply turn everything on.
First, open Terminal and switch to root to avoid permission issues while running these commands.Enable Apache on Mac OS X
Note: Prior to Mountain Lion this was an option for Web Sharing in System Prefrences → Sharing.
Verify It works! by accessing http://localhostEnable PHP for Apache
OS X Mavericks Update: You will need to rerun the steps in this section after upgrading an existing install to Mac OS X Mavericks.
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:Install MySQL
*Download the MySQL DMG for Mac OS X
*Install MySQL
*Install Preference Pane
*Open System Preferences → MySQL
*Ensure the MySQL Server is running
*Optionally, you can enable MySQL to start automatically. I do.
The README also suggests creating aliases for mysql and mysqladmin. However there are other commands that are helpful such as mysqldump. Instead, I updated my 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.
I also run mysql_secure_installation. While this isn’t necessary, it’s good practice.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:Creating VirtualHosts
You could stop here. PHP, MySQL, and Apache are all running. However, all of your sites would have URLs like http://localhost/somesite/ pointing to /Library/WebServer/Documents/somesite. Not ideal for a local development environment.
OS X Mavericks Update: You will need to rerun the steps below to uncomment the vhostInclude after upgrading an existing install to Mac OS X Mavericks.
To run sites individually you need to enable VirtualHosts. To do so, we’ll edit the Apache Configuration again.
Uncomment the following line:
Now Apache will load httpd-vhosts.conf. Let’s edit this file.
Here is an example of VirtualHosts I’ve created.
The first VirtualHost points to /Library/WebServer/Documents. The first VirtualHost is important as it behaves like the default Apache configuration and used when no others match.
The second VirtualHost points to my dev workspace and I can access it directly from http://jason.local. For ease of development, I also configured some custom logs.
Note: I use the extension local. This avoids conflicts with any real extensions and serves as a reminder I’m in my local environment.
Restart Apache:
In order to access http://jason.local, you need to edit your hosts file.
Add the following line to the bottom:
I run the following to clear the local DNS cache:
Now you can access http://jason.local.
Note: You will need to create a new VirtualHost and edit your hosts file each time you make a new local site.A note about permissions
You may receive 403 Forbidden when you visit your local site. This is likely a permissions issue. Simply put, the Apache user (_www) needs to have access to read, and sometimes write, your web directory.
If you are not familiar with permissions, read more. For now though, the easiest thing to do is ensure your web directory has permissions of 755. You can change permissions with the command:
In my case, all my files were under my local ~/Documents directory. Which by default is only readable by me. So I had to change permissions for my web directory all the way up to ~/Documents to resolve the 403 Forbidden issue.
Note: There are many ways to solve permission issues. I have provided this as the easiest solution, not the best.Install PHPMyAdmin
Unless you want to administer MySQL from the command line, I recommend installing PHPMyAdmin. I won’t go into the details. Read the installation guide for more information. I install utility applications in the default directory. That way I can access them under, in this case, http://localhost/phpmyadmin.
In addition to these primary G Suite apps, Google offers apps like Forms and Classroom that can cater to unique needs like those of teachers. While businesses may need to pay Google a modest sum for enterprise-level support, Google’s productivity suite is a great free choice for any personal endeavor. Popular user-friendly apps like Google Docs, Slides, Sheets, and Drawings are all available for free.All of these apps use Google’s cloud storage service, Google Drive. A huge number of third-party tools like Zoho, LucidChart, Slack, and more provide native integration with Google’s many apps.Having your productivity suite based entirely on the cloud offers additional security, as it’s more difficult to lose track of your files.Closing
A local development environment is a mandatory part of the Software Development Process. Given the ease at which you can install Apache, PHP, and MySQL on Mac OS X there really is no excuse.
Find this interesting? Let’s continue the conversation on Twitter.
Mac OS X serves as an excellent development environment, even if you are not actually developing Mac OS or iOS applications. It is the darling of many a LAMP (Linux, Apache, MySQL and PHP) developer, who enjoys a slick desktop operating system with good UNIX-like underpinnings but who don’t necessarily want to put up with all the various limitations and complications that running a Linux desktop brings, consistent improvements in this regard over recent years notwithstanding.
The only trouble with this is that if you want to develop LAMP applications and work on a Mac then traditionally you’ve needed a two-box setup; a Mac on your desk and Linux on a development server. For many this isn’t an issue, and indeed when you’ve got a team of developers, optimal, but what if you wanted a self-contained development environment that was restricted to just one box? What if you wanted that box to be your laptop so you could take it anywhere?Solutions
“Virtual machine!”, I hear you cry. Yes, this is a possible solution, and for many works well. Good virtualisation software is free these days, but using a local VM is cumbersome. Not only does it consume a large slice of your RAM but it also puts a lot of strain on the CPU, meaning that if you are running off your battery your battery life will be decreased. It’s also cumbersome; you have to start up the VM when you need it and there can be complications with the networking, for example, if you have connected to a public wireless network it’s possible that your VM might not be extended the same resource.
There is a software package for Mac OS called MAMP (the M for Mac OS replacing the L for Linux). This is a point-and-click installer which bundles Apache, Linux and PHP for installation on Mac OS. I don’t like this solution, for a number of reasons, including:
*Limited functionality unless you “go pro” (at quite considerable cost). Any self-respecting developer will require multiple virtual hosts as a minimum and won’t need or want a clicky-button interface to get what they want.
*You are entirely at the mercy of the distributors of MAMP with regards to component software versions that are made available to you and when.Alternative solution
There’s an alternative to this. You don’t have to fork out £39 for a package of what it otherwise freely and widely available software. With the help of my friend and colleague Ben Nimmo I present the following assembled and tested instructions for turning your Mac into a native MAMP server without using the packages download.MySQL
*Download and install the latest .dmg and install both the *.pkgs within it (don’t use the TAR/GZ archives). You may wish to install the Workbench too, it’s really good these days.
*Find where the mysql.sock file is expected to be in /etc/php.ini (should be /var/mysql/mysql.sock)
*Create the folder and link the socket file to the expected location.
*Add MySQL to command line by editing /Users/username/.bash_profile and adding this line and then either restarting terminal or source-ing the file:PHP
PHP comes with Mac OS, so it’s not necessary to download and install it, however, there are a couple of necessary steps to configure it:
*Copy the default php.ini file:
*Edit /etc/php.ini and uncomment this line to enable xdebug (not essential, but recommended):Apache
Apache too comes with Mac OS, so again, no need to download and install it. Its configuration, however, is a little more complex, but nothing scary. The described configuration will provide a special Apache “sandbox” environment for your projects. It uses the existing “Sites” directory in your Mac OS home directory.
*Create a subdirectory in this directory for each of your projects, ensuring that the directory name does not contain any characters that would be illegal in a URL. Within each of these subdirectories create another subdirectory called “web”; this will be become the web root of each project. The extra subdirectory is in case you wish to use a framework in your projects which may keep some of its files outside of the web server root (Symfony is a good example of this).
*Create a subdirectory called “logs” in your “Sites” directory; Apache will maintain two log files, access and error, for all the sandbox sites.
*Enable PHP5 with Apache by editing /etc/apache2/httpd.conf and uncomment the following line:
*Change the user and group to your username and “staff” respectively, also in /etc/apache2/httpd.conf:
*While still in /etc/apache2/httpd.conf, find the following configuration and change “Deny from all” to “Allow from all”:
*Create and edit /etc/apache/users/user.conf with the following, changing “sbf” to the username:
*Restart Apache:
Then, for each of your sites, add an entry in /etc/hosts for with the format “name.dev.local” pointing to 127.0.0.1, where name corresponds to a subdirectory in your “Sites” directory. Don’t forget that the public subdirectory of each site is assumed to be “web”, so make a symlink to this if the framework you use has a different convention.
You should then be able to access each of your sites from URLs using the convention http://name.dev.local/ – where “name” again is a subdirectory within your “Sites” directory.Apache Php Mysql Package
I’ve tested this setup procedure and It Works For Me [tm]. If, however, it doesn’t quite work for you as described, please let me know where you’re going wrong and how, if you were able, to resolve it, and I will update these instructions accordingly.
Download here: http://gg.gg/oirl6
https://diarynote-jp.indered.space
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.
I have installed Apache, PHP, and MySQL on Mac OS X since Leopard. Each time doing so by hand. Each version of Mac OS X having some minor difference. This post serves as much for my own record as to outline how to install Apache, MySQL, and PHP for a local development environment on Mac OS X Mountain Lion Mavericks.
Here’s a video showing up to set up a Docker-based tool called DDEV on Mac: “How to set up a Docker-based PHP local development environment for macOS” It’s fast and straightforward. Disclaimer: I work for DDEV, and one of the things I do is interv. Configuring PHP, Apache, MySQL, and Xdebug for PHP development in MAC OS X. This tutorial shows you how to set up PHP on the MAMP (Macintosh, Apache, MySQL, PHP) package, which includes the Apache web server, the MySQL database server, and the PHP engine. MAMP is intended as a PHP development environment for the Mac, which can work seamlessly with the NetBeans IDE.
I am aware of the several packages available, notably MAMP. These packages help get you started quickly. But they forego the learning experience and, as most developers report, eventually break. Personally, the choice to do it myself has proven invaluable.
It is important to remember Mac OS X runs atop UNIX. So all of these technologies install easily on Mac OS X. Furthermore, Apache and PHP are included by default. In the end, you only install MySQL then simply turn everything on.
First, open Terminal and switch to root to avoid permission issues while running these commands.Enable Apache on Mac OS X
Note: Prior to Mountain Lion this was an option for Web Sharing in System Prefrences → Sharing.
Verify It works! by accessing http://localhostEnable PHP for Apache
OS X Mavericks Update: You will need to rerun the steps in this section after upgrading an existing install to Mac OS X Mavericks.
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:Install MySQL
*Download the MySQL DMG for Mac OS X
*Install MySQL
*Install Preference Pane
*Open System Preferences → MySQL
*Ensure the MySQL Server is running
*Optionally, you can enable MySQL to start automatically. I do.
The README also suggests creating aliases for mysql and mysqladmin. However there are other commands that are helpful such as mysqldump. Instead, I updated my 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.
I also run mysql_secure_installation. While this isn’t necessary, it’s good practice.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:Creating VirtualHosts
You could stop here. PHP, MySQL, and Apache are all running. However, all of your sites would have URLs like http://localhost/somesite/ pointing to /Library/WebServer/Documents/somesite. Not ideal for a local development environment.
OS X Mavericks Update: You will need to rerun the steps below to uncomment the vhostInclude after upgrading an existing install to Mac OS X Mavericks.
To run sites individually you need to enable VirtualHosts. To do so, we’ll edit the Apache Configuration again.
Uncomment the following line:
Now Apache will load httpd-vhosts.conf. Let’s edit this file.
Here is an example of VirtualHosts I’ve created.
The first VirtualHost points to /Library/WebServer/Documents. The first VirtualHost is important as it behaves like the default Apache configuration and used when no others match.
The second VirtualHost points to my dev workspace and I can access it directly from http://jason.local. For ease of development, I also configured some custom logs.
Note: I use the extension local. This avoids conflicts with any real extensions and serves as a reminder I’m in my local environment.
Restart Apache:
In order to access http://jason.local, you need to edit your hosts file.
Add the following line to the bottom:
I run the following to clear the local DNS cache:
Now you can access http://jason.local.
Note: You will need to create a new VirtualHost and edit your hosts file each time you make a new local site.A note about permissions
You may receive 403 Forbidden when you visit your local site. This is likely a permissions issue. Simply put, the Apache user (_www) needs to have access to read, and sometimes write, your web directory.
If you are not familiar with permissions, read more. For now though, the easiest thing to do is ensure your web directory has permissions of 755. You can change permissions with the command:
In my case, all my files were under my local ~/Documents directory. Which by default is only readable by me. So I had to change permissions for my web directory all the way up to ~/Documents to resolve the 403 Forbidden issue.
Note: There are many ways to solve permission issues. I have provided this as the easiest solution, not the best.Install PHPMyAdmin
Unless you want to administer MySQL from the command line, I recommend installing PHPMyAdmin. I won’t go into the details. Read the installation guide for more information. I install utility applications in the default directory. That way I can access them under, in this case, http://localhost/phpmyadmin.
In addition to these primary G Suite apps, Google offers apps like Forms and Classroom that can cater to unique needs like those of teachers. While businesses may need to pay Google a modest sum for enterprise-level support, Google’s productivity suite is a great free choice for any personal endeavor. Popular user-friendly apps like Google Docs, Slides, Sheets, and Drawings are all available for free.All of these apps use Google’s cloud storage service, Google Drive. A huge number of third-party tools like Zoho, LucidChart, Slack, and more provide native integration with Google’s many apps.Having your productivity suite based entirely on the cloud offers additional security, as it’s more difficult to lose track of your files.Closing
A local development environment is a mandatory part of the Software Development Process. Given the ease at which you can install Apache, PHP, and MySQL on Mac OS X there really is no excuse.
Find this interesting? Let’s continue the conversation on Twitter.
Mac OS X serves as an excellent development environment, even if you are not actually developing Mac OS or iOS applications. It is the darling of many a LAMP (Linux, Apache, MySQL and PHP) developer, who enjoys a slick desktop operating system with good UNIX-like underpinnings but who don’t necessarily want to put up with all the various limitations and complications that running a Linux desktop brings, consistent improvements in this regard over recent years notwithstanding.
The only trouble with this is that if you want to develop LAMP applications and work on a Mac then traditionally you’ve needed a two-box setup; a Mac on your desk and Linux on a development server. For many this isn’t an issue, and indeed when you’ve got a team of developers, optimal, but what if you wanted a self-contained development environment that was restricted to just one box? What if you wanted that box to be your laptop so you could take it anywhere?Solutions
“Virtual machine!”, I hear you cry. Yes, this is a possible solution, and for many works well. Good virtualisation software is free these days, but using a local VM is cumbersome. Not only does it consume a large slice of your RAM but it also puts a lot of strain on the CPU, meaning that if you are running off your battery your battery life will be decreased. It’s also cumbersome; you have to start up the VM when you need it and there can be complications with the networking, for example, if you have connected to a public wireless network it’s possible that your VM might not be extended the same resource.
There is a software package for Mac OS called MAMP (the M for Mac OS replacing the L for Linux). This is a point-and-click installer which bundles Apache, Linux and PHP for installation on Mac OS. I don’t like this solution, for a number of reasons, including:
*Limited functionality unless you “go pro” (at quite considerable cost). Any self-respecting developer will require multiple virtual hosts as a minimum and won’t need or want a clicky-button interface to get what they want.
*You are entirely at the mercy of the distributors of MAMP with regards to component software versions that are made available to you and when.Alternative solution
There’s an alternative to this. You don’t have to fork out £39 for a package of what it otherwise freely and widely available software. With the help of my friend and colleague Ben Nimmo I present the following assembled and tested instructions for turning your Mac into a native MAMP server without using the packages download.MySQL
*Download and install the latest .dmg and install both the *.pkgs within it (don’t use the TAR/GZ archives). You may wish to install the Workbench too, it’s really good these days.
*Find where the mysql.sock file is expected to be in /etc/php.ini (should be /var/mysql/mysql.sock)
*Create the folder and link the socket file to the expected location.
*Add MySQL to command line by editing /Users/username/.bash_profile and adding this line and then either restarting terminal or source-ing the file:PHP
PHP comes with Mac OS, so it’s not necessary to download and install it, however, there are a couple of necessary steps to configure it:
*Copy the default php.ini file:
*Edit /etc/php.ini and uncomment this line to enable xdebug (not essential, but recommended):Apache
Apache too comes with Mac OS, so again, no need to download and install it. Its configuration, however, is a little more complex, but nothing scary. The described configuration will provide a special Apache “sandbox” environment for your projects. It uses the existing “Sites” directory in your Mac OS home directory.
*Create a subdirectory in this directory for each of your projects, ensuring that the directory name does not contain any characters that would be illegal in a URL. Within each of these subdirectories create another subdirectory called “web”; this will be become the web root of each project. The extra subdirectory is in case you wish to use a framework in your projects which may keep some of its files outside of the web server root (Symfony is a good example of this).
*Create a subdirectory called “logs” in your “Sites” directory; Apache will maintain two log files, access and error, for all the sandbox sites.
*Enable PHP5 with Apache by editing /etc/apache2/httpd.conf and uncomment the following line:
*Change the user and group to your username and “staff” respectively, also in /etc/apache2/httpd.conf:
*While still in /etc/apache2/httpd.conf, find the following configuration and change “Deny from all” to “Allow from all”:
*Create and edit /etc/apache/users/user.conf with the following, changing “sbf” to the username:
*Restart Apache:
Then, for each of your sites, add an entry in /etc/hosts for with the format “name.dev.local” pointing to 127.0.0.1, where name corresponds to a subdirectory in your “Sites” directory. Don’t forget that the public subdirectory of each site is assumed to be “web”, so make a symlink to this if the framework you use has a different convention.
You should then be able to access each of your sites from URLs using the convention http://name.dev.local/ – where “name” again is a subdirectory within your “Sites” directory.Apache Php Mysql Package
I’ve tested this setup procedure and It Works For Me [tm]. If, however, it doesn’t quite work for you as described, please let me know where you’re going wrong and how, if you were able, to resolve it, and I will update these instructions accordingly.
Download here: http://gg.gg/oirl6
https://diarynote-jp.indered.space
コメント