How to run Python/Django combined with Apache - php

I have a running apache/PHP site using XAMPP on my locahost, and i am learning the basics of python/django and have a python manage.py runserver on port 8000, i read about configuring the virtual host on xampp http-vhost.conf but cannot make it work, i just need to run both and somehow remove the port number on my python site, don't know if configuring apache is the best way any advice would be great!
My apache site is running using below url.
http://localhost/myPHPwebiste
My python/django site is running using below url.
http://localhost:8000/myPythonwebiste
My http-vhost.conf on apache server (i saved my python files inside the htdocs)
<VirtualHost 127.0.0.1:8000>
DocumentRoot "D:/xampp/htdocs/myPythonwebiste"
<Directory "D:/xampp/htdocs/myPythonwebiste">
Options All
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
My goal is to make my python site run on url below.
http://localhost/myPythonwebiste

I got a solution from apache documentation closed to what i want to achieve i include below line into my apache http.conf and got it working.
ProxyPass /myPythonwebiste http://localhost:8000/myPythonwebiste

Related

Difference between Laravel local host and XAMPP local host address

I'm trying to learn Laravel, but ran into an issue I hope you can help resolve. Recently, while working to learn php programming I installed XAMPP, without problem and used it with both php and MYSql. It uses the localhost IP of http://127.0.0.1. In the new course I'm using to learn Laravel after the installation of Laravel the setup uses http://127.0.0.1:8000/, which I can access using Visual Code Terminal and entering "php artisan serve". Following the course instructions for setting up Visual Code I next installed an Extension titled "Connect to Server". After installation of the extension I get a dialog box to connect to the database and it defaults to the 127.0.0.1:8000/ address. If I click on the connect button I get an error. That said, if I start XAMPP and change the value in the dialog box and use the XAMPP 127.0.0.1 address I make a successful connection to MYSQL.The question I have is this, am I going to have a problem in the near future as the result of the two different 127.0.0... addresses and if so is there any way to resolve it?
If you look at the problem I have outlined the issue and hope I can get some resolution before I get to the point I run into trouble.
You can use php artisan serve if you wish to use the laravel's serve command. If you wish to use xampp/wamp, you can add a virtual host in your httpd-vhosts.conf file.
In case of wamp, httpd-vhosts.conf file is in C:\wamp64\bin\apache\apache2.4.51\conf\extra where 2.4.51 is the apache version if you did not change the installation path.
In case of xampp, it is C:\xampp\apache\conf\extra
As for the vhost setup, add the snippet below (change depending on your project path):
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "path-to-project\public"
ServerName project.local
<Directory "path-to-project">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog "logs/project-errors.log"
CustomLog "logs/project-access.log" common
</VirtualHost>
Next is open your notepad as administrator then go to C:\Windows\System32\drivers\etc then open hosts file. add 127.0.0.1 project.local
restart wamp/xampp. You should be able to access your project using project.local
Xampp comes with Apcahe/ Mysql so when you run xampp it runs apache and mysql both.
but php artisan serve starts only a php server so your database related thins will not work if you are not running mysql separately (With xampp or as a standalone installation)
You can find more about what the artisan serve command to here PHP artisan serve code

Failed to run Laravel 5 project on browser

