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 , 配置環(huán)境在 /etc/php/7.2/fpm 內(nèi)有兩個(gè)重要配置文件
php.ini
- 設(shè)置 short_open_tag = On
- extension_dir = "/usr/lib/php/20170718"
- 開啟對mysql的支持:extension=mysqli.so,extension=pdo_mysql.so
- 設(shè)置''cgi.fix_pathinfo=0''
php-fpm.conf
引入配置文件 include=/etc/php/7.2/fpm/pool.d/*.conf 在 /etc/php/7.2/fpm/pool.d/ 目錄下 有個(gè) 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 默認(rèn) root 沒有密碼煌抒,不允許遠(yuǎn)程訪問肯夏,需要命令創(chuàng)建新用戶
-
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/ 目錄下 創(chuàng)建一個(gè)軟鏈接
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/;
}
}
創(chuàng)建軟連接
ln -s /etc/nginx/sites-available/phpmyadmin.conf /etc/nginx/sites-enable/
測試Nginx配置的正確語法:
sudo nginx -t
nginx 重新加載
systemctl restart nginx