搭建PHP最新生產(chǎn)環(huán)境

搭建最新版本的 Linux + PHP7.2 + MySQL 8.0 + Nginx1.2 生產(chǎn)環(huán)境(含 Redis 4.0、Node 9.8)

開始前準(zhǔn)備

需要準(zhǔn)備一臺云服務(wù)器(Ubuntu16.04 系統(tǒng)),當(dāng)然你也可以使用本地虛擬機(jī)進(jìn)行測試

安裝 Nginx 服務(wù)器

  1. SSH 遠(yuǎn)程連接服務(wù)器


    image.png
  2. 更新軟件源


  3. 使用該命令安裝 Nginx apt install nginx -y

    image.png

4.測試一下

安裝 Mysql 服務(wù)器

  1. 使用該命令安裝 MySQLapt install mysql-server mysql-client -y

    image.png

  2. 看到交互頁面,會提示輸入密碼,鍵入密碼即可


    image.png
  3. 測試 mysql -uroot -p

    image.png

安裝 PHP7.2

  1. 添加軟件源


    image.png
image.png
  1. 更新軟件源apt update

  2. 查詢PHP版本


    image.png
  3. 安裝 PHP 7.2


    image.png
  4. 安裝成功


    image.png

配置 NGINX 將 PHP 文件轉(zhuǎn)發(fā)給 PHP-FPM

  1. 進(jìn)入到配置文件目

    $ cd /etc/nginx
    
  2. 文件解讀

    • nginx.conf 為主配置文件
    • sites-available 為主機(jī)配置文件,是我們需要配置的域名等信息
    • sites-enable 為主機(jī)配置文件的映射文件,其內(nèi)容來源于 sites-available
  3. 進(jìn)入 sites-available 目錄,將default修改如下(建議備份一下)

    server {
        listen 80 default_server;
        listen [::]:80 default_server;
        
        # SSL configuration
        #
        # listen 443 ssl default_server;
        # listen [::]:443 ssl default_server;
        #
        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
        #
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See: https://bugs.debian.org/765782
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;
        
        root /var/www/html;
        
        # Add index.php to the list if you are using PHP
        index index.php index.html index.htm index.nginx-debian.html;
        
        server_name _;
        
        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }
        
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
        #
        #       # With php7.0-cgi alone:
        #       fastcgi_pass 127.0.0.1:9000;
                # With php7.0-fpm:
                fastcgi_pass unix:/run/php/php7.2-fpm.sock;
        }
        
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        
        #location ~ /\.ht {
        #       deny all;
        #}
    }
    
  4. 查看配置是否出錯


    image.png
    $ nginx -t
    
  5. 進(jìn)入到 /var/www/html 目錄,添加 index.php 文件,其內(nèi)容如下

    <?php
        phpinfo();
    
  6. 重啟 NGINX

    $ service nginx restart
    
  7. 測試


    image.png

安裝 Redis

  1. 添加源

    $ add-apt-repository  ppa:chris-lea/redis-server  
    
  2. 更新源

    $ apt update
    
  3. 安裝
    [圖片上傳中...(image.png-2e3cb8-1523017494581-0)]

    $ apt install redis-server -y
    
  4. 測試

  5. $ redis-cli
    

安裝 Node

  1. 添加源

    curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash 
    
  2. 更新源

    $ apt update
    
  3. 安裝


    image.png
    $ apt install nodejs -y
    
  4. 測試

  5. $ node -v
    $ npm -v
    
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容