Although Mac systems come with PHP and Apache, sometimes they are not the versions we want. Today we will install a newer version of PHP, which is PHP7.0+, on macOS Sierra (10.12.1). In this blog, we installed Apache version 2.4 and MySQL 5.7.16. More on this process later. 1. Preparation before installation 1. Install or update Homebrew I won’t go into too much detail about Homebrew. This is not the first time I’ve mentioned it in this blog. It is an indispensable package manager on Mac. The screenshot below shows the version information of brew I use locally, which is of course the latest version. Before installing the above related content, make sure your brew is the latest version. I won’t go into details about how to install Homebrew on Mac, please Google it yourself. Below, I first performed the brew update operation, which prompted me that the current brew is the latest version. We can use brew -v to view the current brew version. If you are not familiar with brew, you can use brew -h to view brew-related command operations. The details are as follows: 2.Xcode8.2 Make sure your Xcode is the latest version. If your Xcode is before 8.2, you will be prompted to "update Xcode" when you compile PHP7.0+. The following is the error reported when compiling PHP7.0 under Xcode8.1. So, make sure your Xcode is the latest version. Below is my updated Xcode 8.2 version. 2. Installation of Apache2.4 Of course, it is relatively simple to install Apache2.4 using brew. Below is the command to install Apache2.4. First use brew's tap command to create the Apache repository, and then use the install command to install Apache. What we want to install here is Apache2.4, so brew install httpd24. If you want to install Apache2.2, then 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 specific information of your installed Apache2.4. There will be corresponding commands to start the Apache service. Below are the corresponding operations for using brew to operate the Apache server. Start Apache: brew services start homebrew/apache/httpd24 Restart Apache: brew services restart homebrew/apache/httpd24 Shut down Apache: brew services stop homebrew/apache/httpd24 The screenshot below shows the specific Apache information: After installing PHP7.0 later, we will configure Apache uniformly, but we can start the Apache service first and use its default configuration. Below is the access to our Apache service after startup. Of course, the default port is 8080, so the address you need to visit is: localhost:8080. When you visit this address, you will see the information below. You can access the page below in your browser, indicating that your Apache has been successfully installed. 3. Installation of MySQL The installation of MySQL is also relatively simple. We have used it before when introducing Swift's Perfect server framework, which means that I have already installed the MySQL database locally through brew. Of course, if you don't have it installed, it's also relatively easy to install MySQL using brew. Below is the command to install MySQL. You need to wait for a while and your MySQL will be installed. brew install mysql Following the previous routine, after installing the MySQL database, you can use the brew info mysql command to view the corresponding MySQL information. Below is the corresponding information of my local mysql. It can be clearly seen from the info that after you install MySQL for the first time, there will be a root user without a password for you to log in to the MySQL database. After logging in, 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 stop the MySQL service, as shown below: Start: brew services start mysql Restart: brew services restart mysql Stop: brew services stop mysql The specific operations are as follows: As mentioned in the previous blog, Sequel Pro on Mac is quite easy to use for visual management of MySQL, as shown below: 4. Installation of PHP7.0 Next, we will use brew to install PHP 7.0. I encountered some problems during this process. The first was a problem with the Xcode version. I had not upgraded to the latest Xcode 8.2 before, and an error occurred when installing PHP 7.0. Later, I upgraded Xcode. Then we encountered other problems, which will be introduced later. 1. View PHP7.0 information Before using Brew to install PHP7.0, we'd better take a look at the corresponding installation information first, because there are some optional options when installing PHP using brew. If you don't add some optional options, it may not be available in Apache, so it is better to take a look at the relevant information of PHP before installation. Below is the corresponding information viewed using brew info php70. Of course, you can also install PHP7.1. Conflicting PHP versions are given below. And the corresponding dependency packages are given. Of course, we haven't installed PHP 7.0 yet, so most of them are marked with Xs. There are some options below that need to be used when installing PHP7.0. From the following we can clearly see that if you want to use this PHP version on Apache2.4, you have to add the parameter --with-httpd24. This parameter is indispensable. If you do not add it, your installed PHP will not be able to be used on the corresponding Apache, as shown below. 2. Create a PHP repository and install PHP7.0 Below is the command for PHP7.0 installation. --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. It can be installed successfully by directly using brew install php70, but adding --with-http24 will report the following error. In the error message below, the corresponding link to solve the problem is given: "https://github.com/Homebrew/homebrew-php/issues/3736". I found the corresponding solution in this github link. After executing xcode-select --install in the terminal, reinstall it and it will be OK. 3. View the installed PHP related information Below is the relevant information of the installed PHP70. Of course, some of them are still crossed out. If necessary, we can add them later. There is a lot of key information in Info. The following paragraph is the configuration of PHP70 in Apache. We need to add the following configuration items to the httpd.conf file in Apache. It will be introduced in detail later. 5. Apache Configuration Next we need to configure our Apache server. Of course, the main thing is the relationship between Apache2.4 and PHP7.0. As mentioned above, in this blog we mainly focus on the configuration of the httpd.conf file. First open the /usr/local/etc/apache2/2.4/httpd.conf file, which is the relevant configuration file of Apache2.4. First, we configure the corresponding PHP version, that is, paste the configuration information in PHP,Info into httpd.conf. As shown below: Then configure the server's document root as follows: If necessary, add the index.php index file as follows: After restarting the Apache service, we can test it by adding the info.php method in wwwdoc and using the phpinfo() function in the file to print out the corresponding php information. As shown below. Next we can access the info.php file in the browser as follows: At this point, the content of this blog has come to an end. Next, let’s have some fun with PHP on Mac. It seems that someone jokingly said that PHP is the abbreviation of (making H movies), Confucius said: This is a god. The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Detailed steps for setting up a nexus server
>>: Problems with Vue imitating Bibibili's homepage
During system maintenance, you may need to check ...
This article shares the specific code of jQuery t...
css-vars-ponyfill When using CSS variables to ach...
This article uses an example to describe how to r...
Firewall A firewall is a set of rules. When a pac...
B-tree is a common data structure. Along with him...
I recently read Yahoo's 34 Golden Rules and le...
In Dockerfile, run, cmd, and entrypoint can all b...
The examples in this article are all written in s...
Introduction to Angular Angular is an open source...
Table of contents 1. Scopes are expressed in diff...
Table of contents Problem Description The general...
In the past few years of my career, I have writte...
Hello everyone, today we are going to learn about...
Table of contents Preface text 1. Install styleli...