ubuntu16安装php开发环境
一,安装 ubuntu 工具
sudo apt install -y git curl zsh vim
二,安装php 和 php-fpm , redis ,memcached 等
sudo apt install -y php7.0-dev php7.0-fpm php-redis php-memcached php-solr php-imagick php-mongodb php7.0-xml php7.0-zip php7.0-bcmath php7.0-curl php7.0-mysql php7.0-mbstring php7.0-gd
备注:php7.0 就是正常的安装和扩展
php7.0-dev 安装会有 phpize 可用编译swoole
用 php -m 查看扩展
三,安装 composer
curl -sS https://getcomposer.org/installer | php sudo mv composer.phar /usr/local/bin/composer composer config -g repo.packagist composer https://packagist.phpcomposer.com
四,安装 redis
sudo apt install -y redis-server
五,安装 mysql
sudo apt install -y mysql-server-5.7
sudo apt install -y mysql-client
六,远程工具连接 mysql
cd /etc/mysql sudo vi my.cnf 底部添加一些内容: [client] default-character-set = utf8 [mysqld] character-set-server = utf8 bind-address = 0.0.0.0 mysql -u root -p use mysql grant all privileges on *.* to root@"%" identified by "passwd" with grant option; flush privileges;
sudo service mysql restart
GRANT ALL PRIVILEGES ON *.* TO 'root'@'要指定的IP地址' IDENTIFIED BY '设置的密码' WITH GRANT OPTION;
也可以先更新将host更新为% ,然后通过图形化界面(SqlYog, workbench 等)来更新host为自己的ip。
继续输入 flush privileges; 记住,不管选用上面那种方法,都要执行这步来更新数据库用户权限。非常重要!
七,有可能是防火墙的原因
查看已有的iptables规则,以序号显示:
iptables -L -n --line-numbers
删除对应的DROP规则:
iptables -D INPUT 5
八,安装 nginx
sudo apt install -y nginx
九,配置 nginx 和 php-fpm 解析php
vim /etc/nginx/sites-available/default
修改配置文件
server { listen 80 default_server; listen [::]:80 default_server; root /var/www/html; #网站目录 index index.php index.html index.htm index.nginx-debian.html; server_name server_domain_or_IP; #绑定网站域名 location / { try_files $uri $uri/ /index.php?$query_string; #配置转发规则 } # 解析php location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.0-fpm.sock; #利用php-fpm套接字解析php } location ~ /\.ht { deny all; } }
用 sudo nginx -t 查看 nginx 配置文件是否正确
配置 php-pfm
vim /etc/php/7.0/fpm/php.ini 找到cgi.fix_pathinfo=1,将其改为cgi.fix_pathinfo=0
重启 nginx 和 phpfpm
修改权限 :sudo chown -R yourname:root /var/www
sudo chmod -R 777 /var/www sudo service nginx restart sudo service php7.0-fpm restart
网络
网卡1 网络地址转换(NAT)
网卡2 仅主机(Host-Only)网络
sudo apt install -y vim
sudo vim /etc/network/interfaces
使用ifconfig命令查看网卡名称
auto enp0s3
iface enp0s3 inet dhcp
auto enp0s8
iface enp0s8 inet static
address 192.168.56.222
netmask 255.255.255.0
network 192.168.56.0
broadcast 192.168.56.255
sudo /etc/init.d/networking restar