Install Apache2.4 + PHP7.0 + MySQL5.7.16 and apache2.4php7.0 in macOS siider.

Source: Internet
Author: User

Install Apache2.4 + PHP7.0 + MySQL5.7.16 and apache2.4php7.0 in macOS siider.

Although PHP and Apache are provided on Mac systems, they are sometimes not the desired version. Today, we have installed a newer version of PHP, namely PHP7.0 +, on macOS sield (10.12.1. In this blog, we installed Apache 2.4, MySQL5.7.16. This process will be detailed later.

I. Preparations before installation

1. install or update Homebrew

Homebrew does not repeat it too much, nor is it the first mention in the blog. It is an indispensable Package Manager on Mac. The following is the brew version I used locally. Of course, it is the latest version. Before installing the preceding content, make sure that your brew is in the latest version. The installation of Homebrew on Mac is not described in detail here. please Google it on your own.

Below, we first update the brew, prompting me that the current brew is the latest version. We can view the current brew version through brew-v. If you are not familiar with brew, you can use brew-h to view brew command operations. The details are as follows:

  

 

2. Xcode8.2

Make sure that your Xcode version is the latest. If your Xcode version is earlier than 8.2, you will be prompted to "Update Xcode" when compiling PHP7.0 +, the following error is returned when PHP7.0 is compiled under Xcode8.1.

  

Therefore, make sure that your Xcode is the latest version. The following figure shows the updated version of Xcode8.2.

  

 

Ii. Installation of Apache2.4

Of course, using brew to install Apache2.4 is relatively simple. The following is the command to install Apache2.4. Use the brew's tap command to create an Apache repository, and then use the install command to install Apache. Apache2.4 is installed here, so it is brew install httpd24. If you want to install Apache2.2, It is brew install httpd22.

brew tap homebrew/apache

brew install httpd24

The specific process is as follows:

  

After successful installation, you can use brew info httpd24 to view the details of your installed Apache2.4. The command for starting the Apache service is displayed. The following figure shows how to use brew to operate the Apache server.

Start Apache: brew services start homebrew/apache/httpd24

Restart Apache: brew services restart homebrew/apache/httpd24

Disable Apache: brew services stop homebrew/apache/httpd24

The following is the specific Apache Information:

  

After installing PHP7.0, We will configure Apache in a unified manner. However, we can start the Apache service and use its default configuration first. Below is the access to our Apache service after startup. Of course, the default port is port 8080, so the address you need to access is: localhost: 8080. You will see the following information when you access this address. You can access the page below in the browser, indicating that your Apache has been installed successfully.

  

 

Iii. MySQL Installation

MySQL installation is also relatively simple. We used it before introducing the Swift Perfect Server framework. That is to say, I have already installed the MySQL database through brew. Of course, if you have not installed MySQL, it is relatively easy to use brew to install MySQL. The following is the command for installing mysql. You need to wait for a while before installing MySQL.

brew install mysql

After installing the MySQL database according to the previous routine, you can use the brew info mysql command to view the corresponding mysql information. Below is my local mysql information. From info, we can clearly see that after you install MySQL for the first time, there will be a root user without a password for you to log on to the MySQL database. After you log on, you can set a password for the root user.

  

From the above information, we can also see the command to start the mysql server. Of course, we still use brew to start and close the MySQL service, as shown below:

Start: brew services start mysql

Restart: brew services restart mysql

Stop: brew services stop mysql

The procedure is as follows:

  

As mentioned in my previous blog, Sequel Pro on Mac is quite useful for visual MySQL management, as shown below:

  

 

Iv. PHP7.0 Installation

Next, we will use brew to install PHP7.0. I encountered some problems in this process. The first problem was the Xcode version. I didn't upgrade Xcode8.2 before, and then I reported an error when installing PHP7.0. Then I upgraded Xcode. I encountered other problems and will introduce them later.

 

1. View PHP7.0 Information

Before using Brew to install PHP7.0, we 'd better take a look at the corresponding installation information, because some options are also available when using brew to install PHP. If some options are not added, it may not be available in Apache, so it is better to check the related information of PHP before installation.

Below is the use of brew info php70 to view the relevant information, of course, you can also install PHP7.1. The conflicting PHP version is provided below. The corresponding dependency packages are provided. Of course, we have not installed PHP7.0, so most of them are the X number. There are some options below, which must be used to install PHP7.0. From the bottom we can clearly see that if you want to use this PHP version on Apache2.4, you have to add the -- with-httpd24 parameter.This parameter is indispensable. If you do not add it, your installed PHP cannot be used on the corresponding Apache., As shown below.

  

 

2. Create a PHP repository and install PHP7.0

The command for PHP7.0 installation is shown below. -- The with-httpd24 must be added, otherwise it cannot be used on Apache2.4.

brew tap homebrew/php

brew install php70 --with-httpd24

Below is an error I encountered when installing PHP7.0, you can directly use brew install php70 to install successfully, and add -- with-http24 will report the following error. In the error message below, the corresponding connection "https://github.com/homebrew/homebrew-php/issues/3736.pdf" is provided to solve the problem ". The corresponding solution is found in the github connection and executed on the terminal.After xcode-select -- install, reinstall it.

  

 

3. view the PHP information after installation.

The following is the information about the installed PHP70. Of course, some of them still work as forks. If necessary, we can add them later.

  

There is a lot of key information in Info. The following section is the PHP70 configuration in Apache. We need to add the configuration items below in the httpd. conf file of Apache. We will introduce it in detail later.

  

 

V. Apache configuration

Next, we need to configure our Apache server. Of course, it is mainly related to Apache2.4 and PHP7.0. As mentioned above, we mainly configure the httpd. conf file in this blog. First open the/usr/local/etc/apache2/2.4/httpd. conf file, which is the configuration file of Apache2.4.

First, we will configure the corresponding PHP version, that is, the configuration information in PHP and Info will be pasted into httpd. conf. As follows:

  

Configure the file root directory of the server as follows:

  

If necessary, add the index. php file as follows:

  

After the Apache service is restarted, we can test it. In wwwdoc, add the info. php method and use the phpinfo () function in the file to print the corresponding php information. As shown below.

  

Next we can access the info. php file in the browser, as shown below:

  

So far, the content of this blog is over, and the next step is to have fun playing PHP on Mac. It seems that some people say that PHP is short for (shooting H film), and Zi Yue: this is a real person.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.