nginx 安裝配置

  1. yum源安裝

        

    安裝依賴包

 yum install pcre-devel zlib-devel openssl-devel

        安裝需要的服務         

 yum -y install nginx php-mysql mysql mariadb-server php-fpm

    創建nginx的啓動用戶

 useradd -r www

    修改nginx的配置nginx.conf

 user www;
 worker_processes auto;

    修改php-fpm的啓動用戶

  user = www    
  group = www

    創建php-fpm的session目錄

[root@centos7 nginx]# mkdir /var/lib/php/session/
[root@centos7 nginx]#  chown -R www.www /var/lib/php/session/

啓動mariadb服務

[root@centos7 vhost1]# systemctl start mariadb.service 
[root@centos7 vhost1]# systemctl enable mariadb.service   //開機啓動

創建所需要的庫

MariaDB [(none)]> CREATE DATABASE wps;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> GRANT ALL ON wps.* TO 'wps_user'@'192.168.%.%' IDENTIFIED BY 'wps_pass';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec

開啓php-fpm服務

[root@centos7 conf.d]# systemctl start php-fpm.service
[root@centos7 conf.d]# systemctl enable php-fpm.service //開機啓動
Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.

配置nginx虛擬主機wps.conf

[root@centos7 conf.d]# cat wps.conf 
server {
        listen 80;
        server_name www.runner.vip;
        location / {
                root /apps/vhost1/wordpress;
        }
        index  index.php index.html index.htm;
        location ~ \.php$ {
                root           /apps/vhost1/wordpress;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  /apps/vhost1/wordpress$fastcgi_script_name;       #需要指定我們指定存放php程序網站的路徑
                include        fastcgi_params;
        }
}

  配置ssl虛擬主機ssl.conf

[root@centos7 conf.d]# cat ssl.conf 
server {
        listen       443 ssl;
        server_name  myadmin.runner.vip;
        ssl_certificate      /etc/nginx/ssl/nginx.crt;    #從CA申請過來的證書
        ssl_certificate_key  /etc/nginx/ssl/httpd.key;            #私鑰
        ssl_session_cache    shared:SSL:1m;                             #ssl會話共享緩存,1分鐘時間
        ssl_session_timeout  5m;                                        #ssl會話超時時間5分鐘
        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;
        location / {
                root /apps/vhost2/phpmyadmin;
                index index.php index.html index.htm;
        }
        location ~ \.php$ {
                root           /apps/vhost2/phpmyadmin;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  /apps/vhost2/phpmyadmin$fastcgi_script_name;       #需要指定我們指定存放php程序網站的路徑
                include        fastcgi_params;
        }
}

訪問頁面出現錯誤

    myadmin.runner.vip 網頁無法正常運作

    myadmin.runner.vip 目前無法處理此請求。

    

    HTTP ERROR 500


查看錯誤日誌

[root@centos7 conf.d]# tail /var/log/php-fpm/www-error.log 
[29-Jul-2016 08:28:22 UTC] PHP Fatal error:  Call to undefined function mb_detect_encoding() in /apps/vhost2/phpMyAdmin-4.3.5-all-languages/libraries/php-gettext/gettext.inc on line 177
[29-Jul-2016 08:28:25 UTC] PHP Fatal error:  Call to undefined function mb_detect_encoding() in /apps/vhost2/phpMyAdmin-4.3.5-all-languages/libraries/php-gettext/gettext.inc on line 177
[29-Jul-2016 08:28:52 UTC] PHP Fatal error:  Call to undefined function mb_detect_encoding() in /apps/vhost2/phpMyAdmin-4.3.5-all-languages/libraries/php-gettext/gettext.inc on line 177
[29-Jul-2016 08:28:57 UTC] PHP Fatal error:  Call to undefined function mb_detect_encoding() in /apps/vhost2/phpMyAdmin-4.3.5-all-languages/libraries/php-gettext/gettext.inc on line 177
[29-Jul-2016 08:31:37 UTC] PHP Fatal error:  Call to undefined function mb_detect_encoding() in /apps/vhost2/phpMyAdmin-4.3.5-all-languages/libraries/php-gettext/gettext.inc on line 177
[29-Jul-2016 08:31:50 UTC] PHP Fatal error:  Call to undefined function mb_detect_encoding() in /apps/vhost2/phpMyAdmin-4.3.5-all-languages/libraries/php-gettext/gettext.inc on line 177

需要安裝依賴包

[root@centos7 conf.d]# yum -y install php-mbstring
[root@centos7 conf.d]# systemctl reload php-fpm.service 重啓php-fpm服務

打開瀏覽器訪問

    wKiom1ebGofyy8XSAAIZndCJJfg094.png-wh_50


源碼包安裝

    安裝包組

[root@centos7 ~]# yum -y groupinstall "Server Platform Development" "Development Tools"

下載nginx源碼包    

[root@centos7 src]# wget http://nginx.org/download/nginx-1.10.1.tar.gz

編譯安裝nginx

./configure --prefix=/usr/local/nginx \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--user=nginx --group=nginx \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_dav_module  \
--with-http_stub_status_module \
--with-threads \
--with-file-aio

make && make install

安裝mariadb 二進制包

[root@centos7 src]# mkdir /data/mysql -pv
[root@centos7 src]# groupadd -r -g 306 mysql
[root@centos7 src]# useradd -g mysql -s /sbin/nologin mysql
[root@centos7 src]# chown -R mysql.mysql /data/mysql/
[root@centos7 src]# mv mariadb-5.5.46-linux-x86_64 /usr/local/
[root@centos7 src]# ln -sv /usr/local/mariadb-5.5.46-linux-x86_64/ /usr/local/mysql
‘/usr/local/mysql’ -> ‘/usr/local/mariadb-5.5.46-linux-x86_64/’
[root@centos7 src]# cd /usr/local/mysql/
[root@centos7 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
[root@centos7 mysql]# cp support-files/my-large.cnf /etc/my.cnf
cp: overwrite ‘/etc/my.cnf’? y
[root@centos7 mysql]# vim /etc/my.cnf
    [mysqld]
    port            = 3306
    socket          = /tmp/mysql.sock
    skip-external-locking
    key_buffer_size = 256M
    max_allowed_packet = 1M
    table_open_cache = 256
    sort_buffer_size = 1M
    read_buffer_size = 1M
    read_rnd_buffer_size = 4M
    myisam_sort_buffer_size = 64M
    thread_cache_size = 8
    query_cache_size= 16M
    datadir = /data/mysql
    innodb_file_per_table = ON
    skip_name_resolve = ON
    thread_concurrency = 8
 [root@centos7 mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysql
 [root@centos7 mysql]# /etc/init.d/mysql start
Starting MySQL.. SUCCESS!

安裝php-fpm所依賴的安裝包

yum install libxml2-develgd-devel freetype-devel libmcrypt-devel
yum install pcre-developenssl-devel  libevent-devel
[root@centos7 php-5.4.40]# ./configure --prefix=/usr/local/php-fpm \
--with-mysql=/usr/local/mysql \
--with-openssl \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--enable-mbstring \
--enable-xml \
--enable-sockets \
--with-freetype-dir \
--with-gd \
--with-libxml-dir=/usr/ \
--with-zlib \
--with-jpeg-dir \
--with-png-dir \
--with-mcrypt \
--with-config-file-path=/etc/php.d/php.ini \
--with-config-file-scan-dir=/etc/php.d \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--enable-fpm

[root@centos7 php-5.4.40]# cp php.ini-production /etc/php.d/php.ini
[root@centos7 php-5.4.40]# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
[root@centos7 fpm]# chmod +x /etc/rc.d/init.d/php-fpm 

安裝xcache插件
[root@centos7 src]# tar jxf xcache-3.2.0.tar.bz2 
[root@centos7 src]# cd xcache-3.2.0/
[root@centos7 xcache-3.2.0]# phpize 
Configuring for:
PHP Api Version:         20100412
Zend Module Api No:      20100525
Zend Extension Api No:   220100525
[root@centos7 xcache-3.2.0]# ./configure --enable-xcache --with-php-config=/usr/local/php-fpm/bin/php-config
[root@centos7 xcache-3.2.0]# make && make install
[root@centos7 xcache-3.2.0]# cp xcache.ini /etc/php.d/
[root@centos7 xcache-3.2.0]# /etc/init.d/php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm  done

準備數據庫

MariaDB [(none)]> CREATE DATABASE wps;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> GRANT ALL ON wps.* TO 'wps_user'@'192.168.%.%' IDENTIFIED BY 'wps_pass';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> FLUSH PRIVILEGES
    -> ;
Query OK, 0 rows affected (0.00 sec)

配置nginx虛擬主機

[root@centos7 conf.d]# cat wps.conf 
server {
        listen 80;
        server_name www.runner.vip;
        location / {
                root /apps/vhost1/wordpress;
                index  index.php index.html;
        }
        location ~ \.php$ {
                root           /apps/vhost1/wordpress;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  /apps/vhost1/wordpress$fastcgi_script_name;       #需要指定我們指定存放php程序網站的路徑
                include        fastcgi_params;
        }
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章