CentOS 7.0 compile and install nginx1.6.0+mysql5.6.19+php5.5.14
First, configure the firewall, open 80 port, 3306 port
CentOS 7.0 defaults to using firewall as the firewall, where the iptables firewall is changed.
1. Close firewall:
Systemctl Stop Firewalld.service #停止firewall
Systemctl Disable Firewalld.service #禁止firewall开机启动
2. Install iptables Firewall
Yum Install iptables-services #安装
Vi/etc/sysconfig/iptables #编辑防火墙配置文件
# Firewall configuration written by System-config-firewall
# Manual Customization of this file are 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! #保存退出
Systemctl Restart Iptables.service #最后重启防火墙使配置生效
Systemctl Enable Iptables.service #设置防火墙开机启动
Second, to close SELinux
Vi/etc/selinux/config
#SELINUX =enforcing #注释掉
#SELINUXTYPE =targeted #注释掉
Selinux=disabled #增加
: wq! #保存退出
Setenforce 0 #使配置立即生效
Third, the system contract
Software source code Package storage location:/USR/LOCAL/SRC
Source Package Compilation Installation location:/usr/local/software Name
Iv. Download the Package
1, download Nginx (currently 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 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 GD Library installation package
Https://bitbucket.org/libgd/gd-libgd/downloads/libgd-2.1.0.tar.gz
12, LIBVPX (GD library required)
https://webm.googlecode.com/files/libvpx-v1.3.0.tar.bz2
13, TIFF (GD library required)
Http://download.osgeo.org/libtiff/tiff-4.0.3.tar.gz
14, libpng (GD library required)
Ftp://ftp.simplesystems.org/pub/png/src/libpng16/libpng-1.6.12.tar.gz
15, FreeType (GD library required)
Http://download.savannah.gnu.org/releases/freetype/ft2demos-2.5.3.tar.gz
16, JPEGSRC (GD library required)
Http://www.ijg.org/files/jpegsrc.v9a.tar.gz
The above packages are uploaded to the/USR/LOCAL/SRC directory using the WinSCP tool
xshell5+xftp5:http://download.csdn.net/detail/allen_a/9429544
Install the compilation tools and library files (install using the yum command)
Yum install-y apr* autoconf automake bison bzip2 bzip2* cloog-ppl compat* cpp Curl Curl-devel fontconfig Fontconfig-devel FreeType freetype* freetype-devel gcc gcc-c++ gtk+-devel gd gettext gettext-devel glibc kernel kernel-headers keyutils ke Yutils-libs-devel krb5-devel libcom_err-devel libpng libpng-devel libjpeg* libsepol-devel libselinux-devel libstdc++- Devel libtool* libgomp libxml2 libxml2-devel libxpm* libtiff libtiff* make MPFR ncurses* ntp OpenSSL openssl-devel patch p Cre-devel perl php-common php-gd policycoreutils telnet t1lib t1lib* nasm nasm* wget zlib-devel
Installation article
The following is a remote login to the server using the XSHELL5 tool, which operates under the command line
First, install MySQL
1, installation 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 #添加mysql组
useradd-g MySQL mysql-s/bin/false #创建用户mysql并加入到mysql组, does not allow MySQL users to log in directly to the system
Mkdir-p/data/mysql #创建MySQL数据库存放目录
Chown-r Mysql:mysql/data/mysql #设置MySQL数据库存放目录权限
Mkdir-p/usr/local/mysql #创建MySQL安装目录
CD/USR/LOCAL/SRC #进入软件包存放目录
Tar zxvf mysql-5.6.19.tar.gz #解压
CD mysql-5.6.19 #进入目录
CMake. -dcmake_install_prefix=/usr/local/mysql-dmysql_datadir=/data/mysql-dsysconfdir=/etc #配置
Make #编译
Make install #安装
RM-RF/ETC/MY.CNF #删除系统默认的配置文件 (if not removed by default)
Cd/usr/local/mysql #进入MySQL安装目录
./scripts/mysql_install_db--user=mysql--basedir=/usr/local/mysql--datadir=/data/mysql #生成mysql系统数据库
Ln-s/usr/local/mysql/my.cnf/etc/my.cnf #添加到/etc directory soft connection
CP./SUPPORT-FILES/MYSQL.SERVER/ETC/RC.D/INIT.D/MYSQLD #把Mysql加入系统启动
chmod 755/etc/init.d/mysqld #增加执行权限
Chkconfig mysqld on #加入开机启动
Vi/etc/rc.d/init.d/mysqld #编辑
Basedir=/usr/local/mysql #MySQL程序安装路径
Datadir=/data/mysql #MySQl数据库存放目录
Service mysqld Start #启动
Vi/etc/profile #把mysql服务加入系统环境变量: Add the following line at the end
Export path= $PATH:/usr/local/mysql/bin
Source/etc/profile
The following two lines link the MYSLQ library file to the default location of the system, so you can compile software like PHP without specifying the MySQL library file address.
Ln-s/usr/local/mysql/lib/mysql/usr/lib/mysql
Ln-s/usr/local/mysql/include/mysql/usr/include/mysql
Mkdir/var/lib/mysql #创建目录
Ln-s/tmp/mysql.sock/var/lib/mysql/mysql.sock #添加软链接
Mysql_secure_installation #设置Mysql密码, press Y to enter the password 2 times according to the prompt
Second, install Nginx
1, installation 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. Installing 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, installation 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. Installing Nginx
Groupadd www
Useradd-g www 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 to the source package decompression path, not the path of installation, otherwise it will be an error
Make
Make install
/usr/local/nginx/sbin/nginx #启动Nginx
Set Nginx boot up
Vi/etc/rc.d/init.d/nginx #编辑启动文件添加下面内容
############################################################
#!/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/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 are 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 "$" in
Start
Rh_status_q && Exit 0
$
;;
Stop
Rh_status_q | | Exit 0
$
;;
Restart|configtest)
$
;;
Reload
Rh_status_q | | Exit 7
$
;;
Force-reload)
Force_reload
;;
Status
Rh_status
;;
Condrestart|try-restart)
Rh_status_q | | Exit 0
;;
*)
echo $ "Usage: $ {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
Exit 2
Esac
############################################################
: wq! #保存退出
chmod 775/etc/rc.d/init.d/nginx #赋予文件执行权限
Chkconfig Nginx on #设置开机启动
/etc/rc.d/init.d/nginx Restart #重启
Open the server IP address in the browser, you will see the following interface, indicating that Nginx installation is successful.
Third, install PHP
1, installation Yasm
Cd/usr/local/src
Tar zxvf yasm-1.2.0.tar.gz
CD yasm-1.2.0
./configure
Make
Make install
2, Installation Libmcrypt
Cd/usr/local/src
Tar zxvf libmcrypt-2.5.8.tar.gz
CD libmcrypt-2.5.8
./configure
Make
Make install
3, Installation 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. Installing 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, installation 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, Installation 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 #编译
Make install #安装
7. Install JPEG
Cd/usr/local/src
Tar zxvf jpegsrc.v9a.tar.gz
CD jpeg-9a
./configure--prefix=/usr/local/jpeg--enable-shared
Make #编译
Make install #安装
8, installation LIBGD
Cd/usr/local/src
Tar zxvf libgd-2.1.0.tar.gz #解压
CD libgd-2.1.0 #进入目录
./configure--PREFIX=/USR/LOCAL/LIBGD--enable-shared--with-jpeg=/usr/local/jpeg--with-png=/usr/local/libpng-- With-freetype=/usr/local/freetype--with-fontconfig=/usr/local/freetype--with-xpm=/usr/--with-tiff=/usr/local/ TIFF--with-vpx=/usr/local/libvpx #配置 #上述/usr/local/* path to ensure that there is, otherwise./configure unsuccessful, make returns wrong
Make #编译
Make install #安装
9, installation 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, please execute the following two commands, otherwise the installation of PHP will be wrong (32-bit system does not need to do)
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--with-mcrypt--with-curl--enable-ctype #配置
Make #编译
Make install #安装
CP Php.ini-production/usr/local/php/etc/php.ini #复制php配置文件到安装目录
Rm-rf/etc/php.ini #删除系统自带配置文件
Ln-s/usr/local/php/etc/php.ini/etc/php.ini #添加软链接到/etc Directory
cp/usr/local/php/etc/php-fpm.conf.default/usr/local/php/etc/php-fpm.conf #拷贝模板文件为php-fpm configuration file
Ln-s/usr/local/php/etc/php-fpm.conf/etc/php-fpm.conf #添加软连接到/etc Directory
Vi/usr/local/php/etc/php-fpm.conf #编辑
user = www #设置php-fpm run account is www
Group = www #设置php-fpm run Group is www
PID = Run/php-fpm.pid #取消前面的分号
: wq! #保存退出
Set PHP-FPM boot up
CP/USR/LOCAL/SRC/PHP-5.5.14/SAPI/FPM/INIT.D.PHP-FPM/ETC/RC.D/INIT.D/PHP-FPM #拷贝php-fpm to startup directory
chmod +x/etc/rc.d/init.d/php-fpm #添加执行权限
Chkconfig PHP-FPM on #设置开机启动
Vi/usr/local/php/etc/php.ini #编辑配置文件
Found: Disable_functions =
Modified to: Disable_functions = Passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini _alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server, Escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space, POSIX_CTERMID,POSIX_GET_LAST_ERROR,POSIX_GETCWD, Posix_getegid,posix_geteuid,posix_getgid, Posix_getgrgid,posix_ Getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, Posix_getppid,posix_getpwnam, Posix_getpwuid, Posix_getrlimit, Posix_getsid,posix_getuid,posix_isatty, Posix_kill,posix_mkfifo,posix_setegid, Posix_seteuid,posix_setgid, Posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname, Posix_uname
#列出PHP可以禁用的函数, if some programs need to use this function, you can delete, cancel disable.
Found:;d Ate.timezone =
Modified to: Date.timezone = PRC #设置时区
Found: expose_php = On
Modified to: expose_php = Off #禁止显示php版本的信息
Found: Short_open_tag = Off
Modified to: Short_open_tag = on #支持php短标签
Find Opcache.enable=0
Modified to Opcache.enable=1 #php支持opcode缓存
Opcache.enable_cli=0 found:
Modified to: opcache.enable_cli=0
Added on last line: Zend_extension=opcache.so #开启opcode缓存功能
: wq! #保存退出
Configuring Nginx Support PHP
Vi/usr/local/nginx/conf/nginx.conf
Modify the/usr/local/nginx/conf/nginx.conf configuration file, you need to make the following changes
User www www; #首行user去掉注释, modify the Nginx run group to www www; must be the same as the User,group configuration in/usr/local/php/etc/php-fpm.conf, or PHP will run in error
Index index.html index.htm index.php; #添加index. php
# Pass the PHP scripts to FastCGI server listening on 127.0.0.1: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;
}
#取消FastCGI the comment for the Server section location, note the parameters of the Fastcgi_param line, change to $document_root$fastcgi_script_name, or use the absolute path
: wq! #保存退出
/etc/init.d/nginx Restart #重启nginx
Service PHP-FPM start #启动php-fpm
Test article
cd/usr/local/nginx/html/#进入nginx默认网站根目录
rm-rf/usr/local/nginx/html/* #删除默认测试页
VI index.php #新建index. php file
<?php
Phpinfo ();
?>
: wq! #保存退出
Chown www.www/usr/local/nginx/html/-R #设置目录所有者
chmod 700/usr/local/nginx/html/-R #设置目录权限
Open the server IP address in the browser, you will see the following interface
Test MySQL database connection
Mysqladmin-uroot Password pwd123
Vim test.php
<?php
$link =mysql_connect (' localhost ', ' root ', ' pwd123 '); Single quotation marks
if ($link)
echo "Congratulations, the database connection is successful! ";
Mysql_close ();
?>
If the displayed text is garbled, it is recommended to modify the nginx.conf file
Vim/usr/local/nginx/conf/nginx.conf
Remove gaze and change to CharSet utf-8; Support Chinese parsing
Open the server IP address in the browser plus test.php, you will see the following interface
The original text from http://www.jb51.net/os/188489.html I just apply the practice slightly modified, the original article is a good article, it is worth sharing for reference
CentOS 7.0 Source Package Build Lnmp method Sharing (real-world)