alexxero
alexxero

Reputation: 103

PHP app deploy Ubuntu 16.04 nginx apache setting

It's been a 3rd day I'm trying to deploy a little php app. We moving our apps, which is 3 rails apps and 1 php to the same server. Rails apps working fine. PHP doesn't. I've never really deployed PHP app, so I am doing it through guides. So far, I get this situation: If I try to open PHP app in a browser I see default Apache page. If I refresh the page it will show me the content of index.php file, but as a blank text. Refresh again - default Apache page, and again - content of index.php.

My settings:

nginx/sites-available/my.site (enabled in sites-enabled)

server {
     listen 80 default_server;
     listen [::]:80 default_server;

 root /var/www/my.site/httpdocs;

 # Add index.php to the list if you are using PHP
 index index.php index.html index.htm index.nginx-debian.html;

 server_name my.site www.my.site;

 location / {
   proxy_pass http://localhost:8000;
   include /etc/nginx/proxy_params;
 }

 location ~* \.(js|css|jpg|jpeg|gif|png|svg|ico|pdf|html|htm)$ {
expires      30d;
 }

 location @proxy {
    proxy_pass http://127.0.0.1:8000;
    include /etc/nginx/proxy_params;
 }
 location ~* \.php$ {
    proxy_pass http://127.0.0.1:8000;
    include /etc/nginx/proxy_params;
    proxy_set_header X-Real-IP  $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header Host $host;
 }
}

apache2/sites-available/my.site

ServerName my.site
ServerAlias www.my.site

ServerAdmin webmaster@localhost
DocumentRoot /var/www/my.site/httpdocs

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

apache2/ports.conf

NameVirtualHost 127.0.0.1:8000
Listen 8000

<IfModule ssl_module>
    Listen 443
</IfModule>

<IfModule mod_gnutls.c>
    Listen 443
</IfModule>

At the work in day off with no idea how to fix the server. Any advice is appreciated.

Upvotes: 0

Views: 100

Answers (1)

de fn
de fn

Reputation: 26

nginx config

map $sent_http_content_type $expires {
    default               off;
    ~css                  max;
    ~javascript       max;
    ~image             max;
    ~font-woff        max;
    ~video               max;
    ~zip                   max;
    ~txt                    max;
  }
expires                 $expires;

server {
listen 80;
    server_name exemple.com;
    root /home/to/exemple.com;
    index index.php index.html;             

gzip                    on;
gzip_min_length         128;
gzip_http_version       1.1;
gzip_buffers           128 32k;
gzip_types
    text/css
    text/javascript
    text/xml
    text/plain
    text/x-component
    application/javascript
    application/x-javascript
    application/json
    application/xml
    application/rss+xml
    application/atom+xml
    font/truetype
    font/opentype
    application/vnd.ms-fontobject
    image/svg+xml;
gzip_static  on;    
gzip_proxied            expired no-cache no-store private auth;
gzip_disable            "msie6";
gzip_vary                on;

location / {
   proxy_pass http://127.0.0.1:8000;
   proxy_set_header Host $host; 
   proxy_set_header X-Real-IP $remote_addr;
   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
   proxy_set_header X-Forwarded-Proto $scheme;
   }
}

apache config

php 7 mod

apt install libapache2-mod-php7.0

php5 mod

apt install libapache2-mod-php

Include for example php7.0 mod

a2enmod php7.0

VirtualHost config apache

<VirtualHost *:8000>
  ServerName exemple.com
  DocumentRoot /home/to/exemple.com
  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined
  RewriteEngine On
<Directory /home/to/exemple.com/>
  php_admin_flag engine on
  Options -ExecCGI -Indexes +FollowSymLinks
  AllowOverride All
  Require all granted
</Directory>
</VirtualHost>

Remove NameVirtualHost 127.0.0.1:8000 in apache2.conf Paste ServerName 127.0.0.1

systemctl restart apache2
systemctl restart nginx

Original post apache2+nginx proxy

Upvotes: 1

Related Questions