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 Sierra comes pre-installed with PHP version 5.6, however the latest version of PHP is 7.1. After you complete this post, you should upgrade PHP on Mac OS X.
Note: This post is for new installations. If you have installed Apache, PHP, and MySQL for Mac OS El Capitan, read my post on Updating Apache, PHP, and MySQL for Mac OS X Sierra.
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.
Use the links below to download the Apache Tomcat. Unix, Linux, Mac OS). After you download the file, you should calculate a checksum for your download. 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. Cd /etc/apache2/ cp httpd.conf httpd.conf.sierra. Now edit the Apache configuration.
Running Commands
- Download Latest Version xampp-windows-x64-7.4.23-0-VC15-installer.exe (167.8 MB) Get Updates. Home / XAMPP Mac OS X. Downloads / Week.
- Apache OpenOffice.org for Mac OS X (Intel 64-bit) v3.0.0 Beta 2 RC 1 03 Jul 2008 Apache OpenOffice.org for Mac OS X (Intel 64-bit) v3.0.0 Beta 12 May 2008 Apache OpenOffice.org for Mac OS X (Intel 64-bit) v2.4.0 11 Jun 2008.
- Click on the link above to download Apache Directory Studio for macOS. The download appeares in the Downloads folder in Finder. Double-click on the disk image to open it. Drag-and-drop the Apache Directory Studio application on the Applications folder to install it.
Apache Openoffice Download Mac
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 Sierra 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 Sierra
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:
Mac Os X Download For Windows
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.
Configuring the source tree
The next step is to configure the Apache source tree for your particular platform and personal requirements. This is done using the script configure
included in the root directory of the distribution. (Developers downloading an unreleased version of the Apache source tree will need to have autoconf
and libtool
installed and will need to run buildconf
before proceeding with the next steps. This is not necessary for official releases.)
To configure the source tree using all the default options, simply type ./configure
. To change the default options, configure
accepts a variety of variables and command line options.
The most important option is the location --prefix
where Apache is to be installed later, because Apache has to be configured for this location to work correctly. More fine-tuned control of the location of files is possible with additional configure options.
Download Apache Web Server
Also at this point, you can specify which features you want included in Apache by enabling and disabling modules. Apache comes with a wide range of modules included by default. They will be compiled as shared objects (DSOs) which can be loaded or unloaded at runtime. You can also choose to compile modules statically by using the option --enable-module=static
.
Additional modules are enabled using the --enable-module
option, where module is the name of the module with the mod_
string removed and with any underscore converted to a dash. Similarly, you can disable modules with the --disable-module
option. Be careful when using these options, since configure
cannot warn you if the module you specify does not exist; it will simply ignore the option.
In addition, it is sometimes necessary to provide the configure
script with extra information about the location of your compiler, libraries, or header files. This is done by passing either environment variables or command line options to configure
. For more information, see the configure
manual page. Or invoke configure
using the --help
option.
For a short impression of what possibilities you have, here is a typical example which compiles Apache for the installation tree /sw/pkg/apache
with a particular compiler and flags plus the two additional modules mod_ldap
and mod_lua
:
$ CC='pgcc' CFLAGS='-O2'
./configure --prefix=/sw/pkg/apache
--enable-ldap=shared
--enable-lua=shared
When configure
is run it will take several minutes to test for the availability of features on your system and build Makefiles which will later be used to compile the server.
Details on all the different configure
options are available on the configure
manual page.