ubuntu21.04(linux):用apt安装nginx/php/mysql/phpmyadmin(开发环境)

一,apt方式安装php

说明:用apt方式安装适用于本地开发环境,如果是线上生产环境,建议下载软件后编译安装

root@lhdpc:~# apt-get install php
查看结果:
root@lhdpc:~# php -v
PHP 7.4.16 (cli) (built: Mar 23 2021 16:15:03) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.16, Copyright (c), by Zend Technologies

安装php-fpm

root@lhdpc:~# apt-get install php-fpm
查看文件:
root@lhdpc:~# whereis php-fpm
php-fpm: /usr/sbin/php-fpm7.4
启动服务
root@lhdpc:~# service php7.4-fpm start

说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest

         对应的源码可以访问这里获取: https://github.com/liuhongdi/

说明:作者:刘宏缔 邮箱: 371125307@qq.com

 

二,安装nginx

root@lhdpc:~# apt-get install nginx
查看文件:
root@lhdpc:~# whereis nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx /usr/share/man/man8/nginx.8.gz
启动:
root@lhdpc:~# systemctl start nginx
查看进程:
root@lhdpc:~# ss -lntp
State      Recv-Q     Send-Q  Local Address:Port           Peer Address:Port     Process                                                                                 
LISTEN     0          4096      127.0.0.53%lo:53                  0.0.0.0:*         users:(("systemd-resolve",pid=621,fd=13))                                              
LISTEN     0          128           127.0.0.1:631                 0.0.0.0:*         users:(("cupsd",pid=1416,fd=7))                                                        
LISTEN     0          511            0.0.0.0:80                  0.0.0.0:*         users:(("nginx",pid=11583,fd=6),("nginx",pid=11582,fd=6),("nginx",pid=11581,fd=6))     
LISTEN     0          128              [::1]:631                    [::]:*         users:(("cupsd",pid=1416,fd=6))                                                        
LISTEN     0          511               [::]:80                     [::]:*         users:(("nginx",pid=11583,fd=7),("nginx",pid=11582,fd=7),("nginx",pid=11581,fd=7))     
LISTEN     0          50                   *:1716                      *:*         users:(("kdeconnectd",pid=1254,fd=16))
使nginx支持php:
root@lhdpc:~# cd /etc/nginx/sites-enabled/
root@lhdpc:/etc/nginx/sites-enabled# ls
default
root@lhdpc:/etc/nginx/sites-enabled# vi default
编辑内容:
取消php段的注释,结果如下:
location ~ \.php$ {
                include snippets/fastcgi-php.conf;
        #
        #       # With php-fpm (or other unix sockets):
                fastcgi_pass unix:/run/php/php7.4-fpm.sock;
        #       # With php-cgi (or other tcp sockets):
        #       fastcgi_pass 127.0.0.1:9000;
        }
重启nginx服务:
root@lhdpc:/etc/nginx/sites-enabled# systemctl stop nginx
root@lhdpc:/etc/nginx/sites-enabled# systemctl start nginx

 

三,安装php对mysql的支持:

root@lhdpc:/etc/nginx/sites-enabled# apt-get install php-mysql
 
查看效果:
ubuntu21.04(linux):用apt安装nginx/php/mysql/phpmyadmin(开发环境)

四,安装mysql:

更新apt源:
root@lhdpc:~# apt-get update
安装:
root@lhdpc:~# apt-get install mysql-server 
连接到mysql
root@lhdpc:~# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.25-0ubuntu0.21.04.1 (Ubuntu)
 
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
 
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
 
Type help; or \h for help. Type \c to clear the current input statement.
 
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

说明:此时使用my.ini中的默认密码连接

 
新加账号:
mysql> create user root@127.0.0.1 identified by rootpassword;
Query OK, 0 rows affected (0.01 sec)
 
mysql> grant all on *.* to root@127.0.0.1;
Query OK, 0 rows affected (0.00 sec)
 
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

 

重启服务
root@lhdpc:~# systemctl stop mysql
root@lhdpc:~# systemctl start mysql

五,安装phpmyadmin

下载源文件:
root@lhdpc:/usr/local/source# wget https://files.phpmyadmin.net/phpMyAdmin/5.0.1/phpMyAdmin-5.0.1-all-languages.zip
解压:
root@lhdpc:/usr/local/source# unzip phpMyAdmin-5.0.1-all-languages.zip
移动到documentroot
root@lhdpc:/usr/local/source# mv phpMyAdmin-5.0.1-all-languages /var/www/html/phpmyadmin
生成配置文件:
root@lhdpc:/var/www/html/phpmyadmin# cp config.sample.inc.php config.inc.php
修改一行:
root@lhdpc:/var/www/html/phpmyadmin# vi config.inc.php
内容如下:
//$cfg[‘Servers‘][$i][‘host‘] = ‘localhost‘;
$cfg[Servers][$i][host] = 127.0.0.1;
访问,用root和上面所添加的密码登录
查看效果:
ubuntu21.04(linux):用apt安装nginx/php/mysql/phpmyadmin(开发环境)

六,查看linux的版本:

liuhongdi@lhdpc:/usr/local/source$ cat /etc/os-release 
NAME="Ubuntu"
VERSION="21.04 (Hirsute Hippo)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 21.04"
VERSION_ID="21.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=hirsute
UBUNTU_CODENAME=hirsute

 

ubuntu21.04(linux):用apt安装nginx/php/mysql/phpmyadmin(开发环境)

上一篇:Mysql分页和排序、子查询、聚集函数


下一篇:在MySQL中创建dept,emp,salgrade三张表,以供学习使用