Without being completely aware of what you python script is doing, I will try to give you a quick run through of what I would do in your place.
I use Django for all web exposed applications. It works great to customize the url patterns, access to legacy data is superb and the orb for interacting with these data covers 99% of my needs in all projects.
Setting up Django to run in apache is explained in details in the Django documentation. Once you have your new site up and running side by side with your php app you can start the communication between them.
Django accessing the PHP data
Django manage.py can create a model for you based on existing tables. In some cases you can get an out of the box model file ready to use, but in most cases you need to go in an create your own order and customization of relation between you tables. Setup the database section of your settings.py to point to your PHP app database.
DATABASES = {
'default': {
'ENGINE':'django.db.backends.postgresql_psycopg2',
'NAME': 'myphpappdbname',
'USER': 'phpuser',
'PASSWORD': 'phppassword'
# snipped away other options. Might or might not bee needed
}
}
Once you have your setup you can test access to your data with
python manage.py dbshell
When you have ensured correct connection to the database you can run
python manage.py inspectdb > models.py
This will generate a model for each of your tables. Add this model file to and app in your new django project.
python manage.py startapp phpextension
mv models.py phpextension/models.py
Modify your installed apps in settings to include your newly installed app and you now have access to your whole PHP app data through your django app. Create your views for what data you wish expose on the web.
As an added note, if you with to camouflage to the public that you are mixing php and django/python you can create your URL patterns with the following:
url(r'^my_command.php$', 'phpextensions.views.my_command', name="my_command"),
For this to work I think you also need to set the setting APPEND_SLASH=False
.
The views will then see the django view as just another php script (only faster, more gracious and infused with magical unicorns ).
Access to your Django data through PHP
Here I would use a REST api. The simple way is just to build a JSON response in your view with json.dumps(my_dictionary_of_data_for_php) and the more enterprise way is to use tastypie.
Then you can access the data in PHP using
$fc = file_get_contents('http://yourdomain.com/path/to/django/my_command.php');
$django_data = json_decode(fc);