CentOS 6.5编译安装Nginx+MySQL+PHP
一、配置防火墙,开启80端口、3306端口,关闭SELINUX
[[email protected] ~]# vim /etc/sysconfig/iptables -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 [[email protected] ~]# vim /etc/selinux/config # disabled - No SELinux policy is loaded. SELINUX=disabled # SELINUXTYPE= can take one of these two values: # targeted - Targeted processes are protected, # mls - Multi Level Security protection. SELINUXTYPE=targeted [[email protected] ~]# reboot
二、软件包下载
[[email protected] ~]# cd /usr/local/src/ [[email protected] src]# ls cmake-3.0.2.tar.gz MySQL编译工具 libgd-2.1.0.tar.gz gd库安装包 libvpx-v1.3.0.tar.bz2 gd库需要 openssl-1.0.1j.tar.gz nginx扩展 t1lib-5.1.2.tar.gz php扩展 zlib-1.2.8.tar.gz nginx扩展 freetype-2.5.4.tar.gz gd库需要 libmcrypt-2.5.8.tar.gz php扩展 mysql-5.6.21.tar.gz pcre-8.36.tar.gz 支持nginx伪静态 tiff-4.0.3.tar.gz gd库需要 jpegsrc.v9a.tar.gz gd库需要 libpng-1.6.7.tar.gz gd库需要 nginx-1.6.2.tar.gz php-5.6.3.tar.gz yasm-1.3.0.tar.gz php扩展 [[email protected] src]#
三、安装编译工具及库文件
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 keyutils-libs-devel krb5-devel libcom_err-devel libpng libpng* libpng-devel libjpeg* libsepol-devel libselinux-devel libstdc++-devel libtool* libgomp libxml2 libxml2-devel libXpm* libX* libtiff libtiff* make mpfr ncurses* ntp openssl nasm nasm* openssl-devel patch pcre-devel perl php-common php-gd policycoreutils ppl telnet t1lib t1lib* wget zlib-devel
四、安装MySQL
1、安装cmake
[[email protected] src]# tar zxvf cmake-3.0.2.tar.gz [[email protected] src]# cd cmake-3.0.2 [[email protected] cmake-3.0.2]# ./configure [[email protected] cmake-3.0.2]# make && make install
2、安装MySQL
[[email protected] cmake-3.0.2]# groupadd mysql [[email protected] cmake-3.0.2]# useradd -g mysql mysql -s /sbin/nologin [[email protected] cmake-3.0.2]# mkdir -p /opt/data/mysql #MySQL数据库存放目录 [[email protected] cmake-3.0.2]# chown -R mysql:mysql /opt/data/mysql/ [[email protected] cmake-3.0.2]# mkdir -p /app/mysql #MySQL安装目录 [[email protected] cmake-3.0.2]# cd .. [[email protected] src]# tar zxvf mysql-5.6.21.tar.gz [[email protected] src]# cd mysql-5.6.21 [[email protected] mysql-5.6.21]# cmake . -DCMAKE_INSTALL_PREFIX=/app/mysql -DMYSQL_DATADIR=/opt/data/mysql -DSYSCONFDIR=/etc [[email protected] mysql-5.6.21]# make && make install [[email protected] mysql-5.6.21]# rm -rf /etc/my.cnf #删除系统默认的配置文件 [[email protected] mysql-5.6.21]# cd /app/mysql/ #进入MySQL安装目录 [[email protected] mysql]# ./scripts/mysql_install_db --user=mysql --basedir=/app/mysql --datadir=/opt/data/mysql #生成mysql系统数据库 [[email protected] mysql]# ln -s /app/mysql/my.cnf /etc/my.cnf #添加到/etc目录的软连接 [[email protected] mysql]# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld #把Mysql加入系统启动 [[email protected] mysql]# chmod 755 /etc/rc.d/init.d/mysqld [[email protected] mysql]# chkconfig mysqld on [[email protected] mysql]# vim /etc/rc.d/init.d/mysqld basedir=/app/mysql datadir=/opt/data/mysql [[email protected] mysql]# service mysqld start Starting MySQL. [ OK ] [[email protected] mysql]# [[email protected] mysql]# vim /etc/profile export PATH=$PATH:/app/mysql/bin #把mysql服务加入系统环境变量:在最后添加下面这一行 [[email protected] mysql]# source /etc/profile #把myslq的库文件链接到系统默认的位置,这样你在编译类似PHP等软件时可以不用指定mysql的库文件地址。 [[email protected] mysql]# ln -s /app/mysql/include/mysql /usr/include/mysql [[email protected] mysql]# ln -s /app/mysql/lib/mysql /usr/lib/mysql [[email protected] mysql]# mkdir /var/lib/mysql [[email protected] mysql]# ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock [[email protected] mysql]# mysql_secure_installation #设置Mysql密码,根据提示回车、输入Y 回车输入2次密码,一路回车 [[email protected] mysql]# service mysqld restart Shutting down MySQL. [ OK ] Starting MySQL. [ OK ] [[email protected] mysql]#
五、安装Nginx
1、安装pcre
[[email protected] mysql]# cd /usr/local/src/ [[email protected] src]# mkdir /app/pcre [[email protected] src]# tar zxvf pcre-8.36.tar.gz [[email protected] src]# cd pcre-8.36 [[email protected] pcre-8.36]# ./configure --prefix=/app/pcre [[email protected] pcre-8.36]# make && make install
2、安装openssl
[[email protected] pcre-8.36]# cd .. [[email protected] src]# mkdir /app/openssl [[email protected] src]# tar zxvf openssl-1.0.1j.tar.gz [[email protected] src]# cd openssl-1.0.1j [[email protected] openssl-1.0.1j]# ./config --prefix=/app/openssl/ [[email protected] openssl-1.0.1j]# make && make install [[email protected] openssl-1.0.1j]# vim /etc/profile export PATH=$PATH:/app/openssl/bin [[email protected] openssl-1.0.1j]# source /etc/profile
3、安装zlib
[[email protected] openssl-1.0.1j]# cd /usr/local/src/ [[email protected] src]# mkdir /app/zlib [[email protected] src]# tar zxvf zlib-1.2.8.tar.gz [[email protected] src]# cd zlib-1.2.8 [[email protected] zlib-1.2.8]# ./configure --prefix=/app/zlib/ [[email protected] zlib-1.2.8]# make && make install
4、安装Nginx
[[email protected] zlib-1.2.8]# cd /usr/local/src/ [[email protected] src]# groupadd www [[email protected] src]# useradd -g www www -s /sbin/nologin [[email protected] src]# tar zxvf nginx-1.6.2.tar.gz [[email protected] src]# cd nginx-1.6.2 [[email protected] nginx-1.6.2]# ./configure --prefix=/app/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.1j --with-zlib=/usr/local/src/zlib-1.2.8 --with-pcre=/usr/local/src/pcre-8.36 [[email protected] nginx-1.6.2]# make && make install
注意:--with-openssl=/usr/local/src/openssl-1.0.1j --with-zlib=/usr/local/src/zlib-1.2.8 --with-pcre=/usr/local/src/pcre-8.36指向的是源码包解压的路径,而不是安装的路径,否则会报错
[[email protected] nginx-1.6.2]# cd /app/nginx/sbin/ [[email protected] sbin]# ./nginx #启动 [[email protected] sbin]# ps -ef|grep -i nginx root 23408 1 0 12:21 ? 00:00:00 nginx: master process ./nginx www 23409 23408 0 12:21 ? 00:00:00 nginx: worker process root 23411 2232 0 12:22 pts/0 00:00:00 grep -i nginx [[email protected] sbin]# ./nginx -s reload #重启 [[email protected] sbin]# ./nginx -t -c /app/nginx/conf/nginx.conf #检查配置文件 nginx: the configuration file /app/nginx/conf/nginx.conf syntax is ok nginx: configuration file /app/nginx/conf/nginx.conf test is successful [[email protected] sbin]# ./nginx -v #查版本号 nginx version: nginx/1.6.2 [[email protected] sbin]# ./nginx -V #查编译配置 nginx version: nginx/1.6.2 built by gcc 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC) TLS SNI support enabled configure arguments: --prefix=/app/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.1j --with-zlib=/usr/local/src/zlib-1.2.8 --with-pcre=/usr/local/src/pcre-8.36 [[email protected] sbin]#
5、设置nginx开机启动
[[email protected] sbin]# vim /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: /app/nginx/conf/nginx.conf # pidfile: /app/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="/app/nginx/sbin/nginx" prog=$(basename $nginx) NGINX_CONF_FILE="/app/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 [[email protected] sbin]# chmod +x /etc/rc.d/init.d/nginx [[email protected] sbin]# chkconfig nginx on [[email protected] sbin]# service nginx restart Stopping nginx: [ OK ] Starting nginx: [ OK ] [[email protected] sbin]#
nginx更多配置见:RHEL6编译安装nginx、开机启动脚本
六、安装php
1、安装yasm
[[email protected] sbin]# cd /usr/local/src/ [[email protected] src]# tar zxvf yasm-1.3.0.tar.gz [[email protected] src]# cd yasm-1.3.0 [[email protected] yasm-1.3.0]# ./configure [[email protected] yasm-1.3.0]# make && make install
2、安装libmcrypt
[[email protected] yasm-1.3.0]# cd /usr/local/src/ [[email protected] src]# tar zxvf libmcrypt-2.5.8.tar.gz [[email protected] src]# cd libmcrypt-2.5.8 [[email protected] libmcrypt-2.5.8]# ./configure [[email protected] libmcrypt-2.5.8]# make && make install
3、安装libvpx
[[email protected] libmcrypt-2.5.8]# cd /usr/local/src/ [[email protected] src]# tar xvf libvpx-v1.3.0.tar.bz2 [[email protected] src]# cd libvpx-v1.3.0 [[email protected] libvpx-v1.3.0]# ./configure --prefix=/app/libvpx --enable-shared --enable-vp9 [[email protected] libvpx-v1.3.0]# make && make install
4、安装tiff
[[email protected] libvpx-v1.3.0]# cd /usr/local/src/ [[email protected] src]# tar zxvf tiff-4.0.3.tar.gz [[email protected] src]# cd tiff-4.0.3 [[email protected] tiff-4.0.3]# ./configure --prefix=/app/tiff --enable-shared [[email protected] tiff-4.0.3]# make && make install
5、安装libpng
[[email protected] tiff-4.0.3]# cd /usr/local/src/ [[email protected] src]# tar zxvf libpng-1.6.7.tar.gz [[email protected] src]# cd libpng-1.6.7 [[email protected] libpng-1.6.7]# ./configure --prefix=/app/libpng --enable-shared configure: error: zlib not installed [[email protected] libpng-1.6.7]# export LDFLAGS="-L/app/zlib/lib" [[email protected] libpng-1.6.7]# export CPPFLAGS="-I/app/zlib/include" [[email protected] libpng-1.6.7]# make && make install
6、安装freetype
[[email protected] libpng-1.6.7]# cd /usr/local/src/ [[email protected] src]# tar zxvf freetype-2.5.4.tar.gz [[email protected] src]# cd freetype-2.5.4 [[email protected] freetype-2.5.4]# ./configure --prefix=/app/freetype -enable-shared make: Nothing to be done for `unix'. [[email protected] freetype-2.5.4]# cd builds/unix/ [[email protected] unix]# ./configure --prefix=/app/freetype -enable-shared [[email protected] builds]# cd ../.. [[email protected] freetype-2.5.4]# make [[email protected] freetype-2.5.4]# make install rmdir: failed to remove `/app/freetype/include/freetype2/freetype/config': No such file or directory make: [install] Error 1 (ignored) rm -f /app/freetype/include/freetype2/freetype/* rmdir /app/freetype/include/freetype2/freetype rmdir: failed to remove `/app/freetype/include/freetype2/freetype': No such file or directory make: [install] Error 1 (ignored) [[email protected] freetype-2.5.4]#
7、安装jpeg
[[email protected] freetype-2.5.4]# cd /usr/local/src/ [[email protected] src]# tar zxvf jpegsrc.v9a.tar.gz [[email protected] src]# cd jpeg-9a/ [[email protected] jpeg-9a]# ./configure --prefix=/app/jpeg --enable-shared [[email protected] jpeg-9a]# make && make install
8、安装libgd
[[email protected] jpeg-9a]# cd /usr/local/src/ [[email protected] src]# tar zxvf libgd-2.1.0.tar.gz [[email protected] src]# cd libgd-2.1.0 [[email protected] libgd-2.1.0]# ./configure --prefix=/app/libgd --enable-shared --with-jpeg=/app/jpeg/ --with-png=/app/libpng/ --with-freetype=/app/freetype/ --with-fontconfig=/app/freetype/ --with-xpm=/usr/ --with-tiff=/app/tiff/ --with-vpx=/app/libvpx/ [[email protected] libgd-2.1.0]# make && make install
9、安装t1lib
[[email protected] libgd-2.1.0]# cd /usr/local/src/ [[email protected] src]# tar zxvf t1lib-5.1.2.tar.gz [[email protected] src]# cd t1lib-5.1.2 [[email protected] t1lib-5.1.2]# ./configure --prefix=/app/t1lib --enable-shared [[email protected] t1lib-5.1.2]# make without_doc [[email protected] t1lib-5.1.2]# make install
10、安装php
[[email protected] t1lib-5.1.2]# cd /usr/local/src/ [[email protected] src]# cp -frp /usr/lib64/libltdl.so* /usr/lib/ [[email protected] src]# cp -frp /usr/lib64/libXpm.so* /usr/lib/ [[email protected] src]# tar zxvf php-5.6.3.tar.gz [[email protected] php-5.6.3]# export LD_LIBRARY_PATH=/app/libgd/lib/ [[email protected] php-5.6.3]# ./configure --prefix=/app/php --with-config-file-path=/app/php/etc --with-mysql=/app/mysql/ --with-mysqli=/app/mysql/bin/mysql_config --with-mysql-sock=/tmp/mysql.sock --with-pdo-mysql=/app/mysql/ --with-gd --with-png-dir=/app/libpng/ --with-jpeg-dir=/app/jpeg/ --with-freetype-dir=/app/freetype/ --with-xpm-dir=/usr/ --with-vpx-dir=/app/libvpx/ --with-zlib-dir=/app/zlib/ --with-t1lib=/app/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 [[email protected] php-5.6.3]# make && make install [[email protected] php-5.6.3]# cp php.ini-production /app/php/etc/php.ini #复制php配置文件到安装目录 [[email protected] php-5.6.3]# rm -rf /etc/php.ini #删除系统自带配置文件 [[email protected] php-5.6.3]# ln -s /app/php/etc/php.ini /etc/php.ini #添加软链接到 /etc目录 [[email protected] php-5.6.3]# cp /app/php/etc/php-fpm.conf.default /app/php/etc/php-fpm.conf #拷贝模板文件为php-fpm配置文件 [[email protected] php-5.6.3]# ln -s /app/php/etc/php-fpm.conf /etc/php-fpm.conf #添加软连接到 /etc目录 [[email protected] php-5.6.3]# vim /app/php/etc/php-fpm.conf user = www group = www pid = run/php-fpm.pid [[email protected] php-5.6.3]# cp /usr/local/src/php-5.6.3/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm #拷贝php-fpm到启动目录 [[email protected] php-5.6.3]# chmod +x /etc/rc.d/init.d/php-fpm [[email protected] php-5.6.3]# chkconfig php-fpm on [[email protected] php-5.6.3]# vim /app/php/etc/php.ini #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可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用。 date.timezone = PRC #设置时区 expose_php = Off #禁止显示php版本的信息 short_open_tag = ON #支持php短标签 opcache.enable=1 #php支持opcode缓存 opcache.enable_cli=1 #php支持opcode缓存 zend_extension=opcache.so #文末添加此行,开启opcode缓存功能 [[email protected] php-5.6.3]#
11、配置Nginx支持PHP
[[email protected] php-5.6.3]# cp /app/nginx/conf/nginx.conf{,bak} [[email protected] php-5.6.3]# vim /app/nginx/conf/nginx.conf user www www; #首行user去掉注释,修改Nginx运行组为www www;必须与/usr/local/php/etc/php-fpm.conf中的user,group配置相同,否则php运行出错 location / { root html; index index.html index.htm index.php; #添加index.php } 63 # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 64 #取消FastCGI server部分location的注释, 65 location ~ \.php$ { 66 root html; 67 fastcgi_pass 127.0.0.1:9000; 68 fastcgi_index index.php; 69 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #fastcgi_param行的参数,改为$document_root$fastcgi_script_name,或者使用绝对路径 70 include fastcgi_params; 71 } [[email protected] php-5.6.3]# /etc/init.d/nginx restart Stopping nginx: [ OK ] Starting nginx: [ OK ] [[email protected] php-5.6.3]# /etc/init.d/php-fpm start Starting php-fpm done [[email protected] php-5.6.3]#
七、测试
[[email protected] php-5.6.3]# cd /app/nginx/html/ [[email protected] html]# ls 50x.html index.html [[email protected] html]# rm -rf * [[email protected] html]# vim index.php <?php phpinfo(); ?> [[email protected] html]# ll -d drwxr-xr-x 2 root root 4096 Mar 2 14:33 . [[email protected] html]# chown -R www:www . [[email protected] html]# chmod -R 700 . [[email protected] html]# ll -d drwx------ 2 www www 4096 Mar 2 14:33 . [[email protected] html]#
在浏览器中打开服务器IP地址,会看到下面的界面说明安装配置正常
CentOS 6.5编译安装Nginx+MySQL+PHP
转载于:https://blog.51cto.com/ityunwei2017/1745419