这里会显示出您选择的修订版和当前版本之间的差别。
| 两侧同时换到之前的修订记录前一修订版后一修订版 | 前一修订版 | ||
| ubuntu_nginx_php-fpm_mysql_redis [2020/12/26 04:57] – [修改mysql配置文件允许远程登陆] Aven | ubuntu_nginx_php-fpm_mysql_redis [2025/09/17 09:14] (当前版本) – Aven | ||
|---|---|---|---|
| 行 2: | 行 2: | ||
| ===== 安装LNMP环境 ===== | ===== 安装LNMP环境 ===== | ||
| + | |||
| 首先,墙裂推荐一套工具:[[https:// | 首先,墙裂推荐一套工具:[[https:// | ||
| - | ==== 基础环境 ==== | ||
| + | ==== 基础环境 ==== | ||
| < | < | ||
| + | |||
| apt-get update | apt-get update | ||
| apt-get install nginx mysql-server php * 注意 期间会要求输入MySQL的root密码 | apt-get install nginx mysql-server php * 注意 期间会要求输入MySQL的root密码 | ||
| + | |||
| </ | </ | ||
| 行 22: | 行 25: | ||
| # # With php7.0-cgi alone; | # # With php7.0-cgi alone; | ||
| # fastcgi_pass 127.0.0.1: | # fastcgi_pass 127.0.0.1: | ||
| - | # # With php7.0-fpm; | + | # # With php7.2-fpm; |
| - | fastcgi_pass unix:/ | + | fastcgi_pass unix:/ |
| } | } | ||
| ...... | ...... | ||
| - | vi /etc/php/7.0/ | + | vi /etc/php/7.2/ |
| ........... | ........... | ||
| - | listen = / | + | listen = / |
| </ | </ | ||
| 行 37: | 行 41: | ||
| nginx -s stop | nginx -s stop | ||
| nginx | nginx | ||
| + | |||
| </ | </ | ||
| + | |||
| 这里有可能出现找不到pid的情况,可能是因为阿里云服务器自动启动了apache,只要把它关掉就行 | 这里有可能出现找不到pid的情况,可能是因为阿里云服务器自动启动了apache,只要把它关掉就行 | ||
| + | |||
| < | < | ||
| netstat -ap | grep http | netstat -ap | grep http | ||
| kill xxxxx(apache的pid) | kill xxxxx(apache的pid) | ||
| + | |||
| </ | </ | ||
| + | |||
| + | 关闭Apache2自启动,需要找到etc/ | ||
| + | |||
| + | 或直接卸载Apache2 | ||
| + | < | ||
| + | |||
| + | update-rc.d apache2 stop 80 0 1 2 3 4 5 6 | ||
| + | 或一个个删除 | ||
| + | sudo mv S01apache2 | ||
| + | |||
| + | sudo apt-get remove apache2 | ||
| + | |||
| + | </ | ||
| + | |||
| ==== 测试PHP ==== | ==== 测试PHP ==== | ||
| 行 48: | 行 70: | ||
| vi / | vi / | ||
| <?php phpinfo();?> | <?php phpinfo();?> | ||
| + | |||
| </ | </ | ||
| 行 53: | 行 76: | ||
| < | < | ||
| - | vi /etc/php/7.0/ | + | vi /etc/php/7.2/ |
| 找到 short_open_tag = Off | 找到 short_open_tag = Off | ||
| 改为 short_open_tag = On | 改为 short_open_tag = On | ||
| + | |||
| </ | </ | ||
| + | |||
| + | 修改上传文件设置 | ||
| + | |||
| + | < | ||
| + | php.ini | ||
| + | upload_max_filesize = 128M | ||
| + | post_max_size = 128M | ||
| + | memory_limit = 256M | ||
| + | |||
| + | nginx.conf | ||
| + | client_max_body_size 100M; | ||
| + | |||
| + | </ | ||
| + | 需重启php和nginx | ||
| 安装curl扩展 | 安装curl扩展 | ||
| < | < | ||
| - | apt-get install curl libcurl3 libcurl3-dev php-curl | + | apt-get install |
| + | apt-get install php-mbstring | ||
| </ | </ | ||
| 行 77: | 行 117: | ||
| make | make | ||
| make install | make install | ||
| + | |||
| </ | </ | ||
| 行 86: | 行 127: | ||
| Pong | Pong | ||
| + | |||
| </ | </ | ||
| 行 94: | 行 136: | ||
| >config rewrite | >config rewrite | ||
| - | (error) NOAUTH Authentication required.> | + | (error) NOAUTH Authentication required. |
| + | >auth 123456 | ||
| >config rewrite | >config rewrite | ||
| ok | ok | ||
| + | |||
| </ | </ | ||
| 行 103: | 行 147: | ||
| < | < | ||
| - | vi /etc/php/7.0/ | + | vi /etc/php/7.2/ |
| extension=redis.so | extension=redis.so | ||
| + | |||
| </ | </ | ||
| 行 113: | 行 158: | ||
| vi / | vi / | ||
| extension=" | extension=" | ||
| + | |||
| </ | </ | ||
| 行 119: | 行 165: | ||
| < | < | ||
| / | / | ||
| + | |||
| </ | </ | ||
| 行 125: | 行 172: | ||
| < | < | ||
| service mysql start | service mysql start | ||
| - | mysql -uroot -p * 注意 期间会要求验证之前输入的MySQL root密码> | + | mysql -u root -p * 注意 期间会要求验证之前输入的MySQL root密码> |
| Query OK, 0 rows affected (0.00 sec) | Query OK, 0 rows affected (0.00 sec) | ||
| + | |||
| + | </ | ||
| + | |||
| + | 如果此时发现Mysql密码并未设置(按回车直接可进)则可以执行以下动作 | ||
| + | |||
| + | < | ||
| + | |||
| </ | </ | ||
| ==== 修改mysql配置文件允许远程登陆 ==== | ==== 修改mysql配置文件允许远程登陆 ==== | ||
| + | |||
| < | < | ||
| / | / | ||
| 行 136: | 行 191: | ||
| # Instead of skip-networking the default is now to listen only on | # Instead of skip-networking the default is now to listen only on | ||
| # localhost which is more compatible and is not less secure. | # localhost which is more compatible and is not less secure. | ||
| - | # | + | # |
| </ | </ | ||
| ===== HTTPS支持 ===== | ===== HTTPS支持 ===== | ||
| + | |||
| 把证书保存到 / | 把证书保存到 / | ||
| + | |||
| < | < | ||
| vi / | vi / | ||
| 行 147: | 行 205: | ||
| server { | server { | ||
| - | # SSL configuration | + | |
| - | listen 443 ssl default_server; | + | |
| - | listen [::]:443 ssl default_server; | + | listen [::]:443 ssl default_server; |
| - | #ssl on; | + | |
| - | ssl_certificate | + | ssl_certificate |
| - | ssl_certificate_key | + | ssl_certificate_key |
| - | ssl_session_timeout 5m; | + | ssl_session_timeout 5m; |
| - | ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256: | + | ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256: |
| - | ssl_protocols TLSv1 TLSv1.1 TLSv1.2; | + | ssl_protocols TLSv1 TLSv1.1 TLSv1.2; |
| - | ssl_prefer_server_ciphers on; | + | ssl_prefer_server_ciphers on; |
| - | root / | + | |
| - | # Add index.php to the list if you are using PHP | + | |
| - | index index.html index.htm index.php; | + | index index.html index.htm index.php; |
| - | server_name 你的域名; | + | |
| - | location / { | + | |
| - | # First attempt to serve request as file, then | + | # First attempt to serve request as file, then |
| - | # as directory, then fall back to displaying a 404. | + | # as directory, then fall back to displaying a 404. |
| - | try_files $uri $uri/ =404; | + | try_files $uri $uri/ =404; |
| - | } | + | } |
| - | location ~ \.php$ { | + | |
| - | include snippets/ | + | include snippets/ |
| - | fastcgi_pass unix:/ | + | fastcgi_pass unix:/ |
| - | } | + | } |
| } | } | ||
| + | |||
| </ | </ | ||
| + | |||
| + | ===== HTTPS支持 ===== | ||
| + | === 简单方案 === | ||
| + | [[给nginx挂上免费的ssl|Ubuntu+Nginx+免费SSL]] | ||
| + | |||
| + | === 自定义方案 === | ||
| + | 把证书保存到 / | ||
| + | |||
| + | < | ||
| + | vi / | ||
| + | |||
| + | 在最后添加配置 | ||
| + | |||
| + | server { | ||
| + | # SSL configuration | ||
| + | |||
| + | listen 443 ssl default_server; | ||
| + | listen [::]:443 ssl default_server; | ||
| + | |||
| + | #ssl on; | ||
| + | ssl_certificate | ||
| + | ssl_certificate_key | ||
| + | ssl_session_timeout 5m; | ||
| + | ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256: | ||
| + | ssl_protocols TLSv1 TLSv1.1 TLSv1.2; | ||
| + | ssl_prefer_server_ciphers on; | ||
| + | |||
| + | root / | ||
| + | |||
| + | # Add index.php to the list if you are using PHP | ||
| + | index index.html index.htm index.php; | ||
| + | |||
| + | 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; | ||
| + | } | ||
| + | |||
| + | location ~ \.php$ { | ||
| + | include snippets/ | ||
| + | fastcgi_pass unix:/ | ||
| + | } | ||
| + | |||
| + | } | ||
| + | |||
| + | </ | ||
| + | |||