CentOS 7 under Configuration mysql+php (thinkphp) +nginx

Source: Internet
Author: User
Tags fpm install php openssl sapi

Recently configured the Server Deployment Web site on the Linux platform (say more tears!) ), take a note!

First, install MySQL under CentOS (refer to blog)

The MySQL Yum Library provides a simple and convenient way to install and update MySQL-related packages to the latest version. Reference Document: http://dev.mysql.com/downloads/repo/yum/.

1. Before installing, see if there is a MySQL version installed to avoid conflict

# Rpm-qa | grep mysql//check if MySQL is already installed on the operating system

2. Uninstall conflicting versions

# rpm-e MySQL//normal Delete mode # RPM-E--nodeps mysql//brute force Delete mode, if you use the above command to delete, prompted to have other dependent files, then use this command can be strongly deleted

3. After deletion via Rpm-qa | grep mysql command to see if MySQL uninstall succeeded!!

4. Install MySQL

# Yum List | grep MySQL//view the downloadable version of the MySQL database available on Yum # RPM-UVH http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm// Install mysql# mysql-v//view install MySQL version # Yum install mysql-community-server//enable MySQL also need to install MySQL server, through this command install # service MYSQLD  Start//Start mysql# chkconfig mysqld on//set MySQL Boot # grant all privileges on * * to ' admin ' @ '% ' identified by ' 123456 ' with Grant option; Set MySQL remote access//Note: admin for database user name, 123456 for password, @ '% ' means allow any IP connection database. This operation enters MySQL database under the database command # service MYSQLD restart//Restart services

Second, install PHP under CentOS(refer to the blog)

1. Download the PHP installation package (self-built directory such as:/home/download)

# wget http://mirrors.sohu.com/php/php-5.6.2.tar.gz  //version can be selected by itself

2. Install the packages that are dependent on php5.6 compilation

# yum-y Install gcc gcc-c++ libxml2 libxml2-devel  //Installation Dependency Package

3. Unzip the php5.6 source package just downloaded

# TAR-XF php-5.6.2.tar.gz//Decompression Source Package

4. Enter the extracted directory,./configure is configured for the software that is about to be installed, checking that the current environment meets the dependencies of the software to be installed.

# CD php-5.6.2  //Enter the extracted directory #./configure--enable-fpm--enable-mbstring--with-mysql=/usr--enable-pdo-- With-pdo-mysql//Check whether the current environment meets the dependencies to install the software

5. Compile php using the Make command

# make  //compile PHP

Note: PHP compiled for a long time, depending on the performance of the machine needs to wait about 10-20 minutes. Please wait patiently!

6. Once the compilation is complete, we will now start installing PHP

# make install  //install PHP

7. After the installation is complete, we can check whether the installation is successful through the PHP–V command.

# Php–v  //view version number

8. After this installation is complete, you will find that there is no php.ini file in the/usr/local/lib directory. In this we will first copy the PHP installation files provided by the template, as follows:

# CP Php.ini-production/usr/local/lib/php.ini  //copy php.ini-production file to/usr/local/lib/php.ini

Note: Do not think to this PHP installation is complete, LNMP environment of Nginx is not support PHP, need to fastcgi to handle the request for PHP. and PHP needs to php-fpm this component to support it.

Prior to php5.3.3 version php-fpm is in the form of a patch package, and php5.3.3 after the PHP-FPM only need to install PHP-FPM to enable this feature. This is the front, we then configure PHP to use the command--enable-fpm.

After the PHP-FPM function is turned on, we also need to configure PHP-FPM. In fact, PHP-FPM configuration file in the installation of PHP, we have provided a template for the configuration file. The template is/usr/local/etc/php-fpm.conf.default (can be viewed via the More/usr/local/etc/php-fpm.conf.default command)

9. Also only need to copy the file and rename it to php-fpm.conf

10. In order for the PHP-FPM to be started in the form of service. We need to copy the PHP installation directory under the/SAPI/FPM/INIT.D.PHP-FPM file

# CP./SAPI/FPM/INIT.D.PHP-FPM/ETC/INIT.D/PHP-FPM

11.PHP-FPM file does not currently have execute permissions. We want to give PHP-FPM permission to execute and start PHP-FPM

# chmod A+X/ETC/INIT.D/PHP-FPM//Give PHP-FPM Execute Permissions #/ETC/INIT.D/PHP-FPM start  //Start php-fpm# NETSTAT-TUNLP |grep 9000
   //view (PHP-FPM is listening by default is 9000 port)

Third, install nginx under CentOS(refer to blog)

1. Install the dependent library, the system has been able to skip.

# yum install-y gcc gcc-c++ autoconf automake# yum install-y zlib zlib-devel OpenSSL openssl-devel pcre-devel

Note: Do not install these dependent libraries, the subsequent compilation will be error, of course, your system already have these packages can be skipped.

Pcre: The function used for address rewriting.
Zlib:nginx's gzip module, which transmits data packaging, saves traffic (but consumes resources).
OpenSSL: Provides SSL encryption protocol.

2. Download Nginx and install

# wget http://nginx.org/download/nginx-1.9.9.tar.gz  //download Nginx Compression Pack # TAR-ZXVF nginx-1.9.2.tar.gz  //Unzip the package # CD nginx-1.9.2//Enter the extracted directory #./configure//Check that the current environment meets the dependencies to install software # make//compile nginx# made Install//install Mginx

3.nginx is installed by default /usr/local/nginx/ , you can already start the Nginx service, but it is not. There is no Nginx service at this time and you need to create a service.

#vim  /etc/init.d/nginx  
Enter the content below
#!/bin/bash# chkconfig:235 15# Description:nginx is an HTTP server. /etc/rc.d/init.d/functionsstart () {          echo "Start ..."        /usr/local/nginx/sbin/nginx &>/dev/null        if [$?-eq 0];then                echo "Start successful!"        else                echo "Start failed!"        Fi}stop () {          if Killproc nginx-quit; then                echo "Stopping ..."        Fi}restart () {          stop        sleep 1        Start}reload () {          killproc nginx-hup        echo "Reloading ..."}configtest () {          /usr/local/nginx/sbin/nginx- T}case $ in  start)          start; stop)          stop;; restart)          restart;; Reload)          reload;; configtest)          configtest;; *)        echo "Usage:nginx {start|stop|restart|reload|configtest}"        ;; Esac  

4. Execute permissions on this file, or you will not have permission to start the service

# chmod  +x  /etc/init.d/nginx  //give this file permission to execute

5. Finally start Nginx

# service Nginx Start  //Startup Nginx

Four, configure Nginx, so that it supports PHP (thinkphp)

1. Open nginx Config file/etc/nginx/nginx.conf Enter the following in the server to allow it to support PHP (thinkphp)

 location ~ \.php/?             * {root/home/www/xxxx;             Fastcgi_pass 127.0.0.1:9000;             Fastcgi_index index.php;             Fastcgi_param script_filename $document _root$fastcgi_script_name;             Include Fastcgi_params;             #定义变量 $path _info for storing pathinfo information set $path _info "";             #定义变量 $real _script_name for storing the real address set $real _script_name $fastcgi _script_name; #如果地址与引号内的正则表达式匹配 if ($fastcgi _script_name ~ "^ (. +?\.php) (/.+) $") {#将文件地址赋值给变量 $real _script_                  Name set $real _script_name $;             #将文件地址后的参数赋值给变量 $path _info set $path _info;             } #配置fastcgi的一些参数 fastcgi_param script_filename $document _root$real_script_name;             Fastcgi_param script_name $real _script_name; Fastcgi_param path_info $path _info; }
# service Nginx Restart  //restart Nginx

3. Of course you can set up multiple sites in the Ngnix server (refer to the blog)

Note: The process may encounter a variety of problems, the reader needs to constantly explore, solve the problem, pay attention to error tips. To insist!!!

CentOS 7 under Configuration mysql+php (thinkphp) +nginx

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.