技术生活

Debian 安装 php, nginx, mysql, wordpress

一、安装php.

sudo apt-get update

sudo apt-get install -y curl wget gnupg2 ca-certificates lsb-release apt-transport-https
wget https://packages.sury.org/php/apt.gpg
sudo apt-key add apt.gpg
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php7.list

sudo apt-get update

sudo apt-get install -y php7.2 php7.2-cli php7.2-common
sudo apt-get install php7.2-fpm

php -v

二、安装mysql.

wget http://repo.mysql.com/mysql-apt-config_0.8.13-1_all.deb
sudo dpkg -i mysql-apt-config_0.8.13-1_all.deb
sudo dpkg-reconfigure mysql-apt-config

sudo apt update 
sudo apt install mysql-server
sudo systemctl restart mysql.service
sudo mysql_secure_installation

#create database and grant privileges
mysql -u *** -p;
CREATE DATABASE IF NOT EXISTS my_db default charset utf8 COLLATE utf8_general_ci;
GRANT ALL PRIVILEGES ON my_db.* TO 'username'@'localhost' IDENTIFIED BY 'password';
exit

#import data to database from backup.sql
mysql -u *** -p my_db < backup.sql
#export data to backup.sql from database
mysqldump -u *** -p my_db > backup.sql

三、安装nginx.

sudo apt-get update
sudo apt-get install nginx

root /var/www/site_root_folder

四、配置nginx.

sudo nano /etc/nginx/sites-available/default

#root folder
root /var/www/site_root_folder

#Add index.php
index index.php index.html index.htm index.nginx-debian.html;

#server_name _;
server_name domain_a domain_b

# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        # With php-fpm (or other unix sockets):
        fastcgi_pass unix:/run/php/php7.2-fpm.sock;
        #       # With php-cgi (or other tcp sockets):
        #       fastcgi_pass 127.0.0.1:9000;
}

五、配置SSL.

sudo apt update
sudo apt install python3-acme python3-certbot python3-mock python3-openssl python3-pkg-resources python3-pyparsing python3-zope.interface

sudo apt install python3-certbot-nginx

/etc/nginx/sites-available/your_domain
...
server_name your_domain www.your_domain;
...

sudo nginx -t
sudo systemctl reload nginx
sudo certbot --nginx -d your_domain -d www.your_domain
sudo certbot renew --dry-run

六、引用与参考:

  1. https://www.itzgeek.com/how-tos/linux/debian/how-to-install-php-7-3-7-2-7-1-on-debian-10-debian-9-debian-8.html
  2. https://tecadmin.net/install-mysql-on-debian-10-buster/
  3. https://www.digitalocean.com/community/tutorials/how-to-install-wordpress-with-lemp-nginx-mariadb-and-php-on-debian-10
  4. https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-debian-10

发表评论

电子邮件地址不会被公开。 必填项已用*标注