Compile and install Nginx + MySQL + PHP in CentOS 7.0

Source: Internet
Author: User
Tags mcrypt

Compile and install Nginx + MySQL + PHP in CentOS 7.0

Preparation:

CentOS 7.0 system installation and configuration graphic tutorial

Http://www.osyunwei.com/archives/7829.html

1. configure the firewall and enable port 80 and port 3306

CentOS 7.0 uses firewall as the firewall by default. Here, it is changed to iptables firewall.

1. Disable firewall:

Systemctl stop firewalld. service # stop firewall

Systemctl disable firewalld. service # disable firewall startup

2. Install iptables Firewall

Yum install iptables-services # Installation

Vi/etc/sysconfig/iptables # edit the firewall configuration file

# Firewall configuration written by system-config-firewall

# Manual customization of this file is not recommended.

* Filter

: Input accept [0: 0]

: Forward accept [0: 0]

: Output accept [0: 0]

-A input-m state -- state ESTABLISHED, RELATED-j ACCEPT

-A input-p icmp-j ACCEPT

-A input-I lo-j ACCEPT

-A input-m state -- state NEW-m tcp-p tcp -- dport 22-j ACCEPT

-A input-m state -- state NEW-m tcp-p tcp -- dport 80-j ACCEPT

-A input-m state -- state NEW-m tcp-p tcp -- dport 3306-j ACCEPT

-A input-j REJECT -- reject-with icmp-host-prohibited

-A forward-j REJECT -- reject-with icmp-host-prohibited

COMMIT

: Wq! # Save and exit

Systemctl restart iptables. service # restart the firewall to make the configuration take effect.

Systemctl enable iptables. service # Set firewall startup

Ii. Disable SELINUX

Vi/etc/selinux/config

# SELINUX = enforcing # comment out

# SELINUXTYPE = targeted # comment out

SELINUX = disabled # Add

: Wq! # Save and exit

Setenforce 0 # Make the configuration take effect immediately

Iii. system conventions

Software source code package storage location:/usr/local/src

Source code package compilation and installation location:/usr/local/software name

4. download the software package

1. Download nginx (current stable version)

Http://nginx.org/download/nginx-1.6.0.tar.gz

2. Download MySQL

Http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.19.tar.gz

3. Download php

Http://cn2.php.net/distributions/php-5.5.14.tar.gz

4. Download pcre (support for nginx pseudo-static)

Ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.35.tar.gz

5. Download openssl (nginx extension)

Http://www.openssl.org/source/openssl-1.0.1h.tar.gz

6. Download zlib (nginx extension)

Http://zlib.net/zlib-1.2.8.tar.gz

7. Download cmake (MySQL compilation tool)

Http://www.cmake.org/files/v2.8/cmake-2.8.11.2.tar.gz

8. Download libmcrypt (php extension)

Http://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz

9. Download yasm (php extension)

Http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz

10. t1lib (php extension)

Ftp://sunsite.unc.edu/pub/Linux/libs/graphics/t1lib-5.1.2.tar.gz

11. Download the gd library installation package

Https://bitbucket.org/libgd/gd-libgd/downloads/libgd-2.1.0.tar.gz

12. libvpx (required by the gd library)

Https://webm.googlecode.com/files/libvpx-v1.3.0.tar.bz2

13. tiff (required by the gd library)

Http://download.osgeo.org/libtiff/tiff-4.0.3.tar.gz

14. libpng (required by gd library)

Ftp://ftp.simplesystems.org/pub/png/src/libpng16/libpng-1.6.12.tar.gz

15. freetype (required by the gd library)

Http://download.savannah.gnu.org/releases/freetype/ft2demos-2.5.3.tar.gz

16. Required SRC (required by the gd library)

Http://www.ijg.org/files/jpegsrc.v9a.tar.gz

The above software package uses the WinSCP tool to upload to the/usr/local/src directory.

WinSCP: http://winscp.net/download/winscp554.zip

System O & M www.osyunwei.com reminder: qihang01 original content©Copyright. For more information, see the source and source text chain.

5. Install the compilation tool and library file (use the yum command for installation)

Yum install-y apr * autoconf automake bison bzip2 bzip2 * cloog-ppl compat * cpp curl-devel fontconfig-devel freetype * freetype-devel gcc-c ++ gtk + -devel gd gettext-devel glibc kernel-headers keyutils-libs-devel krb5-devel libcom_err-devel libpng-devel libjpeg * libsepol-devel runtime-devel libstdc + +-devel libgomp tool * libxml2 libxml2-devel libXpm * libtiff * make mpfr ncurses * ntp openssl-devel patch pcre-devel perl php-common php-gd policycoreutils telnet t1lib t1lib * nasm * wget zlib-devel

Installation

Use putty to remotely log on to the server.

1. Install MySQL

1. Install cmake

Cd/usr/local/src

Tar zxvf cmake-2.8.11.2.tar.gz

Cd cmake-2.8.11.2

./Configure

Make

Make install

2. Install MySQL

Groupadd mysql # Add a mysql Group

Useradd-g mysql-s/bin/false # create a user mysql and add it to the mysql group. mysql users are not allowed to log on directly to the system.

Mkdir-p/data/mysql # create a directory for storing MySQL Databases

Chown-R mysql: mysql/data/mysql # Set the directory permission for storing MySQL Databases

Mkdir-p/usr/local/mysql # create the MySQL installation directory

Cd/usr/local/src # enter the package storage directory

Tar zxvf mysql-5.6.19.tar.gz # Extract

Cd mysql-5.6.19 # Go To The Directory

Cmake.-DCMAKE_INSTALL_PREFIX =/usr/local/mysql-DMYSQL_DATADIR =/data/mysql-DSYSCONFDIR =/etc # Configuration

Make # compile

Make install # install

Rm-rf/etc/my. cnf # Delete the default configuration file of the system (if it does not exist by default, you do not need to delete it)

Cd/usr/local/mysql # enter the MySQL installation directory

./Scripts/mysql_install_db -- user = mysql -- basedir =/usr/local/mysql -- datadir =/data/mysql # generate a mysql System Database

Ln-s/usr/local/mysql/my. cnf/etc/my. cnf # soft connection added to the/etc directory

Cp./support-files/mysql. server/etc/rc. d/init. d/mysqld # Add Mysql to the system to start

Chmod 755/etc/init. d/mysqld # Add execution permission

Chkconfig mysqld on # Add to startup

Vi/etc/rc. d/init. d/mysqld # Edit

Basedir =/usr/local/mysql # MySQL installation path

Datadir =/data/mysql # MySQl database storage directory

: Wq! # Save and exit

Service mysqld start # start

Vi/etc/profile # Add the mysql service to the system environment variable: Add the following line at the end

Export PATH = $ PATH:/usr/local/mysql/bin

: Wq! # Save and exit

Source/etc/profile # Make the configuration take effect immediately

The following two lines link the myslq library file to the default system location, so that you do not need to specify the mysql library file address when compiling software such as PHP.

Ln-s/usr/local/mysql/lib/mysql/usr/lib/mysql

Ln-s/usr/local/mysql/include/mysql/usr/include/mysql

Mkdir/var/lib/mysql # create a directory

Ln-s/tmp/mysql. sock/var/lib/mysql. sock # Add soft link

Mysql_secure_installation # Set the Mysql password. Press Y to enter the password twice.

Ii. Install Nginx

1. Install pcre

Cd/usr/local/src

Mkdir/usr/local/pcre

Tar zxvf pcre-8.35.tar.gz

Cd pcre-8.35

./Configure -- prefix =/usr/local/pcre

Make

Make install

2. Install openssl

Cd/usr/local/src

Mkdir/usr/local/openssl

Tar zxvf openssl-1.0.1h.tar.gz

Cd openssl-1.0.1h

./Config -- prefix =/usr/local/openssl

Make

Make install

Vi/etc/profile

Export PATH = $ PATH:/usr/local/openssl/bin

: Wq!

Source/etc/profile

3. Install zlib

Cd/usr/local/src

Mkdir/usr/local/zlib

Tar zxvf zlib-1.2.8.tar.gz

Cd zlib-1.2.8

./Configure -- prefix =/usr/local/zlib

Make

Make install

4. Install Nginx

Groupadd www

Useradd-g www-s/bin/false

Cd/usr/local/src

Tar zxvf nginx-1.6.0.tar.gz

Cd nginx-1.6.0

. /Configure -- prefix =/usr/local/nginx -- without-http_memcached_module -- user = www -- group = www -- with-http_stub_status_module -- with-http_ssl_module -- with-http_gzip_static_module -- with-openssl =/usr/local/src/openssl-1.0.1h -- with-zlib =/usr/local/src/zlib-1.2.8 -- with-pcre =/usr/local/src/pcre-8.35

Note: -- with-openssl =/usr/local/src/openssl-1.0.1h -- with-zlib =/usr/local/src/zlib-1.2.8 -- with-pcre =/usr/local/src/pcre-8.35 points is the path to extract the source code package, instead of the installation path. Otherwise, an error is reported.

Make

Make install

/Usr/local/nginx/sbin/nginx # Start Nginx

Set nginx startup

Vi/etc/rc. d/init. d/nginx # edit the Startup File and add the following content

System O & M www.osyunwei.com reminder: qihang01 original content©Copyright. For more information, see the source and source text chain.

######################################## ####################

#! /Bin/sh

#

# Nginx-this script starts and stops the nginx daemon

#

# Chkconfig:-85 15

# Description: Nginx is an HTTP (S) server, HTTP (S) reverse \

# Proxy and IMAP/POP3 proxy server

# Processname: nginx

# Config:/etc/nginx. conf

# Config:/usr/local/nginx/conf/nginx. conf

# Pidfile:/usr/local/nginx/logs/nginx. pid

# Source function library.

./Etc/rc. d/init. d/functions

# Source networking configuration.

./Etc/sysconfig/network

# Check that networking is up.

["$ NETWORKING" = "no"] & exit 0

Nginx = "/usr/local/nginx/sbin/nginx"

Prog = $ (basename $ nginx)

NGINX_CONF_FILE = "/usr/local/nginx/conf/nginx. conf"

[-F/etc/sysconfig/nginx] &./etc/sysconfig/nginx

Lockfile =/var/lock/subsys/nginx

Make_dirs (){

# Make required directories

User = '$ nginx-V 2> & 1 | grep "configure arguments:" | sed's/[^ *] * -- user = \ ([^] * \). */\ 1/G '-'

If [-z "'grep $ user/etc/passwd '"]; then

Useradd-M-s/bin/nologin $ user

Fi

Options = '$ nginx-V 2> & 1 | grep' configure arguments :''

For opt in $ options; do

If ['echo $ opt | grep'. *-temp-path'']; then

Value = 'echo $ opt | cut-d "="-f 2'

If [! -D "$ value"]; then

# Echo "creating" $ value

Mkdir-p $ value & chown-R $ user $ value

Fi

Fi

Done

}

Start (){

[-X $ nginx] | exit 5

[-F $ NGINX_CONF_FILE] | exit 6

Make_dirs

Echo-n $ "Starting $ prog :"

Daemon $ nginx-c $ NGINX_CONF_FILE

Retval =$?

Echo

[$ Retval-eq 0] & touch $ lockfile

Return $ retval

}

Stop (){

Echo-n $ "Stopping $ prog :"

Killproc $ prog-QUIT

Retval =$?

Echo

[$ Retval-eq 0] & rm-f $ lockfile

Return $ retval

}

Restart (){

# Configtest | return $?

Stop

Sleep 1

Start

}

Reload (){

# Configtest | return $?

Echo-n $ "Reloading $ prog :"

Killproc $ nginx-HUP

RETVAL =$?

Echo

}

Force_reload (){

Restart

}

Configtest (){

$ Nginx-t-c $ NGINX_CONF_FILE

}

Rh_status (){

Status $ prog

}

Rh_status_q (){

Rh_status>/dev/null 2> & 1

}

Case "$1" in

Start)

Rh_status_q & exit 0

$1

;;

Stop)

Rh_status_q | exit 0

$1

;;

Restart | configtest)

$1

;;

Reload)

Rh_status_q | exit 7

$1

;;

Force-reload)

Force_reload

;;

Status)

Rh_status

;;

Condrestart | try-restart)

Rh_status_q | exit 0

;;

*)

Echo $ "Usage: $0 {start | stop | status | restart | condrestart | try-restart | reload | force-reload | configtest }"

Exit 2

Esac

######################################## ####################

System O & M www.osyunwei.com reminder: qihang01 original content©Copyright. For more information, see the source and source text chain.

