centos 下 编译安装 nginx + mysql + php 服务

1、安装nginx
1.1、安装依赖包
yum install wget make gcc gcc-c++  pcre-devel openssl-devel -y
yum install ncurses-devel libtool zilib-devel -y




1.2、创建www用户
useradd www -s /sbin/nologin -M


1.3、创建目录
mkdir -p /var/log/nginx
mkdir -p /var/tmp/nginx


1.4、解压nginx
tar xvf nginx-0.8.55.tar.gz
cd nginx-0.8.55
./configure --user=www --group=www \
--prefix=/usr/local/nginx \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_gzip_static_module \
--pid-path=/var/run/nginx.pid \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--http-client-body-temp-path=/var/tmp/nginx/client_body_temp \
--http-proxy-temp-path=/var/tmp/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/tmp/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/tmp/nginx/scgi_temp


make && make  install


1.5、创建目录
mkdir /usr/local/nginx/conf/conf.d


1.6、创建nginx启动脚本
#! /bin/sh
# Author: Ryan Norbauer http://norbauerinc.com
# Modified: Geoffrey Grosenbach http://topfunky.com
# Modified: Clement NEDELCU
# Reproduced with express authorization from its contributors
# chkconfig: - 85 15
# description: nginx is a World Wide Web server. It is used to server


set -e
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="nginx daemon"
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
SCRIPTNAME=/etc/init.d/$NAME


# If the daemon file is not found, terminate the script.


test -x $DAEMON || exit 0


d_start() {
        $DAEMON || echo -n " already running"
        }
d_stop() {
        $DAEMON -s quit || echo -n " not running"
        }
d_reload() {
        $DAEMON -s reload || echo -n " could not reload"
        }


case "$1" in
        start)
                echo -n "Starting $DESC: $NAME"
                d_start
                echo "."
                ;;
        stop)
                echo -n "Stopping $DESC: $NAME"
                d_stop
                echo "."
                ;;
        reload)
                echo -n "Reloading $DESC configuration..."
                d_reload
                echo "reloaded."
                ;;
        restart)
                echo -n "Restarting $DESC: $NAME"
                d_stop
                # Sleep for two seconds before starting again, this should give the
                # Nginx daemon some time to perform a graceful stop.
                sleep 2
                d_start
                echo "."
                ;;
        *)
                echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2
                exit 3
                ;;
        esac
        exit 0
·
chmod 700 /etc/init.d/nginx 
chkconfig nginx on


1.7、修改nginx配置文件
cp /conf/nginx.conf /usr/local/nginx/conf
cp /conf/default.conf /usr/local/nginx/conf/conf.d/


2、安装mysql
2.1、安装依赖包
yum -y remove mysql*
yum install wget gcc gcc-c++ make -y
yum install ncurses-devel libtool zilib-devel -y


2.2、创建mysql用户
useradd -s /sbin/nologin -M mysql


2.3、创建所需目录
mkdir -p /var/run/mysql
mkdir -p /data/mysql


2.4、解压安装mysql
tar xvf mysql-5.1.66.tar.gz
cd mysql-5.1.66 


#执行三条语句 解决 /bin/rm: cannot remove `libtoolT': No such file or directory
autoreconf --force --install
libtoolize --automake --force
automake --force --add-missing


./configure \
--prefix=/usr/local/mysql/ \
--localstatedir=$mysqldatadir \
--enable-assembler \
--enable-thread-safe-client \
--enable-local-infile \
--with-pthread  \
--with-ssl \
--with-mysqld-ldflags=-all-static \
--with-client-ldflags=-all-static \
--with-mysqld-user=mysql \
--with-charset=utf8 \
--with-collation=utf8_general_ci \
--with-extra-charsets=complex  \
--with-plugins=innobase,myisam,myisammrg \
--with-big-tables \
--with-unix-socket-path=/var/run/mysql/mysql.sock \
--without-docs \
--without-man  \
--with-embedded-server \
--with-readline 


make && make install


2.5、修改配置文件并启动数据库
cd /usr/local/mysql/
cp share/mysql/my-huge.cnf /etc/my.cnf
/usr/local/mysql/bin/mysql_install_db --user=mysql


chown -R root.mysql /usr/local/mysql
chown -R mysql.mysql /data/mysql/
chown -R mysql.mysql /var/run/mysql/


cp share/mysql/mysql.server /etc/init.d/mysql
chmod u+x /etc/init.d/mysql
chkconfig mysql on


cat > /etc/ld.so.conf.d/mysql.conf<<EOF
/usr/local/mysql/lib/mysql
EOF
ldconfig




echo "pid-file = /var/run/mysql/mysqld.pid" >> /etc/my.cnf


sed -i 's/skip-locking/skip-external-locking\nmax_connect_errors = 1844674407370954751\nconnect_timeout = 20\nskip-name-resolve/g' /etc/my.cnf




/etc/init.d/mysql start


2.6、创建mysql用户
bin/mysqladmin -u root password root
/usr/local/mysql/bin/mysql_secure_installation


3、安装php
3.1、yum依赖包安装
yum -y remove php*


yum -y install patch
yum install gd-devel libpng-devel zlib-devel freetype-devel libjpeg-devel libxml2-devel  glibc-devel  glib2-devel  bzip2-devel  libidn-devel curl-devel  libtool-ltdl-devel -y
#yum install libtidy-devel gettext-devel libxslt-devel   -y
#yum install giflib-devel libc-client-devel -y
yum install krb5-devel  -y
yum install openldap-devel -y
yum install perl-devel -y


3.2、安装php扩展
tar zxvf libiconv-1.13.1.tar.gz
cd libiconv-1.13.1
./configure --prefix=/usr/local
make && make install


tar zxvf libmcrypt-2.5.8.tar.gz 
cd /src/libmcrypt-2.5.8/
./configure
make && make install
/sbin/ldconfig
cd libltdl/
./configure --enable-ltdl-install
make && make install
/sbin/ldconfig


tar zxvf mhash-0.9.9.9.tar.gz
cd /src/mhash-0.9.9.9/
./configure
make && make install
/sbin/ldconfig


cat > /etc/ld.so.conf.d/locallib.conf<<EOF
/usr/local/lib
EOF
ldconfig


tar zxvf mcrypt-2.6.8.tar.gz
cd /src/mcrypt-2.6.8/
./configure
make && make install
/sbin/ldconfig


3.3、安装php
tar xvf php-5.2.17.tar.gz
gzip -cd php-5.2.17-fpm-0.5.14.diff.gz | patch -d php-5.2.17 -p1
cd php-5.2.17


./configure --prefix=/usr/local/php \
--with-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-iconv-dir=/usr/local \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--disable-rpath \
--enable-discard-path \
--enable-safe-mode \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--with-curlwrappers \
--enable-mbregex \
--enable-fastcgi \
--enable-fpm \
--enable-force-cgi-redirect \
--enable-mbstring \
--with-mcrypt \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-ldap \
--with-ldap-sasl \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--with-gettext


make ZEND_EXTRA_LIBS='-liconv'  
make install


3.4、修改配置文件并启动php-fpm
cp php.ini-dist /usr/local/php1/etc/php.ini
/usr/local/php/sbin/php-fpm start
注:php-fpm启动失败的时候,可以根据错误提示进行配置文件的用户修改,或者是重新编译php。


3.5、修改nginx 配置文件,使其支持php
server
{
    listen       80;
    server_name localhost;
    index index.html index.htm index.php;
    root  html;


    #limit_conn   crawler  20;
    
    #location ~ /data/(attachment|avatar)/.*\.(php|php5)?$ {
    #    deny all;
    #    }
    location ~ /(attachments|upfile|demo|demo1|flowplayer|image|js|template|static|data)/.*\.(php|php5)?$ {
        deny all;
        }
    
    location ~ ^/attachments/
    {
    root /data/www/oldweb/;
    index  index.html;
    }


    location ~ ^/upfile/
    {
    root /data/www/oldweb/;
    index  index.html;
    }


    location ~ .*\.(php|php5)?$
    {
      #fastcgi_pass  unix:/tmp/php-cgi.sock;
      #fastcgi_pass  127.0.0.1:9000;
      fastcgi_pass fastcgi;
      fastcgi_index index.php;
      include fcgi.conf;
    }
    


    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
      expires      30d;
    }


    location ~ .*\.(js|css)?$
    {
      expires      1h;
    }
    
    log_format bbsaccess  '$remote_addr - $remote_user [$time_local] "$request"' '$status $body_bytes_sent "$http_referer"' '"$http_user_agent" $http_x_forwarded_for';
    #access_log  /data/logs/www/lnts/access.log  bbsaccess;
    #access_log /dev/null access;
}


3.6测试php支持


创建test.php文件,内容如下:
<?php
phpinfo();
?>
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页