Mac Raiders (4)--using brew to configure the PHP7 development environment (MAC+PHP+APACHE+MYSQL+REDIS)

Source: Internet
Author: User
Tags fpm gmp php cli apache log install redis

There are a lot of articles on the Internet that are wrong, because it is copying others, the author does not have his own pro-test, not only can not help the novice, but also produces serious misleading, the following introduction is my constant crawling, pro-test one available Tutorial, I hope to give you some help (Mac version is sierra), please indicate the source
A. ap use the mac comes with
Basic usage:
Start Apache: Run "sudo apachectl start"
Stop Apache: run "sudo apachectl stop",
Check out Apache: version: run "sudo apachectl -v",
Restart Apache: Run "sudo apachectl restart"
Related directory
Apache log location /private/var/log/apache2/error_log
Apache configuration master file /etc/apache2/httpd-conf
Apache vhost configuration /etc/apache2/extra/httpd-vhost.conf
Second, install php7.0
1>Use brew doctor to check your brew operation
2> Add brew's PHP extension library: (mac os is more discriminating against PHP, not including PHP packages, then we have to bind other people's git repository, usage is $ brew tap <gihhub_user/repo>)
Brew update
Brew tap homebrew/dupes
Brew tap homebrew/php

(In some places, using brew tap josegonzalez/homebrew-php or brew tap josegonzalez/php, I went to the warehouse of josegonzalez and looked at the warehouse of the homebrew of fork, so I think there are enough of the above two warehouses, so don't write osegonzalez The)
You can use the brew options php70 command to view the options for installing php. Please note: If you want to use apache as the web server under mac, add --with-apache when compiling; if your web server is nginx, you need Plus --with-fpm. Here I install with the following options
Brew install php70 --with-apxs2 --with-apache --with-gmp --with-imap --with-tidy --with-debug
 
Here is a pit, --with-apache this to bring, otherwise the macos sierra system will not generate the corresponding libphp7.so module when installing php7
Then uninstall the downloaded apache, the method is
Brew list //View which are installed
Brew uninstall //Uninstall the corresponding module
Brew cleanup -s //Clear cache and old version files
 
Brew link php70 //Open the PHP70 process
Php -v / / test is successful
 
When you are done installing, enter
Brew info php70
I put the information I put at the end of the article. These words are very important. Please read them carefully.
 
3>Modify the apache configuration file
Open configuration file
Sudo vim /etc/apache2/httpd.conf
Comment out the following two sentences first
#LoadModule php5_module libexec/apache2/libphp5.so
#Include /private/etc/apache2/other/*.conf This line
Then add the following three items, pay attention to the address of libphp7.so, please write your own
LoadModule php7_module /usr/local/opt/php70/libexec/apache2/libphp7.so
 
<FilesMatch .php$>
SetHandler application/x-httpd-php
</FilesMatch>
 
<IfModule php7_module>
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
</IfModule>

The following mentions about the php version switching problem, if you don't care, please skip this paragraph, configure it again.
-------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- --------------------------------
The libphp5.so and libphp7.so modules control the php version used by our apache, for example, you also installed php56
Then add the following to the configuration file
#LoadModule php5_module /usr/local/opt/php56/libexec/apache2/libphp5.so
<IfModule php5_module>
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
</IfModule>
Control the php version of apache selection, then we can only choose one of the libphpX.so modules, the rest of the note, here we use php7, so comment out the libphp5.so sentence, if you use the php56 version, then the reverse operating
Analysis of the role of brew unlink and brew link, the operation here can not change the php version selected by apache, but can control the version in our terminal, we have automatically connected the executable program to /usr/local/bin when we use the brew installation under
  technology sharing
If there are the same executables in both directories, whoever takes precedence is affected by the PATH environment variable.
Enter echo $PATH at the terminal and get my own PATH variable as follows
/usr/local/bin:/usr/local/sbin:/usr/local/Cellar/git/2.10.2/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/ Sbin
Here /usr/local/bin has the highest priority, and the brew link phpxx command has softly connected the corresponding php version to this directory, so we can use the terminal php -v to view the corresponding version.
 -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- --------------------------------
 
4> Add the system environment variable PATH to facilitate our use
Enter the configuration file
Sudo vim ~/.bash_profile
Add the following to the path, note that /usr/local/bin is before /usr/local/sbin
Export PATH="$(brew --prefix homebrew/php/php70)/bin:$PATH"
Export PATH="/usr/local/bin:/usr/local/sbin:$PATH"
Then update the system resources to make them effective
Source ~/.bash_profile
Note:
<1> If you are using zsh, then the configuration file you added is ~/.zshrc
<2>About export PATH="$(brew --prefix homebrew/php/php70)/bin:$PATH" This sentence, in fact, we have automatically connected the executable to /usr/local/bin when using the brew installation. Down, so the php version selected when using the terminal is the version of brew, you can not write this sentence

Analysis of the path to the portal: environment variable PATH analysis
 
5> Test whether apache supports php70
Enter php -v to see your current php version
Create new info.php in the apache default directory (/Library/WebServer/Documents), the content is as follows
<?php
Phpinfo();
?>
Restart the apache service
Apache sudo apachectl restart
Enter localhost/info.php in the browser. When the screen appears, it’s just tears.
 
If you don't know how to configure the project, please click: apache site configuration portal
Three. Install mysql
1>Install mysql
Brew install mysql
 
2> View mysql installation information
Brew info mysql
We can see the following paragraph
 
#######brew info Tips after mysql command#######
We've installed your MySQL database without a root password. To secure it run:
Mysql_secure_installation
 
To connect run:
Mysql -uroot
 
To have launchd start mysql now and restart at login:
Brew services start mysql
Or, if you don’t want/need a background service you can just run:
Mysql.server start
#######brew info Tips after mysql command#######
 
Then we follow the prompts and enter the following command
Mysql_secure_installation
The next step is to follow the prompts and set the password.
Then decide if you want to run mysql and run it if needed.
Brew services start mysql
Run when you don't need it
Mysql.server start

3>Connect mysql
  without password
Mysql -uroot
If you have a password
Mysql -uroot -p
Try running a command
Show databes;
The result is as follows,
Mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.01 sec)
 
Method to exit after entering the mysql command
Exit
 
4> graphics tool is using navicat (cracked version)
4. Install redis
1>Install redis using brew
Brew install redis
 
2>View installation information
Brew info redis
Can see the following information
##########brew info redisDisplay Information#########
To have launchd start redis now and restart at login:
Brew services start redis
Or, if you don’t want/need a background service you can just run:
Redis-server /usr/local/etc/redis.conf
##########brew info redisDisplay Information#########
 
If you want to boot from the start then
Brew services start redis
If you want to use it, start again.
Redis-server /usr/local/etc/redis.conf
 
3> Start redis, the following screen shows that the installation is successful.
technology sharing
4>Open a new window in the terminal to use the client function
Command+n combination button to open a new window
Start the redis client with the redis-cli command.
Redis-cli
Use example
technology sharing
If you want to terminate redis
Redis-cli shutdown
 
Note: I am using the laravel framework, do not have to consider the redis extension of php7.
appendix
########brew info php70 After the command information ###########
==> Caveats
To enable PHP in Apache add the following to httpd.conf and restart Apache:
LoadModule php7_module /usr/local/opt/php70/libexec/apache2/libphp7.so
 
<FilesMatch .php$>
SetHandler application/x-httpd-php
</FilesMatch>
 
Finally, check DirectoryIndex includes index.php
DirectoryIndex index.php index.html
 
The php.ini file can be found in:
/usr/local/etc/php/7.0/php.ini
 
???? Extensions ????
 
If you are having issues with custom extension compiling, ensure that
You are using the brew version, by placing /usr/local/bin before /usr/sbin in your PATH:
 
PATH="/usr/local/bin:$PATH"
 
PHP70 Extensions will always be compiled against this PHP. Please install them
Using --without-homebrew-php to enable compiling against system PHP.
 
???? PHP CLI ????
 
If you wish to swap the PHP you use on the command line, you should add the following to ~/.bashrc,
~/.zshrc, ~/.profile or your shell‘s equivalent configuration file:
 
Export PATH="$(brew --prefix homebrew/php/php70)/bin:$PATH"
 
GMP has moved to its own formula, please install it by running: brew install php70-gmp
 
???? FPM ????
 
To launch php-fpm on startup:
Mkdir -p ~/Library/LaunchAgents
Cp /usr/local/opt/php70/homebrew.mxcl.php70.plist ~/Library/LaunchAgents/
Launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php70.plist
 
The control script is located at /usr/local/opt/php70/sbin/php70-fpm
 
OS X 10.8 and newer come with php-fpm pre-installed, to ensure you are using the brew version you need to make sure /usr/local/sbin is before /usr/sbin in your PATH:
 
PATH="/usr/local/sbin:$PATH"
 
You may also need to edit the plist to use the correct "UserName".
 
Please note that the plist was called ‘homebrew-php.josegonzalez.php70.plist’ in old versions
Of this formula.
 
With the release of macOS Sierra the Apache module is now not built by default. If you want to build it on your system
You have to install php with the --with-apache option. See brew options php70 for more details.
 
To have launchd start josegonzalez/php/php70 now and restart at login:
Brew services start josegonzalez/php/php70
 
 ########brew info php70 After the command information ###########

Related Article

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.