1. 程式人生 > >Centos7 下 nginx1.14+php7.2+mysql5.6+swoole

Centos7 下 nginx1.14+php7.2+mysql5.6+swoole

虛擬機器安裝完centos7後(網路方式為橋接)後:
  vi /etc/sysconfig/network-scripts/ifcfg-ens33
  修改:
    ONBOOT=yes
  儲存退出。 service network restart,現在網路應該就通了,可以ping ip
  檢視自己的ip 可以用ipaddr
  用 ifconfig 檢視當前網路連線資訊。如果 找不到此命令,估計 /sbin/ 裡面就沒有這個命令。
  yum install -y net-tools
  然後就可以用 ifconfig 了。 

     將ip固定:
       修改 BOOTPROTO=static
            IPADDR=你要用的ip
            NETMASK=子網掩碼
            GATEWAY=閘道器
            #NM_CONTROLLED=no

  儲存。 service network restart。再用ifconfig看就變了。
  (NM_CONTROLLED=no表示該介面不通過網路管理器進行管理,而是通過配置檔案管理,這個我沒寫也可以,看情況吧)。
  ping baidu.com 如果報找不到,但是 ping 百度ip 可以通,那麼說明dns解析有問題。
    配置dns解析:
      cd /etc/NetworkManager
      vi NetworkManage.conf
      增加 dns=none
     vi /etc/resolv.conf 
       新增dns 配置
       #主 DNS
       nameserver 114.114.114.114
       #備DNS
       nameserver 8.8.4.4
   service network restart 就好了。再ping baidu.com 應該就可以通了。

   安裝影象化介面:(建議不要安裝)
    # yum groupinstall "GNOME Desktop" "Graphical Administration Tools"
    # ln -sf /lib/systemd/system/runlevel5.target /etc/systemd/system/default.target
    # reboot
---------------------------------------------------------------------------
   Centos6 中防火牆使用的是 iptables
   Cnetos7 中防火牆使用的是 fireware
     開啟埠命令如下:
       firewall-cmd --zone=public --add-port=80/tcp --permanent 
      命令含義:
        --zone            #作用域
        --add-port=80/tcp #新增埠,格式為:埠/通訊協議
        --permanent       #永久生效
    重啟防火牆:
      systemctl restart firewalld.service
    關閉防火牆:
      systemctl stop firewalld.service
    檢視已經開放的埠:
      firewall-cmd --list-ports
    檢視監聽的埠:
      netstat -nltp
      如果指定監聽8080埠,netstat -nltp|grep 8080

---------------------------------------------------------------------
安裝東西前確定gcc,gcc-c++已安裝,這個庫涉及到後面的編譯。

yum install -y gcc gcc-c++ 
groupadd www
useradd -g www www -M -s /sbin/nologin    #-M不建立家目錄,-s /sbin/nologin 不讓登入主機
cat /etc/passwd

安裝nginx:(nginx1.14.x)
  官網有安裝示例。
 (http://nginx.org/en/docs/configure.html 有configure 的詳細說明,包括預設路徑,比 --help 全) 
   ./configure --help
  根據上面的內容,要的直接選中右鍵paste 就直接到下面去了

  ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --without-http_gzip_module --with-pcre
  #--with-http_realip_module --with-http_stub_status_module --with-http_sub_module 
   這幾個視需求而定。
  1.報錯
    ./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
    解決:需要安裝 pcre-devel
          yum install -y pcre-devel
  2.報錯
    ./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.
    解決:需要安裝 openssl-devel
         yum install -y openssl-devel
  3.報錯
    --with-gzip_module ...
    解決: yum install -y zlib-devel 

 再次構建,構建後: echo $? (為0則沒出現過錯)
  make & make install

  然後找到 可執行檔案 nginx,./nginx 執行nginx
    ps -ef|grep nginx  檢視是否已經啟動
    也可以用: netstat -nltp|grep 80
  訪問本地,正常則返回nginx的歡迎頁面。不正常則找不到,檢視80埠是否開啟:
    firewall-cmd --list-ports       看是否有80埠 
    沒開啟則開啟。 
    firewall-cmd --zone=public --add-port=80/tcp --permanent

-------------------------------------------------------------------------
安裝mysql:
groupadd mysql
useradd -g mysql mysql -M -s /sbin/nologin

mysql-5.6.41-linux-glibc2.12-x86_64.tar.gz:
(二進位制檔案的安裝)官網有安裝示例

可以先安裝,碰到問題了再裝依賴; yum install -y cmake perl-devel autoconf
tar xf mysql-5.6.41-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.6.41-linux-glibc2.12-x86_64 /usr/local/mysql
chown -R mysql:mysql mysql
cd mysql
./scripts/mysql_intall_db --user=mysql
安裝初始化完畢(如果原本存在的 /etc/my.cnf有問題,可以刪掉,這樣就直接訪問/usr/local/mysql/my.cnf了)
啟動 support_files/mysql.server
進入資料庫:./bin/mysql -uroot ,也可以 1.cp mysql /usr/bin/ 然後直接 mysql -uroot
此時的資料庫登入不要賬號密碼,可以用這個 delete from mysql.user where user='';
然後 : update mysql.user set Password=PASSWORD('密碼') where user="root"
再不用密碼就登入不進去了。
登入:mysql -uroot -p密碼


下面是非二級制檔案安裝的:(這個沒有測試過)
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql.sock \
-DMYSQL_USER=mysql \
-DEFAULT_CHARSET=utf8 \
-DEFAULT_COLLATION=utf8_general_ci \
-DWITH_MYISAM_STORAGE_ENGINE=1 \      
-DWITH_INNOBASE_STORAGE_ENGINE=1 \     
-DWITH_DEBUG=0 \
-DWITH_READLINE=1 \
-DWITH_EMEDDED_SERVER=1 \
-DENABLED_LOCAL_INFILE=1

檢視構建錯誤: echo $?
安裝成功後,初始化資料庫:
mysql/script/mysql_install_db --datadir=/usr/local/mysql/data/ --basedir=/usr/local/mysql/ --user=mysql
沒報錯,有兩個ok就初始化完成。
  mysql/support-files 中有例項的配置檔案
  移動一個你想要的到 mysql/etc/  裡面,並改名為my.cnf
啟動資料庫:
  mysql/support-files/mysql.server 
  rm -f /etc/my.cnf        #刪掉系統自帶的配置檔案,刪掉後就找 mysql/etc/my.cnf了
  netstat -n|tp
這是用mysql 提示找不到:
 兩種解決辦法: 1.cp mysql /usr/bin/
          2.新增環境變數
 mysql #進去了,但現在還不能用,還有安全性問題
 進入script下有個 mysql_secure_installation 執行它。

--------------------------------------------------------------------------
安裝php:(php-7.2.9)
 下面的配置是摘抄的:
  ./configure --prefix=/usr/local/php --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-bz2 --with-mhash --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-gd-native-ttf --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-zip

 下面的配置是自己看 ./configure --help,自己一個一個選的:
  ./configure --prefix=/usr/local/php --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-config-file-path=/usr/local/php/etc --with-libxml-dir --with-xmlrpc --with-openssl --with-pcre-regex --with-zlib --with-zlib-dir --enable-bcmath --with-bz2 --with-curl --with-libxml-dir --with-pcre-dir --with-gd --with-jpeg-dir --with-png-dir --with-zlib-dir  --with-gettext --with-mhash --enable-mbstring --with-mysqli --enable-pcntl --with-pdo-mysql --with-pdo-sqlite --with-zlib-dir --enable-shmop --with-libxml-dir --with-openssl-dir --enable-soap --enable-sockets --with-iconv-dir --enable-zip --with-pcre-dir --with-libzip --enable-mysqlnd --with-pear

  下面的依賴是網上找的:
      yum -y install openssl
      yum -y install openssl-devel
      yum -y install curl
      yum -y install curl-devel
      yum -y install libjpeg
      yum -y install libjpeg-devel
      yum -y install libpng
      yum -y install libpng-devel
      yum -y install freetype
      yum -y install freetype-devel
      yum -y install pcre
      yum -y install pcre-devel
      yum -y install libxslt
      yum -y install libxslt-devel
      yum -y install bzip2
      yum -y install bzip2-devel

 下面裝的依賴是自己報錯試出來的:
  我們來看看配置會報哪些錯:然後安裝依賴
    yum install -y libxml2-devel bzip2-devel curl-devel libwebp-devel libjpeg-devel libpng-devel freetype-devel 

    yum remove libzip  (yum安裝的版本太低,所以編譯安裝)
    然後libzip的版本要求是>= 0.11
    然後找個目錄下載安裝新版本:
    wget https://nih.at/libzip/libzip-1.2.0.tar.gz
    tar -zxvf libzip-1.2.0.tar.gz
    cd libzip-1.2.0
    ./configure
    make
    make install
    安裝完新版的libzip後可能系統找不到,手動複製下:
    cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h

   前面安裝nginx 時已經安裝了 openssl-devel,pcre-devel,zlib-devel
   php部分我們又安裝了 curl-devel libwebp-devel libjpeg-devel libpng-devel freetype-devel libxml2-devel bzip2-devel 
                      還有對版本有要求 >=0.11 的 libzip(編譯安裝)
   make (沒報錯就進行下一步)
   make install

   cp php-fpm.conf.default php-fpm.conf (程序配置檔案)
   到原始碼安裝包裡:(開發用 development 就夠了,生產環境用 production)
   cp php.ini-development  /usr/local/php/etc/php.ini
   cd /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
   
   cd sbin
   ./php-fpm
  netstat -nltp
  會發現有個 9000 埠的 php-fpm,那麼啟動成功。
----------------------------------------------------------------------------------------------------------------
配置nginx 將其與 php連線起來:
/usr/local/nginx/conf/nginx.conf
  user www www
  開啟 location ~ \.php${
    root           /usr/local/nginx/html;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    include        fastcgi_params;

  }
  然後看路徑 root 要不要配置(根據你的情況而定)
/usr/local/nginx/sbin/nginx -s reload
然後網頁訪問看能不能訪問到 php 檔案。
如果不能訪問,將上面的 fastcgi_param 後面的 /scripts 改為 $document_root 然後過載再試試。
(看下 根目錄要不要將 root的改為www,這個視情況而定)
SUCCESS!

************到此處為止,nginx1.14(stable)+php7.2.9+mysql5.6(二進位制版本) 搭建完成。
--------------------------------------------------------------------------------------
 Centos7 下的 nginx,php,mysql 開機自啟動:
   nginx:
    vi /lib/systemd/system/nginx.service 檔案(建立檔案)
      [Unit]
      Description=nginx
      After=network.target
      [Service]
      Type=forking
      ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
      ExecReload=/usr/local/nginx/sbin/nginx -s reload
      ExecStop=/usr/local/nginx/sbin/nginx -s quit
      PrivateTmp=true
      [Install]
      WantedBy=multi-user.target

   php:
    vi /lib/systemd/system/php-fpm.service 檔案(建立檔案)  
      [Unit]
      Description=php-fpm
      After=network.target
      [Service]
      Type=forking
      ExecStart=/usr/local/php/sbin/php-fpm
      ExecStop=/bin/pkill -9 php-fpm
      PrivateTmp=true
      [Install]
      WantedBy=multi-user.target

   mysql:
    vi /lib/systemd/system/mysql.service 檔案(建立檔案) 
      [Unit]
      Description=MySQL Server
      #Documentation=man:mysqld(8)
      #Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
      After=network.target
      After=syslog.target

      #[Install]
      #WantedBy=multi-user.target

      [Service]
      User=mysql
      Group=mysql
      ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/usr/local/mysql/my.cnf
      LimitNOFILE = 5000
      #Restart=on-failure
      #RestartPreventExitStatus=1
      #PrivateTmp=false

   [Unit]:服務的說明
    Description:描述服務
    After:描述服務類別
    [Service]服務執行引數的設定
    Type=forking是後臺執行的形式
    ExecStart為服務的具體執行命令
    ExecReload為重啟命令
    ExecStop為停止命令
    PrivateTmp=True表示給服務分配獨立的臨時空間
    注意:[Service]的啟動、重啟、停止命令全部要求使用絕對路徑
    [Install]執行級別下服務安裝的相關設定,可設定為多使用者,即系統執行級別為3

   先關閉nginx,php-fpm:直接kill 掉吧
   然後使用以下命令開啟
        systemctl start nginx.service
        systemctl start php-fpm.service
        systemctl start mysql.service

   開機成功,將服務加入開機啟動
      systemctl enable nginx.service       #注意後面不能跟空格
      #Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.

      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.

      systemctl enable mysql.service

   重啟系統,檢視執行的服務。
   systemctl list-units --type=service           #檢視執行的服務
---------------------------------------------------------------------------
Swoole:
   swoole官網:www.swoole.com
  Swoole:面向生產環境的 PHP 非同步網路通訊引擎
   是PHP開發人員可以編寫高效能的非同步併發 TCP,UDP,UnixSocket,HTTP,WebSocket服務。
   Swoole可以廣泛的應用於網際網路,行動通訊,企業軟體,雲端計算,網路遊戲,物聯網(IOT),車聯網,智慧家居等領域。使用PHP+Swoole作為網路通訊框架,可以使企業IT
   研發團隊的效率大大提升,更專注於開發創新產品。

  如何學習swoole
    檢視文件
    實現swoole特性的功能點
    多看看其他現有的swoole案例程式碼(github,開源中國)

   下載安裝swoole:
    進入www.swoole.com點選下載,然後會跳轉介面,選取克隆下載地址:https://gitee.com/swoole/swoole.git
    linux 上安裝git後:
    git clone https://gitee.com/swoole/swoole.git
    下載後是已經解壓好的原始碼
    原始碼安裝,發現這裡面沒有 configure,此時執行裝好的phpize
    執行命令:/usr/local/php/bin/phpize
    這是再看,發現swoole下面有了 configure,還有一些其他改變

    ./configure --with-php-config=/usr/local/php/bin/php-config
      然後 make
      然後 make install
         出現:Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/
         這個路徑說的是擴充套件的路徑。
         進入後列印如下:[[email protected] no-debug-non-zts-20170718]# ll
                 total 9944
                 -rwxr-xr-x. 1 root root 3581556 Apr  5 01:00 opcache.a
                 -rwxr-xr-x. 1 root root 1971952 Apr  5 01:00 opcache.so
                 -rwxr-xr-x. 1 root root 4622688 Apr  5 09:47 swoole.so
         所以說最終的擴充套件是 .so 檔案。

          在swoole原始碼安裝包裡面有 example,進入,這裡面都是使用swoole的例子。
              cd server 。 開啟 echo.php,檢視
             直接 php echo.php
                 報錯,原因是擴充套件檔案的載入還要看php.ini裡面的 extension=
             在php.ini中加上 extension=swoole ,然後 php -m 就可以看到載入的模組swoole了(這裡說明一下,只有在指定的擴充套件目錄下面有相應的.so檔案,並且php.ini裡面添加了配置,php -m才能檢視到該擴充套件)
             再次執行 php echo.php
             然後檢視此埠:netstat -anp|grep 9501
               得到結果:tcp        0      0 0.0.0.0:9501            0.0.0.0:*               LISTEN      32898/php
             ctrl+c 取消掉執行程式後再次 netstat -anp|grep 9501   發現沒有了,消失了

          檢視埠號:
          netstat -anp|grep 9501

          telnet 127.0.0.1 9501

相關推薦

Centos7 nginx1.14+php7.2+mysql5.6+swoole

虛擬機器安裝完centos7後(網路方式為橋接)後:   vi /etc/sysconfig/network-scripts/ifcfg-ens33   修改:     ONBOOT=yes   儲存退出。 service network restart,現在網路應該就通了,

CentOS7+nginx1.14+php7.2.9+mysql5.7

安裝nginx1.14最新穩定版本 安裝nginx需要的庫軟體 1、gcc gcc-c++ 軟體安裝編譯所需的軟體 2、pcre pcre-devel PCRE(Perl Compatible Regular Expression

Centos7完美安裝並配置mysql5.6

原文:https://www.cnblogs.com/yunns/p/4877333.html Centos7將預設資料庫mysql替換成了Mariadb,對於我們這些還想用mysql的人來說並不是一個好訊息。 最近我搜羅了網上各種安裝教程,各種出問題,要麼安裝失敗,要

centos7.3+nginx1.8+php7.1+mysql5.7 安裝(三安裝mysql)

1、配置YUM源 # 下載mysql源安裝包 shell> wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm # 安裝mysql源 shell> yum loca

centos7.3+nginx1.8+php7.1+mysql5.7 安裝(一安裝nginx)

1、先解除安裝老版本 yum remove nginx   2、編輯nginx的yum源配置 vi /etc/yum.repos.d/nginx.repo   往裡面寫入 [nginx]   name=nginx repo   base

阿里雲 LinuxCentOS7 部署javaweb環境 ------ 2.mysql5.6 yum安裝

安裝包一種是tar.gz 壓縮包解壓完配置一下就可以用了,另外一個是rpm包安裝,相當於window裡面exe安裝檔案,這裡mysql 用rpm包安裝比較簡單。 一共幾步: 1.yum源改成阿里yum源 2.下載安裝 3.防火牆開放埠 4.navicat 遠端連

centos7yum安裝lamp,php7.2+mysql5.7

1 安裝apache ①安裝 [[email protected] ~]# yum install httpd ②啟動 [[email protected] ~]# systemctl start httpd 2 安裝php7.2 參考部落格:https:

centos7 Nginx1.14+php7+mysql5.7 以及 centos7 Apache2.4+PHP7+mysql 安裝 Linux 配置 composer 以及Python2.7升級到3.7

ack ria util oca 簡單 www. mbstring fig yum 1 centos7 Nginx1.14+php7.0+mysql5.7 (LNMP)安裝 nginx rpm -Uvh http://nginx.org/packages/centos

CentOS 6.6編譯安裝Nginx1.6.2+MySQL5.6.21+PHP5.6.3

strong 版權 刪除 type lis /tmp tar err conf 準備篇: CentOS 6.6系統安裝配置圖解教程 http://www.osyunwei.com/archives/8398.html 一、配置防火墻,開啟80端口、3306端口 vi /et

centos7.2+mysql5.6.35+subversion1.9.7+apache+https+php5.6.20+manmanager1.10(一)

賬戶 停止 file set and .gz rep kcon start 最近因為windows平臺的powershell病毒,導致所有windows服務器都需要遷移到linux,其中也包括svn,遷移過程中遇到很多坑逐一踩過後,現在就過程記錄下 這套環境是使用的cent

centos7上以RPM方式安裝MySQL5.6

eve 刷新 ftp -i 遠程 span 查找 /var/ load 1. 下載MySQL http://ftp.ntu.edu.tw/MySQL/Downloads/MySQL-5.6/ MySQL-5.6.36-1.el7.src.rpm MySQL-5.6.36-1

centos7安裝docker(2鏡像)

world 組成 啟動 ges src img es2017 base .com docker最小的鏡像——hello-world 下載鏡像 docker pull docker pull hello-world 查看鏡像 docker images docker im

CentOS7使用rpm-gpg-key-epel-6報錯解決方法

centos7今天遇到一個在CentOS7下用rpm-gpg-key-epel-6的文件安裝yum install gridengine-6.2u5-10.el6.4.x86_64 gridengine-devel-6.2u5-10.el6.4.x86_64 gridengine-execd-6.2u5-10

Linux系統 Centos7 yum命令在線安裝 MySQL5.6

yum安裝mysql rpm包現在Centos7的yum源中 沒有mysql,可以直接安裝。用了MariaDB 代替了。那我們如果要裝MySQL數據庫,可以用以下方法# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm

Centos7 安裝nginx1.14

服務 local com font gcc編譯器 位置 spa tor reload 一丶官網 http://nginx.org/en/download.html 至於安裝那個版本首先要看清楚版本代表什麽意思 Nginx官網提供了三個類型的版本Mainline versi

linux centos7源碼 tar安裝mysql5.7.23(5.7以上均可試用)

connect -s ice 安裝 oca 參考 tar centos7 改密碼 1、工具:mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz、centos7 2、解壓後,將mysql-5.7.22-linux-glibc2.12-x86_

centos7升級版本到php7.2

1、檢視PHP版本 php -v 2、刪除舊php yum remove php* 3、安裝epel sudo yum install epel-release 4、安裝remi sudo yum install http://rpms.remirepo

centos7nginx1.14.0配置https

說在前面: centos7上配置https之前需要先配置 ngx_http_ssl_module,否則即使在nginx.conf中配置了https,但在啟動nginx的時候會報錯: nginx: [emerg] the "ssl" parameter requires n

Linux學習_007_CentOS7使用yum命令安裝MySQL5.6

第一步:檢查Linux系統中是否已安裝 MySQL [[email protected] ~]# rpm -qa | grep mysql[[email protected] ~]#   返回空值的話,就說

Centos7使用RPM方式安裝Mysql5.7.12

Systemctl restart mysqld  #重啟MySQL服務 2、進入MySQL控制檯 mysql -uroot -p   #直接按回車,這時不需要輸入root密碼。 3、修改root密碼 update mysql.user setauthentication_string=password