安装PHP拓展
sudo apt-get install -y php php-fpm php-curl php-gd php-intl php-mbstring php-mysql php-imap php-opcache php-sqlite3 php-xml php-xmlrpc php-zip
查看php版本 验证是否成功
php -v
安装Nginx
sudo apt-get install nginx
验证nginx是否成功 安装curl、nano编辑器、wget
apt-get install curl nano wget
curl 127.0.0.1
找到index配置,添加index.php
sudo nano /etc/nginx/sites-enabled/default
找到# pass PHP scripts to FastCGI server后面的location 删除注释如下
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
fastcgi_pass unix:/run/php/php7.3-fpm.sock;
# # With php-cgi (or other tcp sockets):
#fastcgi_pass 127.0.0.1:9000;
}
重启nginx 验证php
sudo systemctl restart nginx
sudo nano /var/www/html/phpinfo.php
新建phpinfo.php文件验证,文件内容为
<?php
phpinfo();
浏览器访问:http://127.0.0.1/phpinfo.php 即可看到PHP探针信息。
安装MySql
sudo apt-get install mariadb-server mariadb-client
sudo mysql_secure_installation
参考
sudo vi /etc/mysql/mariadb.conf.d/50-server.cnf
将bind-address这行注释掉
或者将127.0.0.1 这个值改为 0.0.0.0
然后重启
sudo systemctl restart mariadb.service
设置远程访问权限
mysql -u root -p
use mysql;
例如账号root 密码rootpwd
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'rootpwd' WITH GRANT OPTION;
flush privileges;
ctrl + c 退出界面,执行命令重启服务
sudo systemctl restart mariadb.service
查看mysql服务状态
sudo systemctl status mariadb.service
上传程序包到该目录
cd /var/www/html/
将网站目录文件全部授权777
chmod -R 777 ./html
环境搭建完成