C2/C3 Wiki

C2/C3开发者的乐园

用户工具

站点工具


ubuntu_nginx_php-fpm_mysql_redis

差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

两侧同时换到之前的修订记录前一修订版
后一修订版
前一修订版
ubuntu_nginx_php-fpm_mysql_redis [2018/03/25 15:52] Avenubuntu_nginx_php-fpm_mysql_redis [2025/09/17 09:14] (当前版本) Aven
行 1: 行 1:
-====== ubuntu+Nginx+php-fpm+Mysql+Redis ======+====== ubuntu+Nginx+php-fpm+Mysql+Redis+ssl ====== 
 ===== 安装LNMP环境 ===== ===== 安装LNMP环境 =====
 +
 +首先,墙裂推荐一套工具:[[https://winscp.net/eng/docs/lang:chs|WinSCP]]+[[https://www.putty.org/|Putty]],管理文件方便很多。Mac版用[[http://soft.macx.cn/2647.htm|Coda]]。
 +
 ==== 基础环境 ==== ==== 基础环境 ====
 <code> <code>
 +
 +apt-get update
 apt-get install nginx mysql-server php     * 注意 期间会要求输入MySQL的root密码 apt-get install nginx mysql-server php     * 注意 期间会要求输入MySQL的root密码
 +
 </code> </code>
 +
 ==== 配置Nginx支持PHP ==== ==== 配置Nginx支持PHP ====
 +
 <code> <code>
 vi /etc/nginx/sites-available/default vi /etc/nginx/sites-available/default
行 16: 行 25:
 #    # With php7.0-cgi alone; #    # With php7.0-cgi alone;
 #    fastcgi_pass 127.0.0.1:9000; #    fastcgi_pass 127.0.0.1:9000;
-#    # With php7.0-fpm; +#    # With php7.2-fpm; 
-    fastcgi_pass unix:/run/php/php7.0-fpm.sock;+    fastcgi_pass unix:/run/php/php7.2-fpm.sock;
 } }
 ...... ......
  
- +vi /etc/php/7.2/fpm/php-fpm.conf
-vi /etc/php/7.0/fpm/php-fpm.conf+
 ........... ...........
-listen = /run/php/php7.0-fpm.sock+listen = /run/php/php7.2-fpm.sock
  
 </code> </code>
 +
 ==== 重启Nginx ==== ==== 重启Nginx ====
 +
 <code> <code>
 nginx -s stop nginx -s stop
 nginx nginx
 +
 </code> </code>
 +
 +这里有可能出现找不到pid的情况,可能是因为阿里云服务器自动启动了apache,只要把它关掉就行
 +
 +<code>
 +netstat -ap | grep http
 +kill xxxxx(apache的pid)
 +
 +</code>
 +
 +关闭Apache2自启动,需要找到etc/rc0.d ~ rcx.d/目录下所有 S01apache2文件
 +
 +或直接卸载Apache2
 +<code>
 +
 +update-rc.d apache2 stop 80 0 1 2 3 4 5 6
 +或一个个删除
 +sudo mv S01apache2  K01apache2
 +
 +sudo apt-get remove apache2
 +
 +</code>
 +
 ==== 测试PHP ==== ==== 测试PHP ====
 +
 <code> <code>
 vi /var/www/html/info.php vi /var/www/html/info.php
 <?php phpinfo();?> <?php phpinfo();?>
 +
 </code> </code>
 +
 +修改 short_open_tag
 +
 +<code>
 +vi /etc/php/7.2/fpm/php.ini
 +找到 short_open_tag = Off
 +改为 short_open_tag = On
 +
 +</code>
 +
 +修改上传文件设置
 +
 +<code>
 +php.ini
 +upload_max_filesize = 128M
 +post_max_size = 128M
 +memory_limit = 256M
 +
 +nginx.conf
 +client_max_body_size 100M;
 +
 +</code>
 +需重启php和nginx
 +
 +安装curl扩展
 +
 +<code>
 +apt-get install php7.2-curl libcurl4 libcurl4-dev php-curl
 +apt-get install php-mbstring
 +
 +</code>
 +
 ===== 安装redis ===== ===== 安装redis =====
 +
 ==== 安装和配置redis ==== ==== 安装和配置redis ====
 +
 <code> <code>
 apt-get install redis-server apt-get install redis-server
