John Davidson

How to setup python and php both on a single vps

0 comments
Message:


I have bought a digital ocean VPS ( image: ubuntu) with Plesk. I have connected with one domain. and now I am running a php website successfully on VPS. I want to run the flask application as well in my VPS. I can run it by console. But I want it to be done by a web request , with a domain. But I already added my PHP website with the domain.I want to know if I can run python with that same domain name ( with subdomain if possible ).


example: my website: https://example.com/index.php
I want to run flask app with this endpoint:- https://example.com/python or https://python.example.com


I guess I have to change some configuration settings in apache2/sites-available.


Can I try below .conf ?


<VirtualHost *:80>
ServerName example.com/python
ServerAlias www.example.com/python
ServerAdmin [email protected]
WSGIScriptAlias / /var/www/myapp/pyapp.wsgi
<Directory /var/www/myapp/myapp/>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/myapp/myapp/static
<Directory /var/www/myapp/myapp/static/>
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

But I am not sure at all , I am noob in .conf .


thanks you so much if you can help me. :)



My Answer:
Yes, you can definitely run both PHP and Python applications on the same VPS with Plesk. Here's how you can set it up:

1. Install Flask and Apache mod_wsgi on your VPS:
- Install Flask by running `pip install Flask` in your terminal.
- Install Apache mod_wsgi by running `sudo apt-get install libapache2-mod-wsgi`.

2. Create a Flask application:
- Create a new directory for your Flask application and create a new Python file (e.g. `app.py`) with your Flask code.
- Make sure your Flask application is running successfully by testing it in the terminal.

3. Configure Apache to serve your Flask application:
- Create a new Apache configuration file for your Flask application in `/etc/apache2/sites-available/` (e.g. `python.example.com.conf`).
- Add the following configuration to the file:



ServerName python.example.com
WSGIScriptAlias / /path/to/your/flask/application/app.wsgi


Order allow,deny
Allow from all




4. Enable the new Apache configuration and restart Apache:
- Enable the new configuration by running `sudo a2ensite python.example.com.conf`.
- Restart Apache by running `sudo service apache2 restart`.

5. Update your DNS settings:
- Update your DNS settings to point the subdomain `python.example.com` to your VPS IP address.

6. Test your Flask application:
- Visit `https://python.example.com` in your web browser to test if your Flask application is running successfully.

By following these steps, you should be able to run both your PHP website and Flask application on the same VPS with Plesk. Let me know if you have any further questions or issues.

Rate this post

3 of 5 based on 9184 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us