Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSandra Vos
21,652 PointsPutting website online
I went along with the course 'Building Websites with PHP'. Now my php website is finished and I wanted to test it online. But when I put it online the index.php works, but the contact page gives a 500 internal server error. The entire website worked locally though..
Can anyone explain to me what I need to change when I put the website online? Or should it work online if it works locally?
9 Answers
Sandra Vos
21,652 PointsI solved the problem. It was indeed the .htaccess. I had to uncomment the
RewriteBase /
part -_- I feel so stupid now. But now I have a little more experience on finding a problem. Thanks for your responses guys!
Clayton Tevebaugh
7,617 PointsMy only guess is something got weird with folders when you put it online? Is your file tree the same?
Sandra Vos
21,652 PointsYes my file tree is exactly the same. Then the only option would be a problem with the .htaccess file. I can't create files starting with a dot on my mac.. So I did some weird trick in terminal and now I got a htaccess_files folder with weird stuff in it, but the weird stuff works on my mac. In Sublime Text it shows the htaccess_files folder and a .htaccess file. I didn't upload the htaccess_files folder though. I saved the .htaccess file in Sublime Text as a file with the name "htaccess" (so I can see it in Finder), uploaded it and put a dot in front of it in Transmit (my ftp client). But I don't get why this shouldn't work either.
Daniel Lozano
2,732 PointsMaybe it could be an error inside the .htacces file, because its an internal server error.
Sandra Vos
21,652 PointsThanks, I will look at it!
Andrew Rady
20,880 PointsSandra,
I just did the same thing and I have to say THANK YOU! I knew it was something to do with the .htaccess file, but finding this post fixed the problem in 5 minutes.
Sandra Vos
21,652 PointsHaha well, lucky us :P
Andrew Rady
20,880 PointsDid you have an issues with the swift mailer on your live site? I am getting a 500 internal error and I am not sure if it my hosting company.
Sandra Vos
21,652 PointsYes I indeed have an issue with it.. I only tested in with no info, then I get a failure message. But when I fill in the form and send it, I get a blank page :| I will take a look at it.. Tomorrow, it's almost night over here.
Sandra Vos
21,652 PointsAt this moment I have no idea how to solve this. At this moment I don't have a blank page anymore, but I still get the error 'Something went wrong'. But what went wrong? I haven't got a clue.
I used a different transport type - link: http://swiftmailer.org/docs/sending.html#transport-types
I changed the following:
$transport = Swift_SmtpTransport::newInstance('smtp.mail.webhosting.com', 25)
->setUsername('my_username')
->setPassword('my_password');
It does work now (my error messages at least, no blank pages anymore). But my message doesn't get send. Then it gives the 'something went wrong' error.
Andrew Rady
20,880 PointsI have gotten some progress as well. I tried using an ssl port and it seems to work, but it will not connect to my gmail account even when I enter the correct login information. Here is my code.
$transport = Swift_SmtpTransport::newInstance('smtp.example.org', 587, 'ssl');
->setUsername('my_username')
->setPassword('my_password');
$mailer = Swift_Mailer::newInstance($transport);
Looking at the documentation (http://swiftmailer.org/docs/sending.html) this is how they recommend it. I think it's one step closer if you want to send emails through your gmail.
Sandra Vos
21,652 PointsI figured it out!
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 587, 'tls')
->setUsername('gmail address');
->setPassword('gmail password');
$mailer = Swift_Mailer::newInstance($transport);
BUT
You need to go to https://www.google.com/settings/security/lesssecureapps and give permission to apps with lower security.
Sounds not very attracting to me, but it works. Now I have to figure out how to get my own webhosting shizzle to work. Let me know if you fix it too!
Andrew Rady
20,880 PointsHey Sandra I found the problem out that is causing my code not to send emails. I was listen to the install swiftmailer on the course and Hampton talked about the sendmail location at 4:16 (https://teamtreehouse.com/library/building-websites-with-php/contact-form-sending-email/installing-swiftmailer). In the video it is '/usr/sbin/sendmail -bs') I googled the send mail path to my hosting company(Godaddy) and plugged it into my code and it works! Here is what I mean....
$transport = Swift_SendmailTransport::newInstance('/usr/lib/sendmail -bs');
$mailer = \Swift_Mailer::newInstance($transport);
Let me know if that helps you out.
Sandra Vos
21,652 PointsThis doesn't work for me.. I found the send mail path of my hosting (PcExtreme, dutch hosting) and it's the same Swiftmailer uses as default:
$transport = Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs');
This 'solution' does display the message that the mail was send, no blank pages or whatsoever. Looks perfect on the website, but I just don't get any mail! So in theory I believe the mail was sent, but never got to his destination.. (The condition in the index.php only gives the success message when there is something to send). I can't figure out why this isn't working.
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 587, 'tls')
->setUsername('mygmail@gmail.com')
->setPassword('my-password')
This solution works perfect to me, but only with Gmail. I can't get it to work with my hosting. No clue why.. The only thing I have to change are the smtp address, port, username and password. I'm completely sure this info is correct. So it must be some other thing I have to change I guess.. When I use my hosting info I get the message 'something went wrong'. So the message wasn't even sent.
Sandra Vos
21,652 PointsI'm not quite sure, but do you (or anyone else!!) know if I might need a ssl certificate? My hosting account doesn't have a certificate at the moment, I have to buy one. They say it creates a secure environment for visitors, so it would make sense to me if I need one.
Andrew Rady
20,880 PointsI don't have an ssl certificate and mine will send, but I am not trying to send through gmail.
Sandra Vos
21,652 PointsI'm not sure, but over here in the Netherlands we sometimes have strict rules. All webshops need to have a ssl certificate according to the law. As I've read I believe all personal info between website and customers needs to be secured and therefor also need a ssl certificate. I don't know if there are these kind-of rules in de US?
Josh Naylor
19,341 PointsI am still having an issue!
I uncommented the RewriteBase /, but I am still not able to get to any pages except the homepage and none of the images are loading! For the images, when I inspect element and try to open the image link, I get a "403 Forbidden" error. Any ideas?
Sandra Vos
21,652 PointsI don't quite remember how I solved this issue anymore.. I'm no so good with php yet. But as far as I understand your problem, you may create wrong urls for your pages and images. So that could be the problem why they're not showing and maybe that's what causes the 403 error too (I'm not sure).
I've did a search on 403 error. It seems it has probably something to do with wrong urls (I guess I was right). So your links probably have a mistake in the urls. Be aware it's also upper-, lowercase sensitive.
Anyway this is what I've put in my htaccess file:
RewriteEngine On
# Some hosts may require you to use the `RewriteBase` directive.
# If you need to use the `RewriteBase` directive, it should be the
# absolute physical path to the directory that contains this htaccess file.
#
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
Tom Checkley
25,165 PointsTom Checkley
25,165 PointsHi I've been having the same problem, I've uncommented the line in my .htaccess file so it now looks like this-
I'm still getting the 500 internal server error message when links are clicked from the home page, can anybody spot what i might be doing wrong?
Thanks
Sandra Vos
21,652 PointsSandra Vos
21,652 PointsHi Tom, I can't find any mistakes in your code. It has to work unless your not working from the root map I guess .. Did you do a 'hard refresh' (cmd+r or f5 on windows I believe?). You can also check if your url is formed/spelled the right way. You can check what url is given to your links by hovering over it. In Chrome it shows te url of the link on the bottom (left) of the page. I hope this helps you to uncover the problem. Let me know :)
Tom Checkley
25,165 PointsTom Checkley
25,165 PointsThanks Sandra, it's working now. Now just need to work out why the mail isn't sending.
Sandra Vos
21,652 PointsSandra Vos
21,652 PointsIf you run into any problems with your mailer, you can always ask :) I also had a lot of problems with it.. My codebuddy helped me out. You can also find more info in this discussion. Or you could contact your hosting. This helped me out a lot since they sometimes handle things differently from other hosting companies.