行 48: 行 117:
 make make
 make install make install
 +
 </code> </code>
 +
 ==== 启动和测试Redis ==== ==== 启动和测试Redis ====
 +
 <code> <code>
 redis-server /etc/redis/redis.conf redis-server /etc/redis/redis.conf
->Ping+redis-cli>Ping 
 Pong Pong
 +
 </code> </code>
 +
 +配置权限
 +
 +<code>>config set masterauth   123456
 +>config set requirepass   123456
 +>config rewrite
 +
 +(error) NOAUTH Authentication required.
 +>auth 123456
 +>config rewrite
 +
 +ok
 +
 +</code>
 +
 ==== 配置php-redis ==== ==== 配置php-redis ====
 +
 <code> <code>
-vi /etc/php/7.0/fpm/conf.d/redis.ini   * 注意 并无此文件 直接创建+vi /etc/php/7.2/fpm/conf.d/redis.ini   * 注意 并无此文件 直接创建
 extension=redis.so extension=redis.so
 +
 </code> </code>
 +
 +==== 配置mysqli ====
 +
 +<code>
 +apt-get install php-mysqli
 +vi /etc/php/7.0/fpm/php.ini  * 在文件最后添加
 +extension="mysqli.so"
 +
 +</code>
 +
 ==== 重启fpm ==== ==== 重启fpm ====
 +
 <code> <code>
 /etc/init.d/php7.0-fpm restart /etc/init.d/php7.0-fpm restart
 +
 </code> </code>
 +
 ===== 启动MySQL ===== ===== 启动MySQL =====
 +
 <code> <code>
 service mysql start service mysql start
-mysql -uroot -p    * 注意 期间会要求验证之前输入的MySQL root密码 +mysql -u root -p    * 注意 期间会要求验证之前输入的MySQL root密码>SET NAMES utf8; 
->SET NAMES utf8;+ 
 +Query OK, 0 rows affected (0.00 sec) 
 </code> </code>
 +
 +如果此时发现Mysql密码并未设置(按回车直接可进)则可以执行以下动作
 +
 +<code>>use mysql;>update user set authentication_string=password('新密码') where user='root';
 +
 +</code>
 +
 +==== 修改mysql配置文件允许远程登陆 ====
 +
 +<code>
 +/etc/mysql/mysql.conf.d/mysqld.cnf
 +
 +# Instead of skip-networking the default is now to listen only on
 +# localhost which is more compatible and is not less secure.
 +#bind-address        = 127.0.0.1        #注释掉这一行就可以远程登录了
 +
 +</code>
 +
 +===== HTTPS支持 =====
 +
 +把证书保存到 /etc/nginx/cert/
 +
 +<code>
 +vi /etc/nginx/sites-available/default
 +
 +在最后添加配置
 +
 +server {
 +    # SSL configuration
 +
 +    listen 443 ssl default_server;
 +    listen [::]:443 ssl default_server;
 +
 +    #ssl on;
 +    ssl_certificate   cert/你的pem文件名.pem;
 +    ssl_certificate_key  cert/你的key文件名.key;
 +    ssl_session_timeout 5m;
 +    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
 +    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
 +    ssl_prefer_server_ciphers on;
 +
 +    root /var/www/html;
 +
 +    # 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-php.conf;
 +        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
 +    }
 +
 +}
 +
 +</code>
 +
 +===== HTTPS支持 =====
 +=== 简单方案 ===
 +[[给nginx挂上免费的ssl|Ubuntu+Nginx+免费SSL]]
 +
 +=== 自定义方案 ===
 +把证书保存到 /etc/nginx/cert/
 +
 +<code>
 +vi /etc/nginx/sites-available/default
 +
 +在最后添加配置
 +
 +server {
 +    # SSL configuration
 +
 +    listen 443 ssl default_server;
 +    listen [::]:443 ssl default_server;
 +
 +    #ssl on;
 +    ssl_certificate   cert/你的pem文件名.pem;
 +    ssl_certificate_key  cert/你的key文件名.key;
 +    ssl_session_timeout 5m;
 +    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
 +    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
 +    ssl_prefer_server_ciphers on;
 +
 +    root /var/www/html;
 +
 +    # 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-php.conf;
 +        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
 +    }
 +
 +}
 +
 +</code>
 +
 +
ubuntu_nginx_php-fpm_mysql_redis.1521964360.txt.gz · 最后更改: (外部编辑)