Debian手动安装mysql+nginx+laravel+composer环境
2 min read
#apt update -y && apt upgrade -y && apt install vim nano git curl wget sudo -y
#apt install nginx mariadb-client mariadb-server
//先装nginx,下面安装php时,如果出现nginx错误时,将apache2删除掉
#apt remove --purge apache2 && rm -rf /etc/apache2
#apt install php-7.3 php7.3-intl php7.3-gd php7.3-common php7.3-xml php7.3-curl php7.3-mysql php7.3-mbstring php7.3-bcmath php7.3-cli unzip
#adduser username
//添加普通用户,并附sudo权限
$cd ~
$curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php
$sudo php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer
//创建一个laravel应用
#cd /var/www/html/
#mkdir testapp
$composer create-project --prefer-dist laravel/laravel testapp
$cd testapp
$php artisan
$vim .env //编辑配置
//××××××××××××
APP_NAME:应用程序名称,用于通知和消息。
APP_ENV:当前应用环境。
APP_KEY: 用于生成盐和散列,这个唯一的密钥是在通过 Composer 安装 Laravel 时自动创建的,所以你不需要更改它。
APP_DEBUG: 是否在客户端显示调试信息。
APP_URL:应用程序的基本 URL,用于生成应用程序链接。
DB_DATABASE: 数据库名称。
DB_USERNAME: 连接数据库的用户名。
DB_PASSWORD: 连接数据库的密码。
××××××××××××××//
$sudo chown -R www-data:www-data /var/www/html/testapp
$sudo vim /etc/nginx/conf.d/testapp.conf //编辑nginx配置域名服务
//***********
server {
listen 80;
server_name server_domain_or_IP;
root /var/www/travellist/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
***********//
自定义主页
#vim routes/web.php
ps:php8.0
#sudo apt install -y lsb-release ca-certificates apt-transport-https software-properties-common gnupg2
#echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/sury-php.list
#wget -qO - https://packages.sury.org/php/apt.gpg | sudo apt-key add -
#apt-get update -y && apt-get upgrade -y
#apt install php8.0