r/PHPhelp • u/[deleted] • Oct 09 '20
Getting extremely frustrated with debugging situation
I keep having to post questions here because I keep getting stuck on my homework. The way our professor wants us to do our work, we're supposed to write our HTML + PHP in Notepad++, upload it to the class server, test it, re-write it, re-upload it, test it again, and so on, until it works. The problem is that there's no error messages more helpful than HTTP error 500, even with the error reporting code y'all gave me the other day. I still only get HTTP error 500 messages. Is there some other IDE that I can use that will spot syntax issues and other stuff before I upload it? I'm really sick of getting stuck and having to ask for help. Thanks.
PS. I know I sound upset, but I'm not mad at you guys, I'm mad at the situation.
6
Oct 09 '20
There should be a plugin for php in notepad++ but its been years since Ive used it. I personally use phpstorm. Visualstudio is supposed to be pretty good. Idk if netbeans is still around but it used to support php pretty well. What you should be doing is installing a local mamp/xampp server and setup your project in a folder in the root web directory. This way you can load your site via localhost and when you save the code in notepad++ you can just refresh the page in your browser. This way will also let you configure php so you can print errors on screen or view the logs. Then when your done upload the project to the ftp
4
u/AlphaOmega5732 Oct 09 '20
Personally I'm a big fan of Xampp. Setting up a localhost means you can tweak the code and get instant feedback. Great way to learn imo, plus you can experiment with the code which helps to understand exactly what the code does.
6
u/Atulin Oct 09 '20
Is there some other IDE that I can use that will spot syntax issues and other stuff before I upload it?
You're a student, which means the best PHP IDE there is is available to you for free.
Look into Jetbrains student license. This will get you – among other IDEs – PHPStorm, our lord and savior.
For a local server so you can test it even without uploading it first, Laragon is the easiest to set up.
2
4
u/drwho_who Oct 09 '20
there are various online code sandboxes you can try using for testing, here's one
7
u/przemo_li Oct 09 '20
Yes you can.
PHP have built in developer server!
https://www.php.net/manual/en/features.commandline.webserver.php
You point it at php file you want to serve, provide it with http port, and then use "localhost:port-you-choose" to access it in the browser.
Have fun!
5
Oct 09 '20
Until he spends 3 hours to get the php binary installed on windows. And some development might actually require Apache. Xampp is the way to go for beginners and its been that was as far as I can remember
3
u/hackiavelli Oct 10 '20
Installing on Windows is as simple as downloading the binary and including the path. The longest part is by far the download.
1
u/przemo_li Oct 10 '20
Sorry, I have moved to WSL and haven't installed from windows.php.net for a while now. Last time installing those binaries was easy, and with built in web server that is all you need to do (mostly - since windows build ships with plenty of extra libraries that just need entry in ini)
1
Oct 10 '20
I recall having a frustrating time trying to get multiple versions to switch between on a win10 dev machine. I pray for people who have to deal with with windows servers for website stuff
1
u/przemo_li Oct 10 '20
Windows servers are semi OK.
Not a CLI friendly but if you stick to named & versioned PHP its OK. Minus of course some performance. Given choice winner is clear but Win is not a disaster.
As dev machine though its less appealing. I jumped to WSL as as I could. Am still on WSL 1 but even that is huge productivity boost (even with PHPStorm which by itself tires very hard to overcome Windows issues)
1
Oct 10 '20
I tried wsl in like 2017, and still felt handcuffed. Is it any better in 2020? I had a lot of success using a vm that runs off a 1tb external ssd. Makes it super easy to switch between my laptop and desktop while keeping the same projects and environment between the two
1
u/przemo_li Oct 11 '20
WSL2 is more like well integrated VM.
I only work with Windows at my work.
Am happy Linux only geek at home :)
5
u/CyberJack77 Oct 09 '20
VScode is a free IDE that can help you. https://code.visualstudio.com/docs/languages/php
If you have PHP installed locally, use php -l to find syntax errors.
3
u/HolyGonzo Oct 10 '20 edited Oct 10 '20
Drives me nuts when the top reply to a question like this does not include php -l and your comment is down at the bottom. I upvoted your comment.
I mean, come on, people. This is a student learning PHP and hitting HTTP 500 errors. I'd bet that 90% of the time he gets these errors, it's a simple syntax error.
I've been writing PHP for over 20 years now and I still get simple syntax errors from time to time. The php -l yourscript.php check is the best way to catch those things, especially since you can't always work with web servers under your control and production servers often hide errors that could inadvertently expose a part of the code or logic.
2
u/equilni Oct 09 '20
A suggestion would be to us VS Code (it's free) instead of Notepad++. https://code.visualstudio.com/
Install the PHP tools noted in the main screen. Then when you are coding, you can check if you have errors in the terminal view
3
u/ontelo Oct 09 '20
500 usually points to code.
Put this at the file called first:
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);If that doesn't help. Check the functions you're calling. Depending the system function criticals are not usually echoed.
1
u/CenturiesAgo Oct 09 '20
VScode has my vote. It even has an FTP plugin so u can upload/download/compare with online at the click of a button. The plugin is SFTP i believe.
Edit: As mentioned by others, you can install a PHP plugin.
Edit #2: If you can, ask your teacher to configure the web server to send errors to the browser.
1
u/TechIsSoCool Oct 10 '20
You could add code to open a text file and log to it throughout your code where you might be having issues. Print out variable values, etc. Run it, then after you get the 500 response, read your log file to see what happened. Remove the logging code when it's working.
0
u/AdmiralAdama99 Oct 09 '20
Sounds like you need step debugging. Lets you go line by line, and lets you hover over variables to see their values.
Are you on windows? Personally I use xampp, vs code, and xdebug. A bit of a learning curve, but if you can get that combo set up and working, i think itd be very helpful.
8
u/hackiavelli Oct 09 '20
It's okay to be upset. Academia is often years (if not decades) behind modern best practices and it can be extremely frustrating. Your teacher has you working in a laborious and tedious way in which a professional dev never would.
I would encourage you to set up a local web server (there are many ways to do this: Docker, WSL, Vagrant, PHP's built-in server, a million different *AMP programs) and an IDE. PHPStorm is an industry leader IDE and offers free educational licenses.
If you want to do quick and simple code checking online, there's 3v4l.org. It lets you execute code against multiple versions of PHP.
As for the 500 error, some servers won't let you override the error reporting directive in a script. You can check for the display_errors value using phpinfo().