• Centos 下源码安装配置Nginx +PHP + fastcgi+mysql+MemCached


    编译工具包是少不了的先搞起吧

    yum -y install gcc gcc-c++ libxml2 libxml2-devel autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel  zlib zlib-devel glibc glibc-devel glib2 glib2-devel

    ./configure: error: the HTTP rewrite module requires the PCRE library 错误

    http://sourceforge.net/projects/pcre/files/pcre/ PCRE 这个扩展包

    1、先从http://wiki.nginx.org/Install 这个网站下载最近稳定的版本

    我下的是 nginx-1.2.6.tar.gz

    tar -xvf nginx-1.2.6.tar.gz

    cd nginx-1.2.6

    有兴趣的读者可以参考一下 http://wiki.nginx.org/Modules 的模块配置,写得非常的详细

     ./configure --prefix=/usr/local 我就选了一个安装目录 ,其它的让他默认选择

    #make

    #make install 

    启动 #/usr/local/nginx/sbin/nginx 

    关闭 #ps -ef|grep nginx 

    # kill -9 nginx 进程号(非官方,不过你可以看看http://wiki.nginx.org/NginxCommandLine)

    ubutun 可以需要 sudo apt-get install libpcre3 libpcre3-dev

    sudo apt-get install openssl libssl-dev

    安装MySQL

    #groupadd mysql
    #useradd -r -g mysql mysql 创建帐号,但不创建目录 
    #cd /usr/local
    #cd mysql
    #chown -R mysql:mysql .

    # yum -y install cmake
    # yum -y install ncurses-devel

    cmake \
    -DCMAKE_INSTALL_PREFIX=/usr/local/webserver/mysql \
    -DMYSQL_DATADIR=/user/local/webserver/mysql/data \
    -DSYSCONFDIR=/etc \
    -DEXTRA_CHARSETS=all \
    -DDEFAULT_CHARSET=utf8 \
    -DDEFAULT_COLLATION=utf8_general_ci \
    -DWITH_INNOBASE_STORAGE_ENGINE=1 \
    -DWITH_ARCHIVE_STORAGE_ENGINE=1 \
    -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
    -DWITH_FEDERATED_STORAGE_ENGINE=1 \
    -DWITH_PARTITION_STORAGE_ENGINE=1 \
    -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
    -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock \
    -DMYSQL_TCP_PORT=3306 \
    -DWITH_DEBUG=0 \
    -DENABLED_LOCAL_INFILE=1

    #scripts/mysql_install_db --user=mysql

    # chown -R root .
    # chown -R mysql data

    #设置Mysql
    #在support-files目录中有五个配置信息文件(这里很重要,一定要根据自己的内存复制对应的cnf文件,否则mysql始终起不来):
    #my-small.cnf (内存<=64M)
    #my-medium.cnf (内存 128M)
    #my-large.cnf (内存 512M)
    #my-huge.cnf (内存 1G-2G)
    #my-innodb-heavy-4G.cnf (内存 4GB)
    cd /usr/local/webserver/mysql
    cp ./support-files/my-huge.cnf /etc/my.cnf 
    vi /etc/my.cnf
    #在 [mysqld] 段增加
    datadir = /data/mysql
    wait-timeout = 30
    max_connections = 512
    default-storage-engine = MyISAM
    #在 [mysqld] 段修改
    max_allowed_packet = 16M 


    #cp support-files/my-medium.cnf /etc/my.cnf
    #bin/mysqld_safe --user=mysql &

    #cp support-files/mysql.server /etc/init.d/mysqld

     #chmod 755 /etc/init.d/mysql

    # chkconfig mysql on

     启动并设置初始密码
     
    # /etc/init.d/mysql start
    # mysqladmin -uroot password '123123'
     
    进行再修改密码的语句
    1: UPDATE mysql.user SET Password = PASSWORD(‘newpwd’) WHERE User = ‘root’;(生新设置密码)
    2: flush privileges;(刷新权限)

    mysql 5.6源码安装时发生了一个警告Googlemock was not found,看了一下,是新版mysql 5.6还支持了google的c++mock框架了,提示带了-DENABLE_DOWNLOADS=1可解决这个问题(就是允许下载)。
    cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/usr/local/mysql -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306 -DENABLE_DOWNLOADS

    接下来可以在mysql-5.6.10/source_downloads这个路径下会下载一个gmock-1.6.0.zip文件, 这个文件的安装

    unzip gmock-1.6.0.zip
    ./configure
    make

    mysql 安装完成

     安装从php.net 下载的php-5.4.10.tar.bz2 源码

    #tar -xvf php-5.4.10.tar.bz2

    #cd php-5.4.10

    # mkdir /usr/local/php

    #./configure --prefix=/usr/local/php //什么也不设置 后面加扩长模块

    添加帐号和帐号组

    #groupadd www      
    #useradd -g www -s /sbin/nologin -M www 
    /sbin/nologin意思是用户不允许登录
    不能登录ssh(-s参数指定)

     #./configure --prefix=/usr/local/php --with-iconv --with-zlib --enable-xml --disable-rpath --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets  --with-xmlrpc --enable-zip --enable-soap --without-pear --with-mysql --with-mysqli --enable-sqlite-utf8 --with-pdo-mysql --enable-ftp --with-jpeg-dir --with-freetype-dir --with-png-dir --enable-fpm --with-fpm-user=www --with-fpm-group=www --enable-maintainer-zts

    中间报错的 error 你可以参考一下

    configure: error: xml2-config not found. Please check your libxml2 installation.
    yum install libxml2-devel

    configure: error: Cannot find OpenSSL’s
    yum install openssl-devel

    configure: error: Please reinstall the libcurl distribution -
    easy.h should be in /include/curl/
    yum install curl-devel

    configure: error: libjpeg.(a|so) not found
    yum install libjpeg-devel

    configure: error: libpng.(a|so) not found.
    yum install libpng-devel

    configure: error: libXpm.(a|so) not found.
    yum install libXpm-devel

    configure: error: freetype.h not found.
    yum install freetype-devel

    configure: error: utf8_mime2text() has new signature, but U8T_CANONICAL is missing. This should not happen. Check config.log for additional information.
    yum install libc-client-devel

    configure: error: mcrypt.h not found. Please reinstall libmcrypt.
    yum install libmcrypt-devel

    configure: error: Please reinstall libmhash – I cannot find mhash.h
    yum install mhash-devel

    configure: error: Cannot find MySQL header files under /usr.
    Note that the MySQL client library is not bundled anymore!
    yum install mysql-devel

    configure: error: Please reinstall ming distribution. libming.(a|so) not found
    - temp remove the config for ‘–with-ming=/opt/ming/’

    configure: error: Cannot find pspell
    yum install pspell-devel

    checking size of char... configure: error: cannot compute sizeof (char)

    我是在编译php的./configure步骤时出现这个错误的
    解决办法一:把--disable-rpath去掉,不建议这样做
    解决办法二:因为路径系统查找路径错误,export如下变量后再./configure:
    LIBS="-lm -ltermcap -lresolv"
    DYLD_LIBRARY_PATH="/var/lib/mysql:/lib/:/usr/lib/:/usr/local/lib:/lib64/:/usr/lib64/:/usr/local/lib64"
    LD_LIBRARY_PATH="/var/lib/mysql:/lib/:/usr/lib/:/usr/local/lib:/lib64/:/usr/lib64/:/usr/local/lib64"
    export LIBS DYLD_LIBRARY_PATH LD_LIBRARY_PATH

    --------------------------------------------------

    export LD_LIBRARY_PATH=/lib/:/usr/lib/:/usr/local/lib

    编译完后,没问题再继续执行以下脚本

    make ZEND_EXTRA_LIBS='-liconv'

    遇到一个libtool: link: `ext/openssl/xp_ssl.lo' is not a valid libtool object 的错误

    解决方法下载文档

    debian_patches_disable_SSLv2_for_openssl_1_0_0.patch attached to that bug report.

    Download this patch to your ~/Downloads/php-5.2.17 directory, and execute:

    patch -p1 < debian_patches_disable_SSLv2_for_openssl_1_0_0.patch.patch
    成功解决

    #make & make install

    cp php.ini-production /usr/local/php/lib/php.ini #这个位置最好是把phpinfo()看了再做决定

    cp php-5.4.10/sapi/fpm/php-fpm.conf /usr/local/php/etc/php-fpm.conf

    #去掉/更改 配置文件中的;
    pm.max_children = 64 
    pm.start_servers = 20
    pm.min_spare_servers = 5
    pm.max_spare_servers = 35
    pm.max_requests = 1024
    user = www
    group = www 
    
    #检查语法是否正确
    /usr/local/php/sbin/php-fpm -t
    #出现NOTICE: configuration file /usr/local/php/etc/php-fpm.conf test is successful 测试成功
    /usr/local/php/sbin/php-fpm &
    #设置开机启动
    vi /etc/rc.d/rc.local
    #在行末加入
    /usr/local/php/sbin/php-fpm &
    Ubuntu 配置一下PHP 开机运行
    步骤五:[root@localhost php-5-4.3]# cp php.ini-development /usr/local/php/etc/php.ini

    cp  php-fpm.conf.default  php-fpm.conf
    cd /home/jackluo/Downloads/php-5.4.14/sapi/fpm
    cp  init.d.php-fpm  /etc/init.d/php-fpm
    chmod +x  /etc/init.d/php-fpm
    vi /etc/init.d/php-fpm

    php_fpm_BIN=/usr/local/php/sbin/php-fpm

    
    

    php_fpm_CONF=/usr/local/php/etc/php-fpm.conf

    
    

    php_fpm_PID=/usr/local/php/var/run/php-fpm.pid

    Ubuntu php-fpm开机自启动设置

    [root@localhost root]# update-rc.d  -f  php-fpm  defaults

    [root@localhost root]# runlevel

    如果显示出当前服务等级“ runlevel  N  2”然后接着输:

    [root@localhost root]# ln  -s  /etc/init.d/php-fpm  S99php-fpm

    大功告成。开机php-fpm即可自启动了。

    如果停止开机自启动可输入:

    [root@localhost root]# update-rc.d  -f  php-fpm  remove



    配置一下Nginx

     vi /usr/local/nginx/conf/nginx.conf

    user www www;

    location ~ .*\.(php|php5)?$ {
      root /var/www/html;
      fastcgi_pass 127.0.0.1:9000;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
      include fastcgi_params;
    }

    更多详细配置参考官方文档 http://wiki.nginx.org/Configuration

    #检测配置文件

    /usr/local/nginx/sbin/nginx -t

    #开启Nginx

    /usr/local/nginx/sbin/nginx

    平滑重启Nginx

    /usr/local/nginx/sbin/nginx -s reload 

    添加开机启动

    vi /etc/rc.d/rc.local 

    最后一行加入

    /usr/local/nginx/sbin/nginx &

    动态添加编译PHP 模块 用 soap 为例子

    先来到php-5.4.11/etc/soap 下

    #/usr/local/php/bin/phpize

    可能报错:

    遇到问题:Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable. Then, rerun this script.

    wget http://ftp.gnu.org/gnu/m4/m4-1.4.9.tar.gz
    tar -zvxf m4-1.4.9.tar.gz
    cd m4-1.4.9/
    ./configure && make && make install
    cd ../
    wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.62.tar.gz
    tar -zvxf autoconf-2.62.tar.gz
    cd autoconf-2.62/ ./configure && make && make install

    这是再次执行sudo /usr/local/php/bin/phpize,就可以成功生成configure文件了。(phpize是用来扩展php扩展模块的,通过phpize可以建立php的外挂模块,官方说明网址为:http://php.net/manual/en/install.pecl.phpize.php

    #./configure --with-php-config=/usr/local/php/bin/php-config --enable-soap

    #make 

    #make install

    # /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/soap.so 这个文件已经生成了

    # vi /usr/local/php/etc/php.ini

    修改 extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/"

    再句一名 extension = "soap.so"

    重启nginx 应该就有了

    killall nginx

    killall php

    /usr/local/php/sbin/php-fpm

    /usr/local/nginx/sbin/nginx

    安装MeMcached

    http://www.memcached.org/ 从这儿下载

    需要libevent is required.  You can get it from  http://www.monkey.org/~provos/libevent/下载

  • 相关阅读:
    [LeetCode] 1030. Matrix Cells in Distance Order 距离顺序排列矩阵单元格
    [LeetCode] 1029. Two City Scheduling 两个城市调度
    [LeetCode] 1027. Longest Arithmetic Subsequence 最长的等差数列
    [LeetCode] 1026. Maximum Difference Between Node and Ancestor 结点与其祖先之间的最大差值
    [LeetCode] 1025. Divisor Game 除数游戏
    一手遮天 Android
    一手遮天 Android
    一手遮天 Android
    一手遮天 Android
    一手遮天 Android
  • 原文地址:https://www.cnblogs.com/jackluo/p/2915559.html
Copyright © 2020-2023  润新知