Last active
May 7, 2016 08:28
-
-
Save alash3al/8dd1adad2d8903fba399d5432faeb53f to your computer and use it in GitHub Desktop.
nginx+php environment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| # change this to the apps directory | |
| apps_dir=/home/alash3al/Dev/php | |
| # don't change this var's value | |
| site=$1 | |
| # just change | |
| htdocs=$apps_dir/$site | |
| # create the htdocs directory | |
| mkdir -p $htdocs | |
| # update the hosts file | |
| echo "127.0.0.1 $site" >> /etc/hosts | |
| echo "<?php echo '<pre>', print_r(\$_SERVER, 1), '</pre>';" >> $htdocs/index.php | |
| # test the result | |
| curl $site |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # replace your /etc/nginx/sites-enabled/default with this file | |
| # this file will prepare your nginx environment for a simple PHP development environment . | |
| server { | |
| # change the value of this var to your applications directory | |
| set $apps_dir /home/alash3al/Dev/php; | |
| listen 80 default_server; | |
| listen [::]:80 default_server; | |
| index index.php index.html; | |
| server_name _; | |
| # return 404 if the app doesn't exists | |
| if ( !-d $apps_dir/$http_host ) { | |
| return 404; | |
| } | |
| # set the root directory of the current context | |
| root $apps_dir/$http_host; | |
| # fallback to index.php if the requested file not found | |
| location / { | |
| try_files $uri $uri/ /index.php?$args; | |
| } | |
| # handle php requests | |
| location ~ \.php$ { | |
| include snippets/fastcgi-php.conf; | |
| if ( !-f $request_filename ) { | |
| return 404; | |
| } | |
| fastcgi_param SERVER_NAME $http_host; | |
| fastcgi_pass unix:/run/php/php7.0-fpm.sock; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment