记录下在阿里云搭建 PHP7 开发环境
安装 nginx
sudo apt-get update sudo apt-get install nginx安装完成后会自动开启,通过命令查看# ps -aux |grep nginxroot7921 0.0 0.0 14232 972 pts/0 S+ 21:25 0:00 grep --color=auto nginxroot27770 0.0 0.0 117084 1444 ? Ss 20:39 0:00 nginx: master process /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 processwww-data 27772 0.0 0.1 117692 5120 ? S 20:39 0:00 nginx: worker process浏览器打开 http://x.x./ 可以看到 nginx 的欢迎页面
安装 PHP7
sudo apt-get install python-software-properties software-properties-commonsudo add-apt-repository ppa:ondrej/phpsudo apt-get install php7.0-fpm php7.0-cli php7.0-mcrypt php7.0-mysql php7.0-mbstring php7.0-xml php7.0-curl开启OPcacheapt-get install php70-php-opcache.x86_64sudo service php7.0-fpm restart
配置 nginx 解析 PHP
vi /etc/nginx/sites-available/defaultserver {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.inicgi.fix_pathinfo=0sudo phpenmod mcryptsudo service php7.0-fpm restartsudo service nginx restartvi test.php<?phpphpinfo();
安装 MySQL
# 默认安装 MySQL 5.7sudo apt-get install mysql-server mysql-client#设置好密码后登陆mysql -u root -p
安装 redis
sudo apt-get install gitgit clone -b php7 /phpredis/phpredis.gitmv phpredis/ /etc/cd /etc/phpredissudo apt install php7.0-dev#生成编译文件phpizesudo ./configuremake && make installfind / -name redis.so/etc/phpredis/.libs/redis.so/etc/phpredis/modules/redis.so/usr/lib/php/1012/redis.sovim /etc/php/7.0/apache2/php.ini extension=/etc/phpredis/modules/redis.sosudo service php7.0-fpm restartps -aux |grep redisroot7981 0.0 0.0 14232 1024 pts/0 S+ 21:40 0:00 grep --color=auto redisredis 30952 0.0 0.1 40136 6716 ? Ssl 20:59 0:02 /usr/bin/redis-server 127.0.0.1:6379redis-cli127.0.0.1:6379> info# Serverredis_version:3.0.6redis_git_sha1:00000000redis_git_dirty:0redis_build_id:687a2a319020fa42redis_mode:standaloneos:Linux 4.4.0-79-generic x86_64arch_bits:64multiplexing_api:epollgcc_version:5.3.1process_id:30952run_id:056f34665607470e822036784d93cbbe079080a7tcp_port:6379uptime_in_seconds:2792uptime_in_days:0vi 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访问