Ubuntu18.04 + MySQL + phpMyAdmin + Nginx
安装 软件
apt install nginx
add-apt-repository ppa:ondrej/php
apt-get update
apt-get install php7.2 php-fpm php-mysql php-mbstring
apt-get install mysql-server
apt-get install phpmyadmin
安装完php7.2 , 配置环境在 /etc/php/7.2/fpm 内有两个重要配置文件
php.ini
- 设置 short_open_tag = On
- extension_dir = "/usr/lib/php/20170718"
- 开启对mysql的支持:extension=mysqli.so,extension=pdo_mysql.so
- 设置''cgi.fix_pathinfo=0''
php-fpm.conf
-
引入配置文件 include=/etc/php/7.2/fpm/pool.d/*.conf 在 /etc/php/7.2/fpm/pool.d/ 目录下 有个 www.conf 文件
-
在 www.conf 找到 listen = /run/php/php7.2-fpm.sock, 后面配置 nginx 需要用到
-
重启 php-fpm7.2
/etc/init.d/php7.2-fpm restart
## or
systemctl enable php7.2-fpm
systemctl restart php7.2-fpm
MySQL5.7 默认 root 没有密码,不允许远程访问,需要命令创建新用户
-
Connect to mysql
sudo mysql --user=root mysql
-
Create a user for phpMyAdmin
CREATE USER 'demo'@'localhost' IDENTIFIED BY 'some_pass'; GRANT ALL PRIVILEGES ON *.* TO 'demo'@'localhost' WITH GRANT OPTION; FLUSH PRIVILEGES;
-
Optional: allow remote connections
CREATE USER 'phpmyadmin'@'%' IDENTIFIED BY 'some_pass'; GRANT ALL PRIVILEGES ON *.* TO 'phpmyadmin'@'%' WITH GRANT OPTION; FLUSH PRIVILEGES;
安装后的 的phpmyadmin 目录是在 /usr/share/phpmyadmin
- 我们需要在 /var/www/ 目录下 创建一个软链接
ln -s /usr/share/phpmyadmin /var/www/
- 编写 phpmyadmin.conf 配置文件, 在 /etc/nginx/sites-available 目录下
server{
listen 80;
root /var/www/phpmyadmin;
index index.php;
server_name phpmyadmin.example.top;
rewrite ^(.*)$ https://$host$1 permanent;
}
server{
access_log /var/www/logs/phpmyadmin_access.log;
error_log /var/www/logs/phpmyadmin_error.log;
listen 443 ssl http2;
root /var/www/phpmyadmin;
index index.php;
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";
ssl on;
ssl_certificate /root/.acme.sh/*.example.top/fullchain.cer;
ssl_certificate_key /root/.acme.sh/*.example.top/*.example.top.key;
#ssl_certificate /root/.acme.sh/example.top/fullchain.cer;
#ssl_certificate_key /root/.acme.sh/example.top/example.top.key;
ssl_prefer_server_ciphers on;
ssl_session_timeout 10m;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers TLS13-AES-256-GCM-SHA384:TLS13-AES-128-GCM-SHA256:EECDH+ECDSA+AES256:EECDH+aRSA+AES256:EECDH+ECDSA+AES128:EECDH+aRSA+AES128!MD5;
server_name phpmyadmin.example.top;
#location / {
# index index.html;
# root /var/www/html;
#}
#location /phpmyadmin{
location / {
index index.php;
root /var/www/phpmyadmin/;
#try_files $uri $uri/ /phpmyadmin/index.php?$args;
}
location ~ .php$ {
root /var/www/phpmyadmin/;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ .(htm|html|gif|jpg|png|js|css)$ {
root /var/www/phpmyadmin/;
}
}
测试Nginx配置的正确语法:
sudo nginx -t
nginx 重新加载
systemctl restart nginx
网友评论