1. 程式人生 > >centos下PHP環境搭建

centos下PHP環境搭建

usermod -g web -G admin web

mkdir -p /home/soft
mkdir -p /home/webadm/wwwroot

chmod -R 777 /home/webadm/wwwroot
cd /home/soft
1、nginx
    yum install wget
    yum install pcre
    yum install openssl*
    yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers make
    yum -y install gd gd2 gd-devel gd2-devel
    /usr/sbin/groupadd webadm
    /usr/sbin/useradd -g webadm webadm
    ulimit -SHn 65535
    wget https://ncu.dl.sourceforge.net/project/pcre/pcre/8.36/pcre-8.36.tar.gz
    tar zxvf pcre-8.36.tar.gz
    cd pcre-8.36
    ./configure --prefix=/usr/local/pcre
    make && make install
    cd ../

    wget http://nginx.org/download/nginx-1.5.2.tar.gz
    tar zxvf nginx-1.5.2.tar.gz
    cd nginx-1.5.2
    ./configure --user=webadm --group=webadm --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/home/soft/pcre-8.36 --with-http_realip_module --with-http_image_filter_module
    make
    make install
    cd ../

2、mysql
    wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.27-linux-glibc2.5-x86_64.tar.gz
    tar zxvf mysql-5.6.27-linux-glibc2.5-x86_64.tar.gz
    mv mysql-5.6.27-linux-glibc2.5-x86_64 /usr/local/mysql
    /usr/sbin/groupadd mysql
    /usr/sbin/useradd -g mysql mysql
    cd /usr/local/mysql
    chown -R mysql:mysql ./
    cp support-files/my-default.cnf /etc/my.cnf
    chown mysql:mysql /etc/my.cnf
    vi /etc/my.cnf
[client]
port = 3306
socket = /usr/local/mysql/data/mysql.sock
[mysqld]
port = 3306
socket = /usr/local/mysql/data/mysql.sock
basedir = /usr/local/mysql
datadir  = /usr/local/mysql/data
    scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/
    cp support-files/mysql.server /etc/init.d/mysql
    chmod 755 /etc/init.d/mysql
    service mysql start(etc/init.d/mysql start)
    ps -ef |grep mysql
    netstat -lntup|grep 3306
    cd bin   ///usr/local/mysql/bin
    ./mysql -u root -p            // /usr/local/mysql/bin/mysql -u root -p
    update mysql.user set password=password("root") where user='root';
    flush privileges;
    show databases;

    
3、安裝php依賴庫
    mkdir -p /usr/local/libs/
    wget http://www.ijg.org/files/jpegsrc.v9.tar.gz     
    tar zxvf jpegsrc.v9.tar.gz
    cd jpeg-9/
    ./configure --prefix=/usr/local/libs --enable-shared --enable-static --prefix=/usr/local/libs
    make
    make install
    #make && make install
    cd ../
    
    wget http://prdownloads.sourceforge.net/libpng/libpng-1.6.2.tar.gz
    tar zxvf libpng-1.6.2.tar.gz
    cd libpng-1.6.2/
    ./configure --prefix=/usr/local/libs
    make
    make install
    #make && make install
    cd ../
    
    wget https://nchc.dl.sourceforge.net/project/freetype/freetype2/2.4.12/freetype-2.4.12.tar.gz
    tar zxvf freetype-2.4.12.tar.gz
    cd freetype-2.4.12/
    ./configure --prefix=/usr/local/libs
    make
    make install
    #make && make install
    cd ../
    
    wget "http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz?big_mirror=0"
    wget "http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz?big_mirror=0"
    wget "http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz?big_mirror=0"


    tar zxvf libmcrypt-2.5.8.tar.gz
    cd libmcrypt-2.5.8/
    ./configure --prefix=/usr/local/libs
    make
    make install
    #make && make install
    cd libltdl/
    ./configure --prefix=/usr/local/libs --enable-ltdl-install
    make
    make install
    #make && make install
    cd ../../


    tar zxvf mhash-0.9.9.9.tar.gz
    cd mhash-0.9.9.9/
    ./configure --prefix=/usr/local/libs
    make
    make install
    #make && make install
    cd ../
    
    vi /etc/ld.so.conf
        新增  /usr/local/libs/lib
    ldconfig
    
    tar zxvf mcrypt-2.6.8.tar.gz
    cd mcrypt-2.6.8/
    export LDFLAGS="-L/usr/local/libs/lib -L/usr/lib"
    export CFLAGS="-I/usr/local/libs/include -I/usr/include"
    touch malloc.h
    ./configure --prefix=/usr/local/libs --with-libmcrypt-prefix=/usr/local/libs
    make
    make install
    #make && make install
    cd ../
    
