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
 
查看效果:

四,安裝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和上面所添加的密碼登錄
查看效果:

六,查看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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM