本文使用的版本
PHP 5.5.36
symfony 2.8
composer 1.6.5
关于安装symfony 2.8, 用官网的教程没有成功
https://github.com/symfony/symfony-installer
一直报错:
curl: (35) Server aborted the SSL handshake
采用composer成功了
新建symfony项目
1、下载composer
https://getcomposer.org/download/
2、安装composer
mv composer.phar /usr/local/bin/composer # 成为全域指令 chmod +x /usr/local/bin/composer # 赋予可执行
3、修改 composer 的全局配置文件更换国内镜像
composer config -g repo.packagist composer https://packagist.phpcomposer.com
4、新建项目symfony 指定版本v2.8
composer create-project symfony/framework-standard-edition my_project_name "2.8.*"
命令行中出现的信息一般默认即可
如果出现时区错误timezone
修改配置文件/private/etc/php.ini
[Date] date.timezone = Asia/Shanghai
配置nginx
1、全局配置
修改/usr/local/etc/nginx/nginx.conf
user nobody; worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; client_max_body_size 20M; include conf.d/*.conf; }
说明:
其他都注释掉!
include 是需要加载配置文件的路径
2、项目配置
在配置文件路径下/usr/local/etc/nginx新建conf.d/mywebsite.conf
conf.d对应上面在nginx.conf 配置的include项
log_format logformat '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; server { listen 8080; server_name localhost; index app.php; root /usr/local/var/www/my_project_name/web; location / { if (!-e $request_filename){ rewrite ^/(.+)$ /app.php/$1 last; } client_max_body_size 20M; } location ~ ^/(app|app_dev)\.php(/|$) { fastcgi_pass 127.0.0.1:9999; fastcgi_split_path_info ^(.+\.php)(/.*)$; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param HTTPS off; client_max_body_size 20M; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 1h; client_max_body_size 20M; } access_log /usr/local/var/www/my_project_name/logs/mywebsite.log logformat; error_log /usr/local/var/www/my_project_name/logs/mywebsite.error_log; }
说明
root 刚刚新建项目的路径,指向web目录
access_log,error_log日志文件,需要手动新建,如果遇到权限问题
sudo chown -R $(whoami) /usr/local/var/www/
3、修改完配置文件之后重启nginx、php-fpm
$ brew services reload nginx $ ps aux|grep php-fpm # 看看还有哪些进程,都杀掉 $ kill <pid> $ php-fpm #启动 $ nginx -t # 看下配置是否正常
访问:http://localhost:8080/