4、php
    yum install -y libxml2-devel openssl-devel libcurl-devel libjpeg-devel libpng-devel libicu-devel openldap-devel
    wget http://cn2.php.net/get/php-5.6.15.tar.gz/from/this/mirror
    tar zxvf mirror
    cd php-5.6.15
    
    export LIBS="-lm -ltermcap -lresolv"
    export DYLD_LIBRARY_PATH="/usr/local/mysql/lib/:/lib/:/usr/lib/:/usr/local/lib:/lib64/:/usr/lib64/:/usr/local/lib64"
    export LD_LIBRARY_PATH="/usr/local/mysql/lib/:/lib/:/usr/lib/:/usr/local/lib:/lib64/:/usr/lib64/:/usr/local/lib64"
    ./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-iconv-dir --with-freetype-dir=/usr/local/libs --with-jpeg-dir=/usr/local/libs --with-png-dir=/usr/local/libs --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt=/usr/local/libs --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-opcache --with-pdo-mysql --enable-maintainer-zts --without-pear  --disable-phar --disable-fileinfo
    make
    make install
    #make && make install
    cp php.ini-development /usr/local/php/etc/php.ini
    cd ../
    
    ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
    cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
    
5、配置nginx支援php
    vi /usr/local/nginx/conf/nginx.conf
        server{
            listen 80 default;            #預設埠
            server_name www.laravel50.com bb.laravel50.com;            #域名
            index index.html index.htm index.php;
            root /home/www/laravel50/public;        #域名指向根目錄
            location / {
                try_files $uri $uri/ /index.php?$query_string;
            }
            location ~ \.php$ {
                fastcgi_pass   127.0.0.1:9000;            #php-fpm
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include        fastcgi_params;
            }
        }
    /usr/local/nginx/sbin/nginx
    groupadd nobody
    修改/usr/local/php/etc/php-fpm.conf
        user = webadm
        group = webadm
    /usr/local/php/sbin/php-fpm(pkill php-fpm)
    
6、開放80埠
        /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT   寫入修改
 
         /etc/init.d/iptables save   儲存修改
 
        service iptables restart    重啟防火牆,修改生效
        
7、配置ftp
    yum install vsftpd 
    chkconfig vsftpd on
    chkconfig  //查詢狀態
    service vsftpd start
    groupadd webftp
    useradd -g webftp -M -d /home/www -s /sbin/nologin webftp
    passwd webftp
    chown -R webftp.webftp /home/www
    vi /etc/vsftpd/vsftpd.conf
        anonymous_enable=YES => NO
    getsebool -a | grep ftp
    setsebool allow_ftpd_full_access on
    iptables -I INPUT -p tcp --dport 21 -j ACCEPT
    modprobe ip_conntrack_ftp
    
8、安裝rar

    wget http://www.rarsoft.com/rar/rarlinux-x64-5.4.0.tar.gz
    tar -xzpvf rarlinux-x64-5.4.0.tar.gz
    cd rar/
    make
    unrar e myFile.rar
    
9、selinux
    /etc/sysconfig/selinux
    SELINUX=permissive