Linux (Ubuntu系统)安装 php7.2+nginx+mysql

本文详细介绍在Ubuntu 18.04系统中搭建LAMP(Linux、Apache、MySQL、PHP)环境的完整过程,包括环境准备、软件安装、配置调整及测试访问,适用于Windows下运行的Ubuntu子系统。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

目录

 

1、环境准备

2、步骤操作

3、参考


1、安装环境准备

ubuntu 18.04 (适用windows运行方式)

版本:PHP-7.2 ;Nginx-1.14; Mysql-5.7

2、操作步骤

Step_1:检测软件包列表

sudo apt list 
sudo apt search all | grep php 

Step_2:更新软件包

sudo apt update
sudo apt upgrade

Step_3:安装软件包

sudo apt install nginx 
sudo apt install php7.2
sudo apt install php7.2-fpm
sudo apt install mysql

启动服务:

Nginx服务:
service nginx start #启动服务
ps -ef | grep nginx #查看运行状态
nginx -v #版本号

PHP服务:
service php7.2-fpm start 
ps -ef | grep php-7.2-fpm
php -v 

MYsql服务:
service mysql start
ps -ef | grep mysql 

Step_4:配置环境

Nginx配置:

1.创建配置文件 并 建立软链接(方便开启或关闭配置)

cp /etc/nginx/sites-available/default  /etc/nginx/sites-available/default.conf
ln -s /etc/nginx/sites-enabled/default.conf /etc/nginx/sites-available/default.conf

2. 配置端口 80;root目录;server_name;

开启include snippets/fastcgi-php.conf;和fastcgi_pass unix:/var/run/php7.2-fpm.sock;

server {
        listen 80;
        #listen [::]:80 default_server;

        # SSL configuration
        #
        # listen 443 ssl default_server;
        # listen [::]:443 ssl default_server;
        #
        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
        #
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See: https://bugs.debian.org/765782
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;

        #root /var/www/html;
        root /srv/web;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        server_name www.ps.cn;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        location ~ /\.ht {
                deny all;
        }
}
user:www-data #用户配置
#权限查看
cat /etc/passwd | grep 用户
cat /etc/group | grep 组名
whoami #当前用户

#权限设置
chown -R www-data:www-data /srv/www/
groupadd www-data
useradd -s /sbin/nologin -g www-data www-data

3.检测并重启nginx:

service nginx -t #检查配置是否成功

service nginx restart #重启nginx服务
service php7.2-fpm restart #重启php服务

依赖检查及启动:

systemctl enable php-fpm #开机启动

netstat -lnt | grep 9000 #端口检测 使用端口时
whereis php-fpm #实用查找
echo "<?php phpinfo(); ?>" > index.php

 

Step_5:访问测试

浏览器虚拟IP访问,输出phpinfo信息。

配置windows hosts文件,添加新一行内容

# localhost name resolution is handled within DNS itself.
#	127.0.0.1       localhost
#	::1             localhost

127.0.0.1       localhost
127.0.0.1       www.ps.cn # 新增虚拟机ip对应域名

访问域名:http://www.ps.cn 

Step_6:注意事项

a/ 如windows环境运行 linux系统注意事项,开启windows子系统并按照ubuntu系统。

b/ 安装包版本选择,根据apt list查找对应版本。

c/ 系统安装目录选择;etc/系统配置  var/数据log usr/软件程序 srv/service站点代码。

d/ nginx配置 虚拟主机(独立域名不用默认default.conf ),及软连接配置。

e/ 服务启动及检查配置。

3、参考

ubuntu配置:

https://jingyan.baidu.com/article/fc07f989a357db12ffe519fd.html

https://www.sysgeek.cn/apt-vs-apt-get/

ngnix安装:

https://blog.youkuaiyun.com/github_37501169/article/details/73441847

https://www.zhaokeli.com/article/8496.html

https://www.cnblogs.com/crazytata/p/9686490.html

linux系统:

https://blog.youkuaiyun.com/zyddj123/article/details/82497640

https://www.cnblogs.com/silence-hust/p/4319415.html

https://blog.youkuaiyun.com/weixin_38750084/article/details/82903030

https://www.cnblogs.com/sign-ptk/p/5609322.html

https://www.cnblogs.com/clicli/p/5943788.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值