: Wq! # Save and exit

Chmod 775/etc/rc. d/init. d/nginx # grant the File Execution permission

Chkconfig nginx on # Set startup

/Etc/rc. d/init. d/nginx restart # restart

Open the Server IP address in the browser. The following interface is displayed, indicating that Nginx is successfully installed.

3. install php

1. Install yasm

Cd/usr/local/src

Tar zxvf yasm-1.2.0.tar.gz

Cd yasm-1.2.0

./Configure

Make

Make install

2. Install libmcrypt

Cd/usr/local/src

Tar zxvf libmcrypt-2.5.8.tar.gz

Cd libmcrypt-2.5.8

./Configure

Make

Make install

3. Install libvpx

Cd/usr/local/src

Tar xvf libvpx-v1.3.0.tar.bz2

Cd libvpx-v1.3.0

./Configure -- prefix =/usr/local/libvpx -- enable-shared -- enable-vp9

Make

Make install

4. Install tiff

Cd/usr/local/src

Tar zxvf tiff-4.0.3.tar.gz

Cd tiff-4.0.3

./Configure -- prefix =/usr/local/tiff -- enable-shared

Make

Make install

5. Install libpng

Cd/usr/local/src

Tar zxvf libpng-1.6.12.tar.gz

Cd libpng-1.6.12

./Configure -- prefix =/usr/local/libpng -- enable-shared

Make

Make install

6. Install freetype

Cd/usr/local/src

Tar zxvf freetype-2.5.3.tar.gz

Cd freetype-2.5.3

./Configure -- prefix =/usr/local/freetype -- enable-shared

Make # compile

Make install # install

7. Install jpeg

Cd/usr/local/src

Tar zxvf restart src.v9a.tar.gz

Cd jpeg-9a

./Configure -- prefix =/usr/local/jpeg -- enable-shared

Make # compile

Make install # install

8. Install libgd

Cd/usr/local/src

Tar zxvf libgd-2.1.0.tar.gz # Extract

Cd libgd-2.1.0 # Go To The Directory

. /Configure -- prefix =/usr/local/libgd -- enable-shared -- with-jpeg =/usr/local/jpeg -- with-png =/usr/local/libpng --- freetype =/usr/local/freetype -- with-fontconfig =/usr/local/freetype -- with-xpm =/usr/-- with-tiff =/usr/local/tiff -- -vpx =/usr/local/libvpx # Configuration

Make # compile

Make install # install

9. Install t1lib

Cd/usr/local/src

Tar zxvf t1lib-5.1.2.tar.gz

Cd t1lib-5.1.2

./Configure -- prefix =/usr/local/t1lib -- enable-shared

Make without_doc

Make install

10. install php

Note: If the system is 64-bit, run the following two commands. Otherwise, an error will occur when installing php (the 32-bit system does not need to be executed)

Ln-s/usr/lib64/libltdl. so/usr/lib/libltdl. so

\ Cp-frp/usr/lib64/libXpm. so */usr/lib/

Cd/usr/local/src

Tar-zvxf php-5.5.14.tar.gz

Cd php-5.5.14

Export LD_LIBRARY_PATH =/usr/local/libgd/lib

. /Configure -- prefix =/usr/local/php -- with-config-file-path =/usr/local/php/etc -- with-mysql =/usr/local/mysql -- with-mysqli =/usr/local/mysql/bin/mysql_config -- with-mysql-sock =/tmp/mysql. sock -- with-pdo-mysql =/usr/local/mysql -- with-gd -- with-png-dir =/usr/local/libpng -- with-jpeg-dir =/usr /local/jpeg -- with-freetype-dir =/usr/local/freetype -- with-xpm-dir =/usr/-- with-vpx-dir =/usr/local/libvpx /-- with-zlib-dir =/usr/local/zlib -- with-t1lib =/usr/local/t1lib -- with-iconv -- enable-libxml -- enable-xml -- enable-bcmath -- enable-shmop -- enable-sysvsem -- enable-inline-optimization -- enable-opcache -- enable-mbregex -- enable-fpm -- enable-mbstring -- enable-ftp -- enable-gd-native- ttf -- with-openssl -- enable-pcntl -- enable-sockets -- with-xmlrpc -- enable-zip -- enable-soap -- without-pear -- with-gettext -- enable-session --- mcrypt -- with-curl -- enable-ctype # Configuration

Make # compile

Make install # install

Cp php. ini-production/usr/local/php/etc/php. ini # copy the php configuration file to the installation directory

Rm-rf/etc/php. ini # Delete the built-in configuration file of the system

Ln-s/usr/local/php/etc/php. ini/etc/php. ini # Add a soft link to the/etc directory

Cp/usr/local/php/etc/php-fpm.conf.default/usr/local/php/etc/php-fpm.conf # copy the template file for php-fpm configuration file

Ln-s/usr/local/php/etc/php-fpm.conf # Add soft connection to/etc directory

Vi/usr/local/php/etc/php-fpm.conf # Edit

User = www # Set the php-fpm runtime account to www

Group = www # Set the php-fpm running group to www

Pid = run/php-fpm.pid # Remove the semicolon above

: Wq! # Save and exit

Set the startup of php-fpm

Cp/usr/local/src/php-5.5.14/sapi/fpm/init. d. php-fpm/etc/rc. d/init. d/php-fpm # copy php-fpm to the startup directory

Chmod + x/etc/rc. d/init. d/php-fpm # Add execution permission

Chkconfig php-fpm on # Set startup

Vi/usr/local/php/etc/php. ini # edit the configuration file

Find: disable_functions =

Changed to disable_functions = passthru, exec, system, chroot, scandir, chgrp, chown, shell_exec, proc_open, proc_get_status, ini_alter, ini_alter, rewrite, dl, openlog, syslog, readlink, symlink, delimiter, dll, popen, disk_free_space, checkdnsrr, checkdnsrr, getservbyname, getservbyport, delimiter, posix_ctermid, delimiter, delimiter, posix_getegid, delimiter, posix_getgrnam, posix_getgroups, upper, lower, lower, posix_getpid, lower, posix_getpwnam, lower, lower, posix_getsid, posix_getuid, lower, posix_kill, posix_mkfifo, lower, posix_setsid, posix_setuid, posix_strerror, posix_times, posix_ttyname, posix_uname

# List functions that can be disabled by PHP. If some programs need this function, they can be deleted and disabled.

Locate:; date. timezone =

Change to: date. timezone = PRC # set the time zone

Find: expose_php = On

Change to: expose_php = Off # disable display of php version information

Find: short_open_tag = Off

Changed to: short_open_tag = ON # php short labels supported

Find opcache. enable = 0

Changed to opcache. enable = 1 # php supports opcode caching

Find: opcache. enable_cli = 1 # php supports opcode caching

Changed to: opcache. enable_cli = 0

Add zend_extension = opcache. so # in the last line to enable the opcode cache function.

: Wq! # Save and exit

Configure nginx to support php

Vi/usr/local/nginx/conf/nginx. conf

Modify the configuration file/usr/local/nginx/conf/nginx. conf as follows:

User www; # Remove comments from the first line of user and change the Nginx runtime group to www; the group configuration must be the same as the user in the/usr/local/php/etc/php-fpm.conf, otherwise, an error occurred while running php.

Index index.html index.htm index. php; # add index. php

# Pass the PHP scripts to FastCGI server listening on Fig: 9000

#

Location ~ \. Php $ {

Root html;

Fastcgi_pass 127.0.0.1: 9000;

Fastcgi_index index. php;

Fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;

Include fastcgi_params;

}

# Cancel the location comment of the FastCGI server. Change the parameter of the fastcgi_param row to $ document_root $ fastcgi_script_name, or use the absolute path.

/Etc/init. d/nginx restart # restart nginx

Service php-fpm start # start php-fpm

Test

Cd/usr/local/nginx/html/# enter the default nginx website root directory

Rm-rf/usr/local/nginx/html/* # Delete the default test page

Vi index. php # create an index. php file

<? Php

Phpinfo ();

?>

: Wq! # Save and exit

Chown www. www/usr/local/nginx/html/-R # Set the directory owner

Chmod 700/usr/local/nginx/html/-R # Set Directory Permissions

Open the Server IP address in the browser and you will see the following interface

So far, CentOS 7.0 compilation and installation of Nginx1.6.0 + MySQL5.6.19 + PHP5.5.14 has been completed.

» Link to this article: http://www.osyunwei.com/archives/7891.html

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.