当前位置: 首页 > 工具软件 > Valar PHP > 使用案例 >

Laravel随笔 Ubuntu系统下安装PHP环境

司徒钱青
2023-12-01
  1. 更新阿里镜像
    https://blog.csdn.net/weixin_41490929/article/details/96483335

  2. 安装nginx

sudo apt-get install nginx

开启服务

检查版本:
nginx –v

启动服务:
sudo  nginx
sudo  service nginx start

关闭服务:
sudo  nginx  -s  stop
sudo  service nginx stop

 重启:
sudo  nginx  -s  reload
  1. 1 安装mysql
sudo apt install mysql-server mysql-client
  1. 2 检查是否安装完成
mysql -server
  1. 3 如果没完成且出现

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket
‘/var/run/mysqld/mysqld.sock’

sudo mkdir -p /var/run/mysqld
sudo chown mysql /var/run/mysqld/
sudo service mysql restart

mysql -u root -p
  1. 4 ubantu linux下安装新版mysql,登录时必须sudo mysql -u root -p,因为安装时root用户的密码是随机的,直接mysql -u root -p则无法登录,报错:
    ERROR 1698 (28000): Access denied for user ‘root’@'localhost

解决方案:

步骤一:登录mysql

sudo mysql -u root -p

步骤二:修改密码

update mysql.user set authentication_string=PASSWORD('123'), plugin='mysql_native_password' where user='root';

步骤二:重启服务

flush privileges;
  1. 安装PHP
sudo apt-add-repository ppa:ondrej/php  ###使用 PPA ppa:ondrej/php

sudo apt update  ###更新软件库

sudo apt install php7.0 php7.0-fpm php7.0-cgi php7.0-common php7.0-curl php7.0-mysql php7.0-mcrypt php7.0-mbstring
  1. 1 查看并修改php-fpm的配置
   sudo vim /etc/php/7.0/fpm/pool.d/www.conf

   listen = /run/php/php7.0-fpm.sock

   #listen = 127.0.0.1:9000

查看监听路径是否存在,不存在则手动追加/run/php/,否则无法生成php-fpm.socket

可以用如下方式检查下配置文件是否有错误 sudo php-fpm7.0 -t
修改重启下 sudo service php7.0-fpm restart

  1. 2 修改nginx配置文件
sudo vim /etc/nginx/sites-enabled/default

server {
        listen 80 default_server;
        listen [::]:80 default_server;
                root /var/www;

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

        server_name _;

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

        # pass PHP scripts to FastCGI server
        #
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;

                # With php-fpm (or other unix sockets):
                #此处路径必须与php-fpm配置相同
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;
                # With php-cgi (or other tcp sockets):
                #fastcgi_pass 127.0.0.1:9000;
        }

nginx 检查配置文件命令是 sudo nginx -t
修改重启下 nginx sudo service nginx restart

 类似资料: