Azure App Service with PHP 8 – configure PHP directives and Nginx directives

Before when I was using PHP 7.4 or lower on Azure app service it is using apache2, which means you can overwrite most of the PHP directives such as upload_max_filesize, memory_limit ,display_errors, etc in “.htaccess”. Now for App service with PHP 8, they are now using Nginx which means “.htaccess” override directives won’t work. How to change PHP directives and Nginx directives on app service with php 8? The steps are detailed below:

  1. First, we need to locate both the php.ini and Nginx default config. Per my experience:
    1. php.ini (php directives)- is located at “/usr/local/etc/php/conf.d/php.ini”, I located this using phpinfo().
    1. default (nginx directives) – is located at “/etc/nginx/sites-enabled/default”
  2. We need to copy them into a location such as “/home”
cp /usr/local/etc/php/conf.d/php.ini /home/php.ini
cp /etc/nginx/sites-enabled/default /home/default

3. Now add the Nginx directives or PHP directives to the php.ini or default file in the home directory

i. php.ini – enable display errors

			error_log=/dev/stderr
			display_errors=On
			log_errors=On
			display_startup_errors=On
			date.timezone=UTC
			zend_extension=opcache

ii. default – increase max body to 5M

		server {
		    #proxy_cache cache;
		        #proxy_cache_valid 200 1s;
		    listen 8080;
		    listen [::]:8080;
		    root /home/site/wwwroot;
		    index  index.php index.html index.htm;
		    server_name  example.com www.example.com;
		    client_max_body_size 5M;
		
		    location / {
		        index  index.php index.html index.htm hostingstart.html;
		    }
		
		    # redirect server error pages to the static page /50x.html
		    #
		    error_page   500 502 503 504  /50x.html;
		    location = /50x.html {
		        root   /html/;
		    }
		
		    # Disable .git directory
		    location ~ /\.git {
		        deny all;
		        access_log off;
		        log_not_found off;
		    }
		
		    # Add locations of phpmyadmin here.
		    location ~ [^/]\.php(/|$) {
		        fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
		        fastcgi_pass 127.0.0.1:9000;
		        include fastcgi_params;
		        fastcgi_param HTTP_PROXY "";
		        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
		        fastcgi_param PATH_INFO $fastcgi_path_info;
		        fastcgi_param QUERY_STRING $query_string;
		        fastcgi_intercept_errors on;
		        fastcgi_connect_timeout         300;
		        fastcgi_send_timeout           3600;
		        fastcgi_read_timeout           3600;
		        fastcgi_buffer_size 128k;
		        fastcgi_buffers 4 256k;
		        fastcgi_busy_buffers_size 256k;
		        fastcgi_temp_file_write_size 256k;
		    }
		}

4. Save the files above. Now, we need to do a copy again php.ini and Nginx default back to their original directory – this should be executed every restart of the app. To do this – you need to follow below:

Open and place the code below on App Service -> Configuration -> General settings -> Startup Command

With this command

cp /usr/local/etc/php/conf.d/php.ini /home/php.ini; cp /etc/nginx/sites-enabled/default /home/default; service nginx restart

5. Then click save, the app service will automatically restart – check the “Log stream” if it’s ready to accept requests:

Please follow and like us:

40 thoughts on “Azure App Service with PHP 8 – configure PHP directives and Nginx directives

  1. Thanks for the sensible critique. Me & my neighbor were just preparing to do a little research on this. We got a grab a book from our local library but I think I learned more clear from this post. I’m very glad to see such fantastic info being shared freely out there.

  2. We absolutely love your blog and find many of your post’s to be just what I’m looking for. Does one offer guest writers to write content available for you? I wouldn’t mind composing a post or elaborating on some of the subjects you write related to here. Again, awesome site!

  3. I’m truly enjoying the design and layout of your blog. It’s a very easy on the eyes which makes it much more enjoyable for me to come here and visit more often. Did you hire out a designer to create your theme? Outstanding work!

Leave a Reply

Your email address will not be published.