ubuntu安裝php開發環境
阿新 • • 發佈:2018-04-05
bst magic bind -i deb var NPU fault ubuntu
一,安裝 ubuntu 工具
sudo apt install -y git curl zsh vim
二,安裝php 和 php-fpm , redis ,memcached 等
sudo apt install -y php7.0 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
用 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
ubuntu安裝php開發環境