ubuntu18搭建详细的php环境,Ubuntu18.04搭建PHP的LNMP开发环境

1、安装nginx

sudo apt-get install nginx

nginx的默认网站目录是/var/www/html/

默认的nginx网站配置文件为/etc/nginx/sites-available/default 【可以删除,或者改端口,以免占用80端口】

日志文件在/var/log/nginx/ access.log error.log 一般500服务器问题都可以查看该文件

启用nginx服务器 sudo service nginx start || sudo systemctl start nginx

使用netstat -anp则可以看到80端口已经处于LISTEN状态了。

直接查看80端口可以使用命令:sudo lsof -i:80

查看进程 ps aux | grep nginx

打开浏览器输入虚拟机IP,出现 Nginx 的欢迎界面,就代表 Nginx 安装成功了。

配置Nginx查看:配置Nginx点这儿

2、安装 MySql

sudo apt-get install mysql-server mysql-client

安装完毕后,输入命令打开数据库,然后会让输入密码 直接回车就行

mysql -u root -p

use mysql;

# 修改root可以直接登录

update mysql.user set authentication_string=PASSWORD('新密码'),plugin='mysql_native_password' where user='root' and Host = 'localhost';

#输入命令,刷新 MySQL 系统权限设置

flush privileges;

#重启mysql服务

sudo service mysql restart

以下示例为创建一个具有一定权限的数据库(数据库账号仅对当前数据库生效)。

创建一个新的空数据库。默认编码为UTF8:

CREATE DATABASE dbname DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

为数据库创建具有适当权限的用户/密码组合。例如(再次使用MySQL):

mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,CREATE TEMPORARY TABLES,DROP,INDEX,ALTER ON dbname.* TO 'dbnameuser'@'localhost' IDENTIFIED BY 'yourpassword';

dbname.* :dbname为数据库名。

dbnameuser:用户名。

yourpassword:用户密码。

3、安装php

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

#查看php版本

php -v

#修改/etc/php/7.2/fpm/php.ini【可选】

display_errors=on

#重启服务

sudo service php7.2-fpm restart

sudo service nginx restart

4、安装phpmyAdmin 【默认是apache作为服务器】

sudo apt install phpmyadmin

sudo ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin //软链接到web根目录下(我的是/var/www/html/),

如果是apache,浏览器输入127.0.0.1/phpmyadmin验证查看,

如果是nginx,可以给phpadmin作为一个项目单独配置一个端口

如果访问 ip:port/phpmyadmin 403被禁止,你可以为phpmyadmin单独配置一个文件,将根目录指向 /var/www/html/phpmyadmin,并将端口配置成随机一个,比如8090,然后重启再访问 ip:8090,就好了。

5、附录nginx配置文件

default 配置文件可以删除的。

sudo touch center.conf

sudo vim center.conf

以下配置文件是 Homestead 默认生成的配置文件,laravel项目基本复制过去,改改root目录,改改错误日志路径,改改php-fpm对应的版本,最后的ssl可以删除,就ok了,

server {

listen 80;

listen 443 ssl http2;

server_name .center.com;

root "/home/vagrant/code/Center/public";

index index.html index.htm index.php;

charset utf-8;

location / {

try_files $uri $uri/ /index.php?$query_string;

}

location = /favicon.ico { access_log off; log_not_found off; }

location = /robots.txt { access_log off; log_not_found off; }

access_log off;

error_log /var/log/nginx/center.com-error.log error;

sendfile off;

client_max_body_size 100m;

location ~ \.php$ {

fastcgi_split_path_info ^(.+\.php)(/.+)$;

fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;

fastcgi_index index.php;

include fastcgi_params;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

fastcgi_intercept_errors off;

fastcgi_buffer_size 16k;

fastcgi_buffers 4 16k;

fastcgi_connect_timeout 300;

fastcgi_send_timeout 300;

fastcgi_read_timeout 300;

}

location ~ /\.ht {

deny all;

}

ssl_certificate /etc/nginx/ssl/center.com.crt;

ssl_certificate_key /etc/nginx/ssl/center.com.key;

}

#最后将配置文件加载

sudo ln -s /etc/nginx/sites-available/center.conf /etc/nginx/sites-enabled/

参考文章:点这儿

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值