Php+mysql+nginx+phpmyadmin Environment Construction

Source: Internet
Author: User
Tags aliases curl fpm phpinfo phpmyadmin

English Original: http://blog.frd.mn/install-nginx-php-fpm-mysql-and-phpmyadmin-on-os-x-mavericks-using-homebrew/

Refer to post author: http://blog.liuweifeng.net/author/liuweifeng/

First of all, to avoid all kinds of magical errors, please install XCode. After Yosemite is released, the latest version of XCode is 6.1.0 (6a1052d). Then, do not ignore the step, please do in the terminal

Xcode-select--install  

To install the latest Xcode command line tools.

Installing Homebrew

If not installed, please visit official website →_→ Homebrew

If you have already installed Homebrew, perform brew doctor on the terminal to check for various possible conflicts and issues. Then perform brew update && brew upgrade the upgrade Homebrew itself and bring your own formulas

Installing PHP-FPM

Homebrew formulas in the default wood has php-fpm, we need to manually add:

Brew Tap homebrew/php  

Then start the installation:

Brew Search PHP     //Choose PHP versionBrew install--without-apache--with-fpm--with-MySQL php71

Change to the newly installed PHP, open ~/.bash_profile

Export path= "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"  //can take the following way

Because we're going to install nginx,apache, we don't need it. (Looks like OS X comes with Apache?). )。

If you want to use PHP on the command line, you need to set the $PATH in your shell's profile:

# If You use Bash    echo ' Export path= ' $ (brew--prefix homebrew/php/php71)/bin: $PATH "' >> ~/.bash_profile &&A MP;. ~/.bash_profile  # If You use Zshecho ' Export path= ' $ (brew--prefix homebrew/php/php71)/bin: $PATH "' >> ~/.ZSHRC &&. ~/.zshrc  

Set boot up:

mkdir -P~/library/  launchagents/usr/local/cellar/php71/7.1.5_17/homebrew.mxcl.php71.plist ~/library/launchagents/  

Start PHP-FPM:

See if PHP-FPM is listening on port 9000:

Lsof-pni4 | grep LISTEN | grep php  

The output should look like this:

PHP-FPM   78168 liuweifeng    7u  IPv4 0x9c66922b37bcbcb7      0t0  TCP 127.0.0.1:9000 (LISTEN)  PHP-fpm   78170 liuweifeng    0u  IPv4 0x9c66922b37bcbcb7      0t0  TCP 127.0.0.1:9000 ( LISTEN)  php-fpm   92277 liuweifeng    0u  IPv4 0x9c66922b37bcbcb7      0t0  TCP 127.0.0.1:9000 (LISTEN)  php-fpm   94154 liuweifeng    0u  IPv4      0x9c66922b37bcbcb7 0t0  TCP 127.0.0.1:9000 (LISTEN)  
Install MySQL
Mysql

Set boot up:

ln-sfv/usr/local/opt/mysql/*
MySQL Security Settings
Mysql_secure_installation

You can set the root password, remove anonymous users, disable root login, and so on.

Installing PhpMyAdmin

First you need to installautoconf

Settings $PHP_AUTOCONF :

# If You use Bashecho ' php_autoconf= "' $ (which AUTOCONF) ' ' >> ~/.bash_profile &&. ~/.bash_profile  

To start installing phpMyAdmin:

Brew Install phpMyAdmin  
Installing Nginx
Set boot auto-start

Since we need to start port 80, we need to use sudo to run Nginx

sudo cp-v/usr/local/opt/nginx/*. plist/library/launchdaemons/  sudo chown root:wheel/library/ Launchdaemons/homebrew.mxcl.nginx.plist
Start Nginx
Close Nginx
sudo launchctl unload/library/launchdaemons/homebrew.mxcl.nginx.plist  
More Configuration nginx.conf

Create a directory to use in the configuration file

Mkdir-p/usr/local/etc/nginx/logs  mkdir-p/usr/local/etc/nginx/sites-available  mkdir-p/usr/local/etc/ nginx/sites-enabled  mkdir-p/usr/local/etc/nginx/conf.d  mkdir-p/usr/local/etc/nginx/ssl  sudo mkdir-p /var/wwwsudo chown:staff/var/www  sudo chmod 775/var/www  

Remove the default nginx.conf (in fact there's /usr/local/etc/nginx/nginx.conf.default a backup you can take a look at if you want to see it ...) ), and then use curl the custom version downloaded from Github:

Rm/usr/local/etc/nginx/nginx. conf   -L HTTPS:///gist.github.com/frdmn/7853158/raw/nginx.conf-o/usr/local/etc/nginx/nginx.conf  

This is a simple and lightweight configuration file as much as possible.

Load PHP-FPM

Download my custom configuration file from Github:

Curl-l https://
Create a default virtual host
Curl-l https://gist.github.com/frdmn/7853158/raw/sites-available_default-o/usr/local/etc/nginx/ Sites-available/default  curl-l https://Gist.github.com/frdmn/7853158/raw/sites-available_ Default-ssl-o/usr/local/etc/nginx/sites-available/default-ssl  curl-l https://  Gist.github.com/frdmn/7853158/raw/sites-available_phpmyadmin-o/usr/local/etc/nginx/sites-available/phpmyadmin  

Use the Git clone my instance virtual host configuration from Github (including the default 404, 403 pages, and one phpinfo() rewrite).

Clone http://git.frd.mn/frdmn/nginx-virtual-host.git/var/www  rm-rf/var/ Www/.git  

After cloning, remember to delete the. Git directory so that it won't be logged by git.

The Translator notes: Actually, I bright this 404 and 403 is quite ugly ...

Setting up SSL

Create the desired directory

mkdir -p/usr/local/etc/nginx/ssl

Create 4096bit RSA keys and self-signed certificates:

OpenSSL req-new -newkey rsa:4096-days 365-nodes-x509-subj "/c=us/st=state/l=town/o=office/cn=localhost"-ke Yout/usr/local/etc/nginx/ssl/localhost. key -out/usr/local/etc/nginx/ssl/localhost. CRT   -New -newkey rsa:4096-days 365-nodes-x509-subj "/c=us/st=state/l=town/o=office/cn=phpmyadmin"-keyout/usr/ Local/etc/nginx/ssl/phpmyadmin. Key -OUT/USR/LOCAL/ETC/NGINX/SSL/PHPMYADMIN.CRT  
Enable Virtual Host

To create a soft link:

ln-sfv/usr/local/etc/nginx/sites-available/default /usr/local/etc/nginx/sites-enabled/default -sfv/usr/local/etc/nginx/sites-available/default-ssl/usr/local/etc/nginx/sites-enabled/    default-SSL  

Start Nginx again:

Final Test

Basically finished, click on the following link to feel it:

    • http://localhost→ "Nginx Works" page
    • Http://localhost/info→phpinfo ()
    • http://localhost/nope→ "Not Found" page
    • https://localhost:443→ "Nginx Works" page (SSL)
    • Https://localhost:443/info→phpinfo () (SSL)
    • https://localhost:443/nope→ "Not Found" page (SSL)
    • Https://localhost:306→phpmyadmin (SSL)
Service configuration

You will definitely be shutting down or restarting one of the services set up above, so you may need to set some aliases. (You need to modify the PHP version in bash_aliases)

# If You use bashcurl-l https://gist.github.com/frdmn/7853158/raw/bash_aliases-o/tmp/.bash_aliases  cat/tmp/. Bash_aliases >> ~/.bash_aliases  echo "source ~/.bash_aliases" >> ~/.bash_profile  # If you use Zshcurl-l https://gist.github.com/frdmn/7853158/raw/bash_aliases-o/TMP/.ZSHRC  cat/tmp/.bash_aliases >> ~/.ZSHRC  echo "source ~/.bash_aliases" >> ~/.ZSHRC  

Then open a terminal window to make the above aliases effective:

SOURCE ~/. bash_profile   # orsource ~/.ZSHRC  

Now you can use aliases instead of launchctl a long list of parameters ~

Nginx

You can start, close, and restart Nginx in this way:

Nginx. start  nginx. Stop  nginx. Restart  

Quick tail access Logs and error logs:

Nginx.logs. access  nginx. Logs. default. access  nginx. Logs.phpmyadmin. access  nginx. Logs. default-ssl. access  nginx. Logs. error  nginx. Logs.phpmyadmin.error  

Check the configuration:

php-fpm

Start, close, restart PHP-FPM:

PHP-FPM. start  php-fpm. Stop  PHP

Check the configuration:

Php-fpm-t
Mysql

To start, shut down, and restart MySQL:

MySQL. Start   MySQL. Stop   MySQL. restart  

Php+mysql+nginx+phpmyadmin Environment Construction

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.