Ubantu虚拟机PHP+Nginx+Mysql8.0+Composer+xshell环境安装

Ubantu虚拟机环境安装

Ubuntu安装Nginx

安装

安装包安装命令

sudo apt-get install nginx

更新源

sudo apt-get update

更新已安装的包

sudo apt-get upgrade

目录

名称目录
配置文件/etc/nginx/nginx.conf
程序文件/usr/sbin/nginx
日志/var/log/nginx
默认虚拟主机/var/www/html

命令

namecommand
启动sudo /etc/init.d/nginx start
停止sudo /etc/init.d/nginx stop
重启sudo /etc/init.d/nginx restart
状态sudo /etc/init.d/nginx status
namecommand
查看状态$ sudo systemctl status nginx.service
开启 nginx 服务$ sudo systemctl start nginx.service
重启服务$ sudo systemctl restart nginx.service
查看所有服务$ sudo systemctl list-units --type=servic

配置

安装完之后,需要配置一下nginx。

在/etc/nginx/sites-enable/defaul文件里
		
打开location ~ \.php$处的注释

把fastcgi_pass配置如下:

fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;【注意PHP的版本】

Ubuntu安装php

命令

apt-get update && apt-get upgrade
sudo apt-get install --dry-run php
sudo apt-get install php

安装完成,命令 php-v 可查看PHP版本

查看PHP所有扩展

apt-cache search --names-only ^php | grep "php7.4"

安装扩展

apt-get install php7.4-xml

所有扩展

php7.4 - server-side, HTML-embedded scripting language (metapackage)
php7.4-cgi - server-side, HTML-embedded scripting language (CGI binary)
php7.4-cli - command-line interpreter for the PHP scripting language
php7.4-common - documentation, examples and common module for PHP
php7.4-curl - CURL module for PHP
php7.4-dev - Files for PHP7.4 module development
php7.4-gd - GD module for PHP
php7.4-gmp - GMP module for PHP
php7.4-json - JSON module for PHP
php7.4-ldap - LDAP module for PHP
php7.4-mysql - MySQL module for PHP
php7.4-odbc - ODBC module for PHP
php7.4-opcache - Zend OpCache module for PHP
php7.4-pgsql - PostgreSQL module for PHP
php7.4-pspell - pspell module for PHP
php7.4-readline - readline module for PHP
php7.4-snmp - SNMP module for PHP
php7.4-sqlite3 - SQLite3 module for PHP
php7.4-tidy - tidy module for PHP
php7.4-xml - DOM, SimpleXML, XML, and XSL module for PHP
php7.4-xmlrpc - XMLRPC-EPI module for PHP
libphp7.4-embed - HTML-embedded scripting language (Embedded SAPI library)
php7.4-bcmath - Bcmath module for PHP
php7.4-bz2 - bzip2 module for PHP
php7.4-dba - DBA module for PHP
php7.4-enchant - Enchant module for PHP
php7.4-fpm - server-side, HTML-embedded scripting language (FPM-CGI binary)
php7.4-imap - IMAP module for PHP
php7.4-interbase - Interbase module for PHP
php7.4-intl - Internationalisation module for PHP
php7.4-mbstring - MBSTRING module for PHP
php7.4-phpdbg - server-side, HTML-embedded scripting language (PHPDBG binary)
php7.4-soap - SOAP module for PHP
php7.4-sybase - Sybase module for PHP
php7.4-xsl - XSL module for PHP (dummy)
php7.4-zip - Zip module for PHP

命令

namecommand
启动$ sudo service php7.4-fpm start
停止$ sudo service php7.4-fpm stop
重启$ sudo service php7.4-fpm restart
状态$ sudo service php7.4-fpm reload

ubuntu 下 PHP-FPM + Nginx 环境搭建

nginx.conf 配置文件

http {

...
...
省略部分代码,不用修改
...
...

       include /etc/nginx/conf.d/*.conf;
       include /etc/nginx/sites-enabled/*;
       include /etc/nginx/vhost/项目的配置文件;
       include /etc/nginx/vhost/项目的配置文件;
}

vhost下项目的配置文件


server {
        listen        80;
        server_name  域名;
        root   项目根目录;

        location / {
            index index.php index.html error/index.html;

            try_files $uri $uri/ /index.php?$query_string;
            autoindex  off;
        }
        location ~ \.php(.*)$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass   unix:/run/php/php7.4-fpm.sock;
        }
}


Ubuntu安装mysql

安装MySQL8.x 命令

sudo apt-get install mysql-server

配置MySQL

开始初始化

sudo mysql_secure_installation
#1
VALIDATE PASSWORD PLUGIN can be used to test passwords...
Press y|Y for Yes, any other key for No: N (我的选项)
 
#2
Please set the password for root here...
New password: (输入密码)
Re-enter new password: (重复输入)
 
#3
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them...
Remove anonymous users? (Press y|Y for Yes, any other key for No) : N (我的选项)
 
#4
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network...
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y (我的选项)
 
#5
By default, MySQL comes with a database named 'test' that
anyone can access...
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : N (我的选项)
 
#6
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y (我的选项)

检查mysql服务状态:

systemctl status mysql.service

配置远程访问

授权root用户可以远程登陆
GRANT ALL ON *.* TO 'root'@'%';
刷新权限
flush privileges;
修改加密规则
ALTER USER 'root'@'localhost' IDENTIFIED BY 'yourpassword' PASSWORD EXPIRE NEVER;
更新 root 用户密码
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'yourpassword';
刷新权限
FLUSH PRIVILEGES

测试连接。用 Navicat 连接数据库就可以正常连接了。

Ubuntu如何开启root账户登录

以普通用户登录系统,创建root用户的密码

1.以普通用户登录系统,创建root用户的密码
sudo passwd root
2.先输入当前普通用户(如用户coco)的密码,用于提权。
3.然后再输入为root用户所设置的密码,输入两次,这样就完成设置root用户密码了(注意Linux系统下密码是没有回显的)

修改50-ubuntu.conf文件

1.在终端输入命令:
sudo gedit /usr/share/lightdm/lightdm.conf.d/50-ubuntu.conf
2.在文件末尾增加如下两行并保存:
greeter-show-manual-login=true #手工输入登陆系统的用户名和密码
allow-guest=false #不允许guest登录(可选)

修改gdm-autologin文件

1.在终端输入命令:
sudo gedit /etc/pam.d/gdm-autologin
2.在第三行前面加#以注释掉auth required pam_succeed_if.so user != root quiet_success,随后保存并退出

修改gdm-password文件

1.在终端输入命令:
sudo gedit /etc/pam.d/gdm-password
2.在第三行前面加#以注释掉auth required pam_succeed_if.so user != root quiet_success,随后保存并退出

修改/root/.profile文件

1.在终端输入命令:
sudo gedit /root/.profile
2.将文件末尾的mesg n 2> /dev/null || true这一行注释掉,并随后添加:
tty -s&&mesg n || true

注销当前用户,登录root用户

一般修改完配置后最好重启一下
reboot

Ubantu 链接xshell

开启SSH服务,需要开启openssh-server

sudo apt-get install openssh-server

启动

root@ubuntu:~# ps -e | grep ssh
如果只有ssh-agent表示还没启动,需要
root@ubuntu:~# /etc/init.d/ssh start

编辑一下/etc/ssh/sshd_config文件

root@ubuntu:~# /etc/ssh/sshd_config 
将 PermitRootLogin改为yes:

重启ssh-server即可

root@ubuntu:~# sudo /etc/init.d/ssh restart

ubuntu 全局安装composer

安装

apt install curl
curl -sS https://getcomposer.org/installer | php

这样要这样运行composer

php composer.phar

把composer.phar移动至

 mv composer.phar /usr/local/bin/composer

##composer忽略版本匹配

提示我的PHP 7版本太高,不符合composer.json需要的版本,但是在PHP 7下应该也是可以运行的,composer可以设置忽略版本匹配,命令是:
composer install --ignore-platform-reqs
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

葛小伦的大哥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值