简体   繁体   中英

PHP API is not working With Django on apache2 Ubuntu server | Google Cloud

I have successfully deployed a Django project on the apache2 web server on Linux Ubuntu machine on Google Cloud . It is working fine. Also, I have PHP API that connects with the MySQL database the same Django connects. But the issue is that the Django application works fine and PHP API is not working.

I have also placed the index.html page in my /var/www/html/api_folder/index.php path. so when I type my_ip/api_folder in a browser it opens index.html page but the API is not working. the api files are in api_folder as in the index.html page.

below is my conf file in /sites-available directory of apache2. even the basic PHP file works and prints the message in echo. but when I type My_ip/api_folder/api/get_about_us/?key=xxxx it shows me 404 Error page.

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html
     Alias /api_folder /var/www/html/api_folder
    <Directory /var/www/html/api_folder>
    Options Indexes FollowSymLinks
            AllowOverride All
            Require all granted
    Allow from all
     </Directory>

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

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

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf


    Alias /static /home/my_user/spinner/static
      <Directory /home/my_user/spinner/static>
        Require all granted
      </Directory>

     Alias /media /home/my_user/spinner/media
      <Directory /home/my_user/spinner/static/media>
        Require all granted
      </Directory>

      <Directory /home/my_user/spinner/spinner>
        <Files wsgi.py>
          Require all granted
        </Files>
      </Directory>

    WSGIScriptAlias / /home/my_user/spinner/spinner/wsgi.py
    WSGIDaemonProcess spinner_app python-path=/home/my_user/spinner python-home=/home/my_user/venv_spinner
    WSGIProcessGroup spinner_app



</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

you may have an issue in .htaccess file. please check .htaccess file once.

make sure you have enabled apache2 Rewrite rule. run following command to do that:

sudo a2enmod rewrite
sudo service apache2 restart

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM