阿里雲 Ubuntu PHP7 Nginx Mysql 開發環境搭建

記錄下在阿里雲搭建 PHP7 開發環境php

安裝 nginx

sudo apt-get update 
sudo apt-get install nginx

安裝完成後會自動開啓,經過命令查看
# ps -aux |grep nginx
root      7921  0.0  0.0  14232   972 pts/0    S+   21:25   0:00 grep --color=au
to nginx
root     27770  0.0  0.0 117084  1444 ?        Ss   20:39   0:00 nginx: master p
rocess /usr/sbin/nginx -g daemon on; master_process on;
www-data 27771  0.0  0.0 117404  3084 ?        S    20:39   0:00 nginx: worker p
rocess
www-data 27772  0.0  0.1 117692  5120 ?        S    20:39   0:00 nginx: worker p
rocess

瀏覽器打開 http://x.x.x.x.com/ 能夠看到 nginx 的歡迎頁面

clipboard.png

安裝 PHP7

sudo apt-get install python-software-properties software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt-get install php7.0-fpm php7.0-cli php7.0-mcrypt php7.0-mysql php7.0-mbstring php7.0-xml php7.0-curl
開啓OPcache
apt-get install php70-php-opcache.x86_64
sudo service php7.0-fpm restart

配置 nginx 解析 PHP

vi /etc/nginx/sites-available/default
server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    #root 爲項目代碼所在目錄
    root /var/www/html;
    index index.php index.html index.htm;

    #填寫購買的阿里雲外網IP或者本身已經解析備案的域名
    server_name http://x.x.x.x/;

    #更改未被註釋一行
    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
        # Uncomment to enable naxsi on this location
        # include /etc/nginx/naxsi.rules
    }
    #添加下面代碼
        location ~ \.php$ {
               try_files $uri $uri/ =404;
               fastcgi_split_path_info ^(.+\.php)(/.+)$;
               fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
               fastcgi_index index.php;
               fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
               include fastcgi_params;
        }
}

sudo vi /etc/php/7.0/fpm/php.ini
cgi.fix_pathinfo=0

sudo phpenmod mcrypt
sudo service php7.0-fpm restart
sudo service nginx restart
vi test.php
<?php
phpinfo();

clipboard.png

安裝 MySQL

# 默認安裝 MySQL 5.7
sudo apt-get install mysql-server mysql-client
#設置好密碼後登錄
mysql -u root -p

安裝 redis

sudo apt-get install git
git clone -b php7 https://github.com/phpredis/phpredis.git
mv phpredis/ /etc/
cd /etc/phpredis
sudo apt install php7.0-dev
#生成編譯文件
phpize
sudo ./configure
make && make install
find / -name redis.so
/etc/phpredis/.libs/redis.so
/etc/phpredis/modules/redis.so
/usr/lib/php/20151012/redis.so

vim /etc/php/7.0/apache2/php.ini 
extension=/etc/phpredis/modules/redis.so
sudo service php7.0-fpm restart
ps -aux |grep redis
root      7981  0.0  0.0  14232  1024 pts/0    S+   21:40   0:00 grep --color=auto redis
redis    30952  0.0  0.1  40136  6716 ?        Ssl  20:59   0:02 /usr/bin/redis-server 127.0.0.1:6379
redis-cli
127.0.0.1:6379> info
# Server
redis_version:3.0.6
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:687a2a319020fa42
redis_mode:standalone
os:Linux 4.4.0-79-generic x86_64
arch_bits:64
multiplexing_api:epoll
gcc_version:5.3.1
process_id:30952
run_id:056f34665607470e822036784d93cbbe079080a7
tcp_port:6379
uptime_in_seconds:2792
uptime_in_days:0

vi test.php
<?php

//鏈接本地Redis服務  
$redis=new Redis();
$redis->connect('127.0.0.1','6379');

上傳代碼

scp -r . root@x.x.x.x:/var/www/html

參考
阿里雲Ubuntu14+PHP7+Nginx+Mysql環境搭建
在阿里雲上部署Laravel應用
阿里雲ECS部署Laravel+PHP7+Nginx
Nginx配置https訪問html

相關文章
相關標籤/搜索