CentOS_6.5 install Nginx + PHP + MySQL

Source: Internet
Author: User
Tags install openssl sql error automake
Provides various official and user-released code examples. For code reference, you are welcome to learn how to install Nginx + PHP + MySQL in CentOS_6.5.
Preparations

Install make
Yum-y install gcc automake autoconf libtool make

Install g ++
Yum install gcc-c ++


Start now
---------------------------------------------------------------------------
Generally, we need to install pcre and zlib first. The former is used to rewrite, and the latter is used to compress gzip.
This document selects/data/soft/src.
I. Nginx Installation
Cd/data/soft/src

1. Install the PCRE Library
Ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/ download the latest PCRE source package, use the following command to download the compilation and installation of PCRE package:

Cd/data/soft/src
Wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.34.tar.gz
Tar-zxvf pcre-8.34.tar.gz
Cd pcre-8.34
./Configure
Make
Make install

2. Install the zlib library
Http://zlib.net/zlib-1.2.8.tar.gz to download the latest zlib source package, use the following command to download the compilation and installation of zlib package:

Cd/data/soft/src
Wget http://zlib.net/zlib-1.2.8.tar.gz
Tar-zxvf zlib-1.2.8.tar.gz
Cd zlib-1.2.8
./Configure
Make
Make install

3. Install ssl (ssl is not installed in some vps by default)
Cd/data/soft/src
Wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz
Tar-zxvf openssl-1.0.1c.tar.gz
Yum-y install openssl-devel

4. Install nginx
Nginx generally has two versions: stable version and development version. You can select one of these two versions based on your purpose, the following describes how to install Nginx in the/data/soft/nginx directory:

Cd/data/soft/src
Wget http://nginx.org/download/nginx-1.4.2.tar.gz
Tar-zxvf nginx-1.4.2.tar.gz
Cd nginx-1.4.2
. /Configure -- sbin-path =/data/soft/nginx \ -- conf-path =/data/soft/nginx. conf \ -- pid-path =/data/soft/nginx. pid \ -- with-http_ssl_module \ -- with-pcre =/data/src/pcre-8.34 \ -- with-zlib =/data/src/zlib-1.2.8 \ -- with-openssl =/data/src/openssl-1.0.1c
Make
Make install

After the installation is successful, the/data/soft/nginx directory is as follows:
Fastcgi. conf koi-win nginx. conf. default
Fastcgi. conf. default logs scgi_params
Fastcgi_params mime. types scgi_params.default
Fastcgi_params.default mime. types. default uwsgi_params
Html nginx uwsgi_params.default
Koi-utf nginx. conf win-utf

5. Start
Ensure that port 80 of the system is not occupied by other programs. Run the/data/soft/nginx command to start Nginx,

Netstat-ano | grep 80
If no result is found, skip this step.
Sudo/usr/local/nginx

Open the browser to access the IP address of this machine. If the browser displays Welcome to nginx! Nginx has been installed and runs successfully.

Nginx is installed here. If you only need to process static html, you do not need to continue the installation. If you need to process php scripts, you also need to install php-fpm.

6. Start Nginx at startup
Echo "/data/soft/nginx/sbin/nginx">/etc/rc. local


Ii. Compile and install php-fpm
PHP-FPM is a PHP FastCGI manager that is only used for PHP and can be downloaded at http://php-fpm.org/download.

PHP-FPM is actually a patch of PHP source code, designed to integrate FastCGI process management into the PHP package. You must patch it to your PHP source code before using it after compiling and installing PHP.

The new version of PHP has already integrated php-fpm and is no longer a third-party package. We recommend that you use it. PHP-FPM provides a better PHP process management method, can effectively control the memory and process, can smoothly load PHP configuration, than spawn-fcgi has more advantages, so it is officially included by PHP. In./configure with-enable-fpm parameters to open the PHP-FPM, other parameters are configured php, the meaning of the specific options can be viewed here: http://www.php.net/manual/en/configure.about.php.

Preparations before installation
Run the command in centos (automatically install gcc)
Yum-y install gcc automake autoconf libtool make
Yum-y install gcc-c ++ glibc

Yum-y install libmcrypt-devel mhash-devel libxslt-devel \
Libjpeg-devel libpng-devel freetype-devel libxml2 libxml2-devel \
Zlib-devel glibc-devel glib2 glib2-devel bzip2 bzip2-devel \
Ncurses-devel curl-devel e2fsprogs e2fsprogs-devel \
Krb5 krb5-devel libidn-devel openssl-devel

1. install php-fpm (recommended)
Cd/data/soft/src
Wget http://museum.php.net/php5/php-5.4.7.tar.gz
Tar zvxf php-5.4.7.tar.gz
Cd php-5.4.7
. /Configure -- prefix =/data/soft/php -- enable-fpm -- with-mcrypt \ -- enable-mbstring -- disable-pdo -- with-curl -- disable-debug -- disable-rpath \ -- enable-inline-optimization -- with-bz2 -- with-zlib -- enable-sockets \ -- enable-sysvsem -- enable-sysvshm -- enable-pcntl -- enable-mbregex \ -- with-mhash -- enable-zip -- with-pcre-regex -- with-mysql -- with-mysqli \ -- with-gd -- with-jpeg-dir
Make all install

2. The above completes the installation of php-fpm.
Below are the settings for php-fpm running users
Cd/data/soft/php
Cp etc/php-fpm.conf.default etc/php-fpm.conf
Vi etc/php-fpm.conf
Modify
User = www
Group = www

If the www user does not exist, add the www user first.
Groupadd www
Useradd-g www

3. Modify the nginx configuration file to support php-fpm
Modify the nginx configuration file to nginx. conf.
The following configurations are added to the server segment:

# Pass the PHP scripts to FastCGI server listening on Fig: 9000
Location ~ \. Php $ {
Root/data/www; # project root directory
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
Fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;
Include fastcgi_params;
}

4. Create a PHP Test File
Create a PHP File

Create the index. php file under/data/www and enter the following content:
Echo phpinfo ();
?>

5. Start the php-fpm Service
/Data/soft/php/sbin/php-fpm

Restart the nginx Server:
/Data/nginx-s reload

6. Disable and restart php-fpm
Disable php-fpm:
Kill-INT 'cat/data/soft/php/var/run/php-fpm.pid'

Php-fpm restart:
Kill-USR2 'cat/data/soft/php/var/run/php-fpm.pid'

7. php-fpm boot
Echo "/data/soft/php/sbin/php-fpm">/etc/rc. local


Iii. Install mysql
Cd/data/soft/src
Wget http://downloads.mysql.com/archives/mysql-5.1/mysql-5.1.70.tar.gz
Tar-zxvf mysql-5.1.70.tar.gz
Cd mysql-5.1.70

Yum install ncurses-devel
. /Configure '-- prefix =/data/soft/mysql ''-- without-debug'' -- with-charset = utf8'' -- with-extra-charsets = all'' -- enable -Cycler ''-- with-pthread'' -- enable-thread-safe-client ''-- with-mysqld-ldflags =-all-static'' -- with-client-ldflags = -all-static ''-- with-big-tables'' -- with-readline ''-- with-ssl'' -- with-embedded-server ''-- enable-local-infile ''-- with-plugins = innobase' make
Make install

Mysql is installed in the/data/soft/mysql path.
------------------------------------

Install the mysql option File
Cp support-files/my-medium.cnf/etc/my. cnf

Set Automatic startup for mysql
Cp-r support-files/mysql. server/etc/init. d/mysqld
/Sbin/chkconfig -- del mysqld
/Sbin/chkconfig -- add mysqld

Configure permission table
Chown-R mysql: mysql/data/soft/mysql
/Data/soft/mysql/bin/mysql_install_db -- user = mysql

Start mysql
/Etc/init. d/mysqld start

Mysql Initialization Configuration:
Export PATH =/data/soft/mysql/bin: $ PATH
/Data/soft/mysql/bin/mysql_secure_installation
Note: Set the mysql root Password as prompted.

Now that mysql is installed, we start to use the client to connect to mysql.
If an error is reported:
SQL Error (1130): Host '192. 168.1.100 'is not allowed to connect to this MySQL server

First, log on to the Mysql server by following the steps below

To log on to mysql, you need to switch to the bin directory of mysql under dos and perform the following operations:

# Mysql-uroot-ppassword
Mysql> use mysql;

Mysql> update user set host = '%' where user = 'root ';

Mysql> flush privileges;

Mysql> select 'host', 'user' from user where user = 'root ';

Mysql> quit
OK. Remote connection successful!
The software package can be downloaded directly to the 360 cloud Disk: http://yunpan.cn/cfX8FB5UTnfDR (extraction code: 91e7)

AD: truly free, domain name + VM + enterprise mailbox = 0 RMB

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.