I am very new to laravel, I am using windows 7 OS. I have a PHP website made on laravel 5 which I want to run on my browser. I have gone through the videos and the various website on "How to run laravel 5 project on browser" but unfortunately I failed to run my project on the browser.
I am using XAMPP and below is my Virtual Hosts file of apache. My localhost port is 7000.
<VirtualHost *:7000>
DocumentRoot "C:\xampp2\htdocs\basicwebsite\public"
ServerName basicwebsite.com
</VirtualHost>
And inside the hosts file within the system32 folder I have put the following line
127.0.0.1 basicwebsite.com
When I am trying to run it on my browser it gives me an error
"This site can’t be reached
basciwebsite.com refused to connect."
Any help is welcome.
When I'm developing locally with Laravel, I simply execute php artisan serve on the terminal. I can then run it on http://localhost:8000
check below points -
1.) .env file should have APP_KEY
2.) have you created "storage/views" , "storage/cache"
Try This:
<VirtualHost *:7000>
DocumentRoot "C:/xampp2/htdocs/basicwebsite/public"
ServerName basicwebsite.com
<Directory "C:/xampp2/htdocs/basicwebsite">
</Directory>
</VirtualHost>
Try using something other than basicwebsite.com in the servername,
Maybe use basicwebsite.local
Explanation:
.com is widely used therefore using something different should do the trick, try http://nameofwebsite.local
(doesn't have to be .local, can be anything really but not .com or .net for example)

How to change apache domain name(locally) for a laravel site on ubuntu?

Good day guys in my application I want to change the normal http://127.0.0.1:8000/ that laravel uses to serve sites when one runs php artisan serve to example.com and this should have sub domains like app1.example.com and app2.example.com.
In the main time I have tried to create a virtual host for my site by creating a .conf file inside of etc/apache2/sites-available/example.com.conf and here is how it looks:
<VirtualHost *:80>
ServerAdmin webmaster#example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /home/tangaye/sites/example/public/index.php
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
After doing that I enable the virtual host I created by running sudo a2ensite example.com.conf and sudo service apache2 reload to reload apache2 configuartions and sudo service apachIe2 restart from the on I added the address my site points to in /etc/hosts:
127.0.0.1 localhost example.com
127.0.1.1 tangaye
After doing all this when I run php artisan serve from my laravel site directory I still see my site being launch like this:
Laravel development server started: http://127.0.0.1:8000
After all I have done I expected to rather see this:
Laravel development server started: example.com
The worst thing is when I try to access example.com in my browser it tends to search for it on the internet.
At this point I don't really understand what really I'm doing. All I want is to be able to customize my site domain name LOCALLY and add other sub domains.
Will appreciate any help. Thanks!
You can't specify port numbers in /etc/hosts. There's no way to get around that part.
You should be able to just throw example.com after the localhost definition:
127.0.0.1 localhost example.com
and then it will also resolve to 127.0.0.1 ... then it's just a matter of name-based hosting configurations in Apache. Your file looks pretty good, but DocumentRoot is specifying a folder, not a file. Remember to do an a2ensite to enable your site (it's really just creating a symlink in sites-enabled pointing at the sites-available file) and restart Apache.
To avoid your browser interpreting a web address as a search term, you can prefix it with http://
Note that PHP's built-in development server and Apache are two completely separate ways to serve a PHP webpage/app.
php artisan serve is a rapid development tool, allowing for easy access to a PHP project without the need to set up a full-fledged web server (e.g. Apache). All you need is PHP and you can run Laravel or other PHP projects. (It's also important to note that this should be used for development only, never in production.)
Apache, on the other hand, is a full-featured web server, with all the bells and whistles, including virtual host management. And it works over port 80, so no need to add the port to your URLs.
If you want to use a named URL in your development environment, you should:
Install Apache
Configure Apache, including virtual hosts and PHP configuration.
Modify your hosts file to point your chosen development domain name to your local machine (or the machine serving your app, which could be a Vagrant box, Docker, etc. if you choose to use such tools).
Don't bother using php artisan serve at all.

Django and Php Sites on single Apache Server

I have a Django site running on ec2 instance (ubuntu) on apache2 using mod_wsgi. I have placed it in /var/www/django_project. It is Up and running without any issues. Now i want to host another site (php, mysql) on this ec2 instance only. I tried to configure my httpd.conf and added php directory with proper permissions, but I believe due to Alias setting in mod_wsgi, any request above '/' is taken up by django.
I DO NOT have any domain name. I access my Django site with IP of machine (i.e w.x.y.z/django_app).
Correct me if I am wrong : Since i do not have server name, I cannot have both site running on port 80 using virtual Hosts.
And I do not mind running them on different ports either. Please suggest me a way to host php site on this server. which file to configure and how to configure it.
My httpd.conf file:
Alias /static /var/www/resumerepo/static
<Directory /var/www/resumerepo/static>
order deny,allow
Allow From All
</Directory>
WSGIScriptAlias / /var/www/resumerepo/resumerepo/wsgi.py
WSGIPythonPath /var/www/resumerepo
<Directory /var/www/resumerepo>
<Files wsgi.py>
Order deny,allow
Allow From All
</Files>
</Directory>
It works fine and my app is accessible. However if i put it in one virtual host and make another virtual host, apache restart throws an error saying PythonPath can not be in virtual host.
You can't do this easily if your django project is accessible via the root of your domain (or your IP), for example: http://1.2.3.4 -> leads to your django project`.
I think, one solution could be to move your django project to a subdirectory, like http://1.2.3.4/django, and make your php project also accessible in subdirectory, like http://1.2.3.4/php.
Or you can create a new virtual host, listening on port 8080, for example, for your php project. This way :
http://1.2.3.4 leads to your django project
http://1.2.3.4:8080 leads to your php project
The second option may be easier to set up, as you won't have to change config for your django project.
Your vhost file could look like :
<VirtualHost *:8080>
ServerAdmin contact#yourdomain
DocumentRoot /var/www/php
<Directory /var/www/php>
AllowOverride All
Order allow,deny
Allow From All
</Directory>
</VirtualHost>
Maybe this won't work : according to Apache documentation, you should not use virtual hosts without ServerName.

XAMPP localhost returns object not found after installing Laravel

After much faffing about I got laravel to work with XAMPP. However, I can't seem to access directories in the htdocs folder via localhost now. Attempt to access a file returns Object not found! along with The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.
The changes I made to get laravel working seems like a blur now. The only thing I remember doing is editing the hosts file to enable the virtual host to work by adding 127.0.0.1 laravel.dev in the hosts file (using a mac btw). I also added a virtual host to the httpd-vhost.conf file.
I did undo the above changes but it didn't make a difference.
Any thoughts on whats gone wrong?
Thanks.
Dispelling Confusion
Just thought I'd clarify what my experience is. Before installing laravel 4 I could access all my projects with localhost/someProjectName but now it fails.
I'm trying to identify what change caused this behaviour. Btw, I have no problems accessing my laravel project (my mapping allows me access to it via laravel.dev)
Look into your /etc/httpd.conf file and see if you have Virtual hosts activated.
If so, check your etc/extra/httpd-vhosts.conf file. You might have set up a VirtualHost already.
EDIT: I have found that once you turn on Virtual Hosts, XAMPP needs a default VirtualHost for your basic htdocs files
Try adding a default VirtualHost (at the bottom of the file) like so:
<VirtualHost *:80>
ServerName localhost
DocumentRoot "/Applications/XAMPP/htdocs"
<Directory "/Applications/XAMPP/htdocs">
Options Indexes FollowSymLinks Includes execCGI
AllowOverride All
Order Allow,Deny
Allow From All
</Directory>
</VirtualHost>
It sounds to me like it is a problem with the way your directories are configured. Be sure to create a Virtual Host (if you're using Apache) that points to the public folder within your application directory.
For example, if your Laravel project is under /Applications/XAMPP/htdocs/Laravel then set up a Virtual Host like this:
<VirtualHost *:80>
DocumentRoot /Applications/XAMPP/htdocs/Laravel/public
# Other directives here
</VirtualHost>
Additionaly, if you're working with PHP >= 5.4, SSH into the application folder and run
./artisan serve
(Be sure that your PHP executable is in your PATH variable). Then go localhost:8000 and you should have your application running.
Running this command runs the PHP built-in webserver and saves you the trouble of configuring virtual hosts.
In your Apache's http.conf, find the DocumentRoot line and add the subdirectory /public on the end.
Once that is done and you've restarted Apache, you'll be able to access everything which is contained within your htdocs/public folder (including subdirectories of that folder), along with any routes you've defined in Laravel.
Laravel is designed to be set up this way as to protect the code and files by not having them in the folder which is served out to the web.
I have same issue and found that there are miss configuration in vhost. So that's are correct configuration.
in etc/extra/httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "D:/xampp/htdocs/laravel-master/public"
ServerName laravel.local
ErrorLog "logs/laravel-master-error.log"
<Directory D:/xampp/htdocs/laravel-master/public>
AllowOverride All
Order Allow,Deny
Allow From All
</Directory>
</VirtualHost>
In the hosts file
127.0.0.1 laravel.local
I don't know if you're running L4 or L3. However, launch CLI and
$ cd ./path/to/project
Then for L4:
$ php artisan serve
For L3:
$ php -S localhost:8000 -t public
Now you can go to localhost:8000 and see your application.
You're having problem because the object really doesn't exist in your htdocs directory. You don't have to append xampp after localhost or 127.0.0.1 because xampp will treat it as an object or a folder under htdocs.
if you want to access your blog, make sure you have a blog folder under htdocs and put in your URL localhost/blog

Categories