Apache Php For Mac

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.

Almost every tutorial on how to install the LAMP stack (Linux, Apache, MySQL, PHP) will recommend that you use the built-in Apache module for processing PHP scripts. For example, in Ubuntu you would enable this when you use a command such as sudo apt install libapache2-mod-phpto install a package. This would in turn force Apache to use mpm. Before I go on, I have the latest version (v5.0.15) of OS X Server (yes, horrible, I know.however, the web server seems to work A-OK).I searched high and low for days trying to update (or at least get Apache to point to) a new version of PHP. Before I go on, I have the latest version (v5.0.15) of OS X Server (yes, horrible, I know.however, the web server seems to work A-OK).I searched high and low for days trying to update (or at least get Apache to point to) a new version of PHP. Many website owners use PHP with their websites to expand the capabilities of the sites. Before you can enable PHP on a Mac, you first have to enable Apache. Both PHP and Apache are free open source software programs and both come installed on all Macs. PHP is server-side software, and Apache is the most widely used web server software. Mac runs on base Unix foundation so mainly you could install almost all Linux/Unix software on Mac very easily. Mac OS X comes by default with Apache Web 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.

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.

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

First, open the Terminal app and switch to the root user so you can run the commands in this post without any permission issues:

Mac

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.

Apache php mac os x

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.

Apache Php For Mac

Apache and PHP come packaged with OS X. To create a local web server, all you need to do is configure Apache and install MySQL.

Enable Apache on Mac OS X

To check what version of apache you have currently installed on your mac just open you terminal and type httpd -v

Verify if apache is running by accessing http://localhost:

If you get “This site can’t be reached”, you need to start apache, just type,sudo apachectl start and press enter:

Verify localhost again:

if you see “It works!” apache is running.

Apache Commands

You can start, stop, and restart your server by typing:

Setting up root directory

Apache’s default directory is /Library/WebServer/Documents that is where `It work’s!` file is located at.

Move into apache users folder:

Type ls and check if you have a config file named after your yourusername.conf username, if you can’t find one, that’s ok, then just type sudo nano yourusername.conf

Add this configuration to your file:

Press “Ctrl + x” to exit, “y” to save changes and hit enter.

Then to give apache permissions to read we type sudo chmod 644 YourUserName.conf and press enter, lastly we type sudo apachectl restart

Done!

Mac OSX 10.8 comes with PHP 5.2 by default, in order to check what version you currently have just type php -v.

Apache Php Server Mac

Whatever is the current version of your PHP, go ahead and update it here.

Enable PHP

Set up apache on mac

cd into Documents:

Apache Mysql Php For Mac

cd into apache directory:

then edit your config file:

then search “PHP” by using ctrl + w” :

Php

Uncomment the following line (remove #):

Now apache can serve PHP.

Configure PHP .ini

cd into /usr/local/php5/php.d

The configuration file (php.ini) is read when PHP starts up. For the server module versions of PHP, this happens only once when the web server is started. For the CGI and CLI versions, it happens on every invocation.

Here you can configure your time zone and other settings, just type:

Done!.

Download it from here

You don’t have to log in, just click “No thanks, just start my download”.

Run the installer.

Install Apache On Mac

Finish installation and set it up to be running on startup by going into your system preferences bottom line and clicking on MySQL icon, you will get a default password, save it, you will need it later.

Apache Php Mysql Mac High Sierra

Configure MySQL

Add MySQL to PATH

The path is a list of directories that Unix uses in order to locate programs on the machine that it can run.

If you type which php in your terminal you will get back its location:

Up until this point, MySQL has not yet been added to the path, we have to add the directory where MySQL resides to that list.

You can take a look at that list by typing:

MySQL is located at:

Now we need to add this path to PATH, just type:

We need to add this to .bash_profile:

Ctrl + x to exit then press “y” to save changes and enter to confirm file name.

Set root password

To set a new password:

If you already have a password and you want to change it, then type:

All ready!

Request–response, or request–reply, is one of the basic methods computers use to communicate with each other.

The browser sends a request for some data and apache responds to the request. Usually, there is a series of such interchanges until the complete response is sent.

Reply (All) With All Attachments in the mail conversation; Reply Many Emails in seconds; Auto Add Greeting when reply; Add Date into subject. Настройка outlook 2016 for mac.

This image illustrates how it works.

You can check if everything works by creating a .php file inside your /Sites directory, launch your browser and type in the address bar http://localhost/~yourusername/filename.php

Now your development environment is ready. Enjoy!

Adrian Prieto

“If you are not willing to learn, no one can help you. If you are determined to learn, no one can stop you.” ― Zig Ziglar

Latest posts by Adrian Prieto (see all)

  • How To Set Up Your WordPress Development Environment with a Large Database ft. MAMP & MAC, The Really Easy Guide - April 24, 2020
  • Next.js ▲ + Typescript + Storybook The Really Simple Guide 2019 - November 25, 2019
  • Next.js + Styled Components The Really Simple Guide ▲ + 💅 - June 26, 2018