ubuntu16.04 安裝php7.2 Nginx Mysql5.7


安裝php7.2

可以通過 apt list | grep php7 命令查看是否有php7.2的包,ubuntu16.04默認是有7.0的。

添加源

sudo apt-get install software-properties-common
sudo add-apt-repository -y ppa:ondrej/php sudo apt-get update

再次執行 apt list | grep php7 命令就可以發現列表中已經包含有7.2版本的包了。

安裝php7.2

apt-get install php7.2

nginx使用php需要安裝php7.2-fpm, 和一些php插件

sudo apt-get install php7.2-mysql php7.2-fpm php7.2-curl php7.2-xml php7.2-gd php7.2-bcmath php7.2-mbstring php-memcached php7.2-zip

安裝完成,執行 php --version 查看是否安裝成功

上述安裝php命令會自動安裝apache2服務,可以通過 service apache2 status 查看

卸載apache2,執行以下命令

service apache2 stop
apt remove apache2*
apt autoremove
 
        

安裝Nginx

apt install nginx
service nginx status #查看狀態

配置php-fpm

有時候安裝完成后不知道安裝到什么地方啦可以使用下面命令查找下

whereis php-fpm

第一種方法修改配置監聽9000端口來處理nginx的請求(這種方法一般在windows上使用)

修改 /etc/php/7.2/fpm/pool.d/www.conf 文件找到第36行,注釋並添加一行

;listen = /run/php/php7.2-fpm.sock
listen = 127.0.0.1:9000

修改nginx配置/etc/nginx/sites-available/default (這個地方是默認的配置文件,也可以加在其他地方)

location ~ \.php$ {
  try_files $uri =404;
  fastcgi_split_path_info ^(.+\.php)(/.+)$;
  fastcgi_pass 127.0.0.1:9000;
  #fastcgi_pass unix:/run/php/php7.2-fpm.sock;
  fastcgi_index index.php;
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  include fastcgi_params;
}

另一種方法linux下使用sock方法速度會更快,不修改 /etc/php/7.2/fpm/pool.d/www.conf 文件,使用里面  /run/php/php7.2-fpm.sock 這樣的路徑,后面nginx也要設置成這種格式  fastcgi_pass unix:/run/php/php7.2-fpm.sock;

 

配置nginx

   修改站點根目錄訪問權限

chmod -R 777 /www/html/
server {
    listen       80;
    server_name  aaa.domain.com;
    root  /www/html/admin/wwwroot/public/;
    index index.html index.htm index.php;
    location / {     
        # 攔截所有請求,用於偽靜態去掉index.php
if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=$1 last; break; } }
# 攔截所有.php結尾的請求,交給fastcgi_pass選項指定的文件處理,這里就是PHP fpm模塊監聽的地址。可啟用端口監聽或者sock監聽 location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass 127.0.0.1:7131; #fastcgi_pass unix:/run/php/php7.2-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } server { listen 443 ssl ;#配置SSL server_name aaa.domain.com; root /www/html/admin/wwwroot/public/; index index.html index.htm index.php; #################開啟SSL ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #################證書文件地址 ssl_certificate /www/certs/aaa.domain.com/domain_nginx_public.crt; ssl_certificate_key /www/certs/aaa.domain.com/domain_nginx.key; location / { if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=$1 last; break; } } location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass 127.0.0.1:9000; #fastcgi_pass unix:/run/php/php7.2-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }

  

啟動php-fpm,nginx

service php7.2-fpm restart
service nginx restart

查看9000端口是否運行

netstat -lnt | grep 9000

 

安裝Mysql5.7

運行容器

docker run --restart=always --privileged=true --name mysql -d -p 3306:3306 -v /www/mysql/data/:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 mysql:5.7

 

 

參考

https://blog.csdn.net/qq_31953961/article/details/90079814

https://www.zhaokeli.com/article/8496.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM