By itayperry91
I have been trying to host a website (php project) on Digital Ocean using Ubuntu 16.04.5 and apparently it’s pretty complicated for the inexperienced. I uploaded all files to var/www/html using FileZilla and the main router doesn’t work. Instead of domain/login router the only router that works is domain/index.php/login. I’ll show you - http://www.itayperry.com/index.php/login
Why does this happen? The index.php should’nt be there. I would love for some help :)
BTW, the project is built in a Slim Framework (with Twig) and the main file is index.php containing a routers.php requirement indise of it. These are my project files on GitHub: https://github.com/itayperry/School-Project and I’m using Apache 2.4.18
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Ensure the .htaccess file in the directory structure contains:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
You also need a directory directive to enable .htaccess files and allow the RewriteEngine directive to be used. This is sometimes done globally in the httpd.conf file, but its generally a good idea to limit the directive to just your virtual host by enclosing it in your VirtualHost configuration block. This is generally setup in your configuration in the form of:
<VirtualHost *:80>
ServerAdmin me@mysite.com
DocumentRoot "/path/www.mysite.com/public_html"
ServerName mysite.com
ServerAlias www.mysite.com
#ErrorLog "logs/mysite.com-error.log"
#CustomLog "logs/mysite.com-access.log" combined
<Directory "/path/www.mysite.com/public_html">
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
As a result, Apache will send all requests for non-existent files to my index.php script in which I instantiate and run my Slim application. With URL rewriting enabled and assuming the following Slim application is defined in index.php, you can access the application route below at “/login” rather than “/index.php/login”.
ServerName mysite.com
ServerAlias www.mysite.com
<Directory "/path/www.mysite.com/public_html">
AllowOverride All
Order allow,deny
Allow from all
</Directory>
All of this doesn’t appear on my virtual host - but still - I swiped the .htaccess file with what you told me to write and then I restarted the Apache and it worked!!! Thank you so much! I’ve been stuck for three days. I’m not a pro and these things are very complicated.
Btw, I have a database for that project in phpMyAdmin, can I connect it to the project? and will it be updated after every user interaction? Or is it better to copy it and let all the changes be done solely on the server? I’d be happy to get your advice ;)
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.