CentOS7 下配置 Nginx + PHP7 + MariaDB + ThinkPHP5.1
生活随笔
收集整理的這篇文章主要介紹了
CentOS7 下配置 Nginx + PHP7 + MariaDB + ThinkPHP5.1
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
最近突然想學習一下使用一些比較成熟的后臺框架,考慮到之前幫大佬打下手的時候用過 ThinkPHP 所以就暫定了以 ThinkPHP 為主要學習目標。
下面是我在服務器端配置 Thinkphp 所需環境而踩的一些坑(且有很多已經是老坑了):
- 本次配置選擇的服務器系統為 Centos7 環境是 Nginx + PHP7 + MariaDB + ThinkPHP5.1
- 我會按照我個人認為合適的順序分別介紹他們的安裝與配置過程
1. MariaDB 的安裝與初始配置
# yum 安裝 yum -y install mariadb mariadb-server# 安裝完成MariaDB,首先啟動MariaDB systemctl start mariadb # 設置開機啟動 systemctl enable mariadb# 接下來進行MariaDB的相關簡單配置 mysql_secure_installation#首先是設置密碼,會提示先輸入密碼 Enter current password for root (enter for none):# 初次運行直接回車#設置密碼 Set root password? [Y/n] # 是否設置root用戶密碼,輸入y并回車或直接回車 New password: # 設置root用戶的密碼 Re-enter new password: # 再輸入一次你設置的密碼#其他配置 Remove anonymous users? [Y/n] # 是否刪除匿名用戶 Disallow root login remotely? [Y/n] #是否禁止root遠程登錄 Remove test database and access to it? [Y/n] # 是否刪除test數據庫 Reload privilege tables now? [Y/n] # 是否重新加載權限表#初始化MariaDB完成,接下來測試登錄 mysql -uroot -ppassword2. PHP7 + PHP-FPM 安裝
# 在centos7通過yum安裝PHP7,首先在終端運行: rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm# 提示錯誤: error: Failed dependencies: epel-release >= 7 is needed by webtatic-release-7-3.noarch# 需要先安裝epel-release。 yum -y install epel-release # 再安裝PHP7 rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm # 獲取PHP7的yum源 yum install php70w php70w-fpm# 驗證安裝 PHP -v,# 顯示當前PHP版本,信息如下: [root@Ryoma /]# php -v PHP 7.0.18 (cli) (built: Apr 15 2017 07:09:11) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies# 這樣就在CentOS 7下通過yum安裝成功PHP7.3. 編譯安裝 Nginx 并配置 PHP
# [必須]安裝 nginx 需要先將官網下載的源碼進行編譯,編譯依賴 gcc 環境,如果沒有 gcc 環境,則需要安裝: yum install gcc-c++# [必須]PCRE(Perl Compatible Regular Expressions) 是一個Perl庫,包括 perl 兼容的正則表達式庫。nginx 的 http 模塊使用 pcre 來解析正則表達式,所以需要在 linux 上安裝 pcre 庫,pcre-devel 是使用 pcre 開發的一個二次開發庫。nginx也需要此庫。命令: yum install -y pcre pcre-devel# [自選]zlib 庫提供了很多種壓縮和解壓縮的方式, nginx 使用 zlib 對 http 包的內容進行 gzip ,所以需要在 Centos 上安裝 zlib 庫。 yum install -y zlib zlib-devel# [自選]nginx 不僅支持 http 協議,還支持 https(即在ssl協議上傳輸http),所以需要在 Centos 安裝 OpenSSL 庫。 yum install -y openssl openssl-devel# 官網下載 Ngxin # 直接下載.tar.gz安裝包,地址:https://nginx.org/en/download.html # 推薦選擇穩定版下載 : 當前版本 1.12.2 # 下載鏈接: https://nginx.org/download/nginx-1.12.2.tar.gz wget -c https://nginx.org/download/nginx-1.12.2.tar.gz# 解壓 用到了之前下載的zlib庫 若沒下載可選擇其他方式解壓 tar -zxvf nginx-1.12.2.tar.gz# 編譯前初始化配置 cd nginx-1.12.2 # 進入nginx目錄 ./configure # 使用默認配置# 編譯安裝 make make install# 查找安裝路徑 [root@Ryoma nginx-1.12.2]#whereis nginx nginx: /usr/local/nginx# 啟動、停止 nginx cd /usr/local/nginx/sbin/ # 進入 nginx sbin 目錄 ./nginx # 啟動 nginx ./nginx -s quit # 此方式停止步驟是待 nginx 進程處理任務完畢進行停止 ./nginx -s stop # 此方式相當于先查出 nginx 進程id再使用kill命令強制殺掉進程 ./nginx -s reload # 重新加載#查詢 nginx 進程: ps aux|grep nginx# 配置 nginx vim /usr/local/nginx/conf/nginx.conf # 個人配置圖如下4. 安裝 ThinkPHP5
# 全局安裝 composer curl -sS https://getcomposer.org/installer | php mv composer.phar /usr/local/bin/composer# tp5 5.1 版本安裝 composer create-project topthink/think tp5 --prefer-dist # PHP版本低于5.6的話 將仍然安裝5.0版本總結
以上是生活随笔為你收集整理的CentOS7 下配置 Nginx + PHP7 + MariaDB + ThinkPHP5.1的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 龟苓膏的功效与作用(立秋吃龟苓膏有四大好
- 下一篇: 丹西斯的母亲(卢卡·丹西斯的女朋友简介)