ubuntu21.04(linux):用apt安装nginx/php/mysql/phpmyadmin(开发环境)
2023-09-14 08:59:32 时间
一,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
查看效果:
![](https://img2020.cnblogs.com/blog/1938691/202106/1938691-20210619213633067-961707322.png)
四,安装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和上面所添加的密码登录
查看效果:
![](https://img2020.cnblogs.com/blog/1938691/202106/1938691-20210619213633089-884900428.png)
六,查看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
相关文章
- [PHP] ubuntu16.04配置Lamp环境(搭建linux+apache+mysql+php7环境)
- Mysql:is not allowed to connect to this MySQL server
- Linux下,如何给PHP安装pdo_mysql扩展
- 【MySQL】一次修改mysql 默认路径的经历
- Linux - mysql 异常: ERROR! MySQL is not running, but lock file (/var/lock/subsys/mysql) exists
- linux - mysql 异常:MySQL Daemon failed to start.
- linux - mysql:安装mysql
- XtraBackup出现 Can't connect to local MySQL server through socket '/tmp/mysql.sock'
- Linux + apache + php + mysql
- 使用mysql-connector-python操作MYSQL数据库
- CentOS下httpd下php 连接mysql 本机可以,外网报错Could not connect: Can't connect to MySQL server on '127.0.0.1' (13)2003 原因解析
- Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’
- PHP连接MySQL数据库的三种方式(mysql、mysqli、pdo)
- Linux CentOS6.5下编译安装MySQL 5.6.16【给力详细教程】
- Linux下MySQL源码编译安装(eg:mysql-5.6.27.tar.gz )
- Linux复习资料——MySQL-client-5.6.50-1.el7.x86_64与MySQL-server-5.6.50-1.el7.x86_64包安装MySQL全过程
- linux下源代码搭建php环境之mysql(一)
- 嵌入式Linux开发,Ubuntu下交叉编译内核报错:error while loading shared libraries: /lib/x86_64-linux-gnu/libc++.so:
- linux 配置apache、mysql、php ——20150807
- Linux【实操篇】—— 用户管理、linux系统root密码找回方式
- MySql高级----Linux下的mysql的安装与初始化配置
- 【Mysql异构实时同步Oracle】OGG12异构同步mysql到oracle(windows mysql实时同步数据到linux oracle)详细文档
- 解决办法:Linux mysql命令 -bash: mysql: command not found 找不到命令