PHP 开发环境搭建

个人使用的方式有两种

  1. LAMP/LNMP 环境
  2. PHP 自带的webserver

PHP 自带的webserver

配置搭建比较简单,一条命令即可以下实现一个本地 server php -S 0.0.0.0:8010。在浏览器中就可以访问。

LNMP 环境 搭建

整体结构

https://zhuanlan.zhihu.com/p/427552247 https://www.cnblogs.com/renyz/p/11347897.html

安装

Nginx

可以手动编译安装,也可以是使用apt-get方式安装。第二种方式版本较低。

FPM、MySQL

apt-get方式安装,便捷。

配置

Nginx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 server {
listen 8082;
#server_name localhost;

root /data/codes/sevenga_tuitui/backend;
index index.php;

location / {
try_files $uri $uri/ /index.php?$args;
# upload_limit_rate 1m;
}

location ~ \.php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}

PHP-FPM

配置文件 /etc/php5/fpm/pool.d/www.conf,设置fpm监听端口和 Nginx 配置一致

1
listen =127.0.0.1:9000 

FAQ

mysql 安装过程未设置密码,用 root 、空密码登陆报 ERROR 1045 (28000) 错误。

1
2
3
sudo /etc/init.d/mysql stop
sudo mysqld_safe --user=mysql --skip-grant-tables --skip-networking&
sudo mysql -u root mysql

更改sql用户密码

1
2
update mysql.user set password=PASSWORD('新密码'where User='root'
flush privileges

重启数据库:

/etc/init.d/mysql restart

参考

  1. ubuntu 系统解决mysql连接问题(ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO))

PHP 开发环境搭建
http://blog.soul11201.com/2015/11/17/lnmp-环境-搭建/
作者
soul11201
发布于
2015年11月17日
许可协议