刘贵学博客

Ubuntu 下PHP开发环境配置脚本

1. 系统更新

apt-get update

2. 安装git

apt-get install libcurl4-openssl-dev  libexpat1-dev git

3. 安装 lnxcfg 脚本 ( bookmark, git command alias, vim and plugins.)

git clone https://github.com/guixue/lnxcfg.git
cd lnxcfg
make
vi ~/.bashrc 
添加
if [ -f ~/.mybashrc ]; then
    . ~/.mybashrc
fi
source ~/.bashrc

4. 安装 HTTP 服务器: nginx

apt-get install nginx

测试: hello.html 可以显示

5. 安装数据库: mysql-server

apt-get install mysql-server

mysql -u root -p 测试通过

6. 安装PHP:

6.1 PHP5.X

ubuntu 16.04 无法安装 php5.6

sudo apt-get purge `dpkg -l | grep php| awk '{print $2}' |tr "\n" " "`
sudo add-apt-repository ppa:ondrej/php
sudo apt-get install software-properties-common
sudo apt-get update
sudo apt-get install php5.6
apt-get install php5.6-cli php5.6-cgi mysql-server php5.6-mysql 
apt-get install php5.6-xml php5.6-gd
apt-get install php5.6-fpm
apt-get install spawn-fcgi
cd /usr/sbin
ln -s php-fpm5.6 php-fpm

6.2 PHP 7.x

sudo apt-get install php
apt-get install php-cli php-cgi php-mysql php-xml php-gd

7. 测试PHP 环境:

1) . 新增vhost 站点:

例如: /etc/nginx/sites-enabled/default.conf

server {
    listen 80;
    server_name [IP or domain Name];

    root  /var/www/sites/default/;

    location / {
        index index.html index.php;
        autoindex on;
    }
    
    include enable-php.conf;
    
    access_log logs/[domain Name].log;

}

注: /etc/nginx/enable-php.conf ,针对通用的所有的PHP解析:

location ~ \.php$ {
        fastcgi_intercept_errors on;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  fastcgi_script_name;
        include fastcgi_params;

}

测试: info.php 简单探针程序可以运行;

<?php

phpinfo();

info.php 测试通过

apt-get install phpmyadmin
# whereis phpmyadmin
# ln -s /usr/share/phpmyadmin phpadmin

SSH 配置