Configure mysql + php (ThinkPHP) + nginx and centosthinkphp in centos 7

Source: Internet
Author: User
Tags sapi

Configure mysql + php (ThinkPHP) + nginx and centosthinkphp in centos 7

Recently, I deployed my website on the Linux platform by configuring servers !), Take notes!

1. First, install mysql under centos (refer to the blog)

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

1. Check whether the mysql version is installed before installation to avoid conflicts.

# Rpm-qa | grep mysql // check whether mysql is installed on the Operating System

2. Uninstall conflicting versions

# Rpm-e mysql // normal deletion mode # rpm-e -- nodeps mysql // strong deletion mode. If you use the preceding command to delete a file, the system prompts that there are other dependent files, you can use this command to forcibly delete it.

3. Run the rpm-qa | grep mysql command to check whether mysql has been uninstalled successfully !!

4. Install mysql

# Yum list | grep mysql // view the mysql database version available on yum # rpm-Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm // install mysql # mysql-v // view the version of installed mysql # yum install mysql-community-server // to enable mysql, you also need to install the mysql server, run this command to install # service mysqld start // start mysql # chkconfig mysqld on // set Mysql startup # grant all privileges on *. * to 'admin' @ '%' identified by '000000' with grant option; // set Mysql Remote Access // Note: Dmin is the database username, 123456 is the password, and @ '%' indicates that any IP address is allowed to connect to the database. Run the database command to enter the mysql database for # service mysqld restart // restart the service

II,Install php in centos(Refer to blog)

1. download the php installation package (create a directory such as/home/download)

# Wget http://mirrors.sohu.com/php/php-5.6.2.tar.gz // you can choose your own version

2. install the software package on which php5.6 is compiled

# Yum-y install gcc-c ++ libxml2 libxml2-devel // install the dependency package

3. decompress the downloaded php5.6 source code package.

# Tar-xf php-5.6.2.tar.gz // extract the source package

4. Go to the extracted directory./configure to configure the software to be installed and check whether the current environment meets the dependency 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 requirements for software installation link

5. Use the make command to compile php

# Make // compile php

Note: php compilation takes about 10-20 minutes depending on the machine performance. Please be patient!

6. After compilation, We will install php now.

# Make install // install php

7. After the installation is complete, run the php-v command to check whether the installation is successful.

# Php-v // view the version number

8. After installation, you will find that the php. ini file is not in the/usr/local/lib directory. Here we will first copy the template provided by the php installation file, as shown below:

# Cp php. ini-production/usr/local/lib/php. ini // copy the php. ini-production file to/usr/local/lib/php. ini

Note: The php installation is complete. nginx in the lnmp environment does not support php. fastcgi must be used to process php requests. Php requires the php-fpm component.

Php-fpm versions earlier than php5.3.3 exist in the form of a patch package. php-fpm Versions later than php5.3.3 only need to enable this function when installing php-fpm. This is the frontend. We can configure the command "enable-fpm" used by php.

After the php-fpm function is enabled, we also need to configure php-fpm. In fact, when installing php, the configuration file of php-fpm has provided us with a configuration file template. This template is/usr/local/etc/php-fpm.conf.default (can be viewed through the more/usr/local/etc/php-fpm.conf.default command)

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

# cp /usr/local/etc/php-fpm.conf.default /usr/local/etc/php-fpm.conf 

10. To enable php-fpm to be started as a service. Copy the/sapi/fpm/init. d. php-fpm file in the php installation directory.

# cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

11. The php-fpm file currently has no execution permission. We need to grant php-fpm execution permission and start php-fpm

# Chmod a + x/etc/init. d/php-fpm // grant php-fpm execution permission #/etc/init. d/php-fpm start // start php-fpm # netstat-tunlp | grep 9000 // view (php-fpm listens to port 9000 by default)

III,Install nginx in centos(Refer to blog)

1. Install the dependent library. You can skip this step.

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

Note: If you do not install these dependent libraries, an error will be reported later during compilation. Of course, you can skip these packages in your system.

Pcre: used for address rewriting.
Zlib: gzip module of nginx, which package transmission data and saves traffic (but consumes resources ).
Openssl: provides ssl encryption protocol.

2. Download and install nginx

# Wget http://nginx.org/download/nginx-1.9.9.tar.gz // download nginx compressed package # tar-zxvf nginx-1.9.2.tar.gz // extract compressed package # cd nginx-1.9.2 // enter the extracted directory #. /configure // check whether the current environment meets the dependency of the software to be installed # make // compile nginx # make install // install mg1 _

3. nginx is installed on/usr/local/nginx/You can start the nginx service, but it is not. There is no nginx service at this time. You need to create a service.

# Vim/etc/init. d/nginx // use vim to open/etc/init. d/nginx
Enter the following content
#!/bin/bash# chkconfig:235 85 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 $1 in  start)          start ;;stop)          stop ;;restart)          restart ;;reload)          reload ;;configtest)          configtest ;;*)        echo "Usage: nginx {start|stop|restart|reload|configtest}"        ;;esac  

4. Grant the executable permission to this file. Otherwise, the service will not be started.

# Chmod + x/etc/init. d/nginx // give the file executable permission

5. Start nginx

# Service nginx start // start nginx

4. Configure nginx to support php (ThinkPHP)

1. Open the nginx configuration file/etc/nginx. conf and enter the following content in the server 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; # defines the variable $ path_info, which is used to store pathinfo information set $ path_info "; # defines the variable $ real_script_name, used to store the real address set $ real_script_name $ fastcgi_script_name; # if the address matches the regular expression in the quotation marks, if ($ fastcgi_script_name ~ "^ (. +? \. Php )(/. +) $ ") {# assign the file address to the variable $ real_script_name set $ real_script_name $1; # assign the parameter after the file address to the variable $ path_info set $ path_info $2 ;} # configure fastcgi parameters 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 multiple sites on the ngnix server (refer to the blog)

Note: readers may encounter various problems during the process, and they need to constantly explore,Solve the problem,Note the error message. Stick to it !!!

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.