DEV Community

Cover image for Struggling to Manage Multiple PHP Versions and Frameworks? Here's the Perfect Solution!
Golam Rahman Sagor
Golam Rahman Sagor

Posted on

Struggling to Manage Multiple PHP Versions and Frameworks? Here's the Perfect Solution!

Are you struggling to manage multiple PHP projects or frameworks running on different PHP versions? You’re not alone! But worry no more — I’ve got the perfect solution for you.

Let me introduce Local by WP Engine, a powerful and free development tool designed primarily for WordPress but versatile enough to support any PHP project or framework. Today, I’ll show you how to use Local to run not just WordPress sites but also raw PHP applications and frameworks like Laravel, all in a step-by-step guide.

Ready to simplify your development process? Let’s dive in!

Download and Install Local

  1. Visit https://localwp.com to download Local.
  2. Install it on your machine and open the application.

Create a WordPress Site

  1. Open Local and click the “+” icon or the “Create a New Site” button to start a new site.
  2. Enter a name for your site (e.g., “MyWordPressSite”) and click “Continue.”
  3. Choose an environment: select Preferred for recommended settings or Custom to specify the PHP version, web server type (Apache or Nginx), and MySQL version.
  4. Set up WordPress admin credentials by entering your admin username, password, and email address. Enable the “Multisite” option if needed.
  5. Click “Add Site” and wait for Local to create the site, download WordPress core files, and set up the database.
  6. Once the site is ready, click “Start Site” to run it, and click “Open Site” to view it in your browser. Use “Admin” to access the WordPress dashboard.

Locate the Root Directory

  1. In the Local application, click the “Site Folder” button for your project.
  2. Open the app/public directory — this is your project’s root directory.

Set Up a Laravel Application

  1. Delete all files inside the app/public directory.
  2. Copy your Laravel project files into this directory.
  3. Open the .env file in your Laravel project and update the database credentials with values from Local's database tab: host, username, password, and port.

Configure the Server

For Apache

  1. Create a .htaccess file in the app/public directory.
  2. Add the following code:
<IfModule mod_rewrite.c>  
Options +FollowSymLinks  
RewriteEngine On  
RewriteCond %{REQUEST_URI} !^/public/   
RewriteCond %{REQUEST_FILENAME} !-d  
RewriteCond %{REQUEST_FILENAME} !-f  
RewriteRule ^(.*)$ /public/$1   
#RewriteRule ^ index.php [L]  
RewriteRule ^(/)?$ public/index.php [L]   
</IfModule>
Enter fullscreen mode Exit fullscreen mode

For Nginx

  1. Open the /conf/nginx/site.conf.hbs file from the project directory.
  2. Replace the root directive:
# Old  
root "{{root}}";  
# New  
root "{{root}}/public";
Enter fullscreen mode Exit fullscreen mode
  1. Restart Local to apply changes.

Start Your Application

  1. Start the application from Local.
  2. Visit the project URL to verify everything is working correctly.

Conclusion

With Local, you can easily manage multi-version PHP applications, including raw PHP, Laravel, and more. It’s simple, efficient, and free. Download Local from https://localwp.com and simplify your PHP development today!

Have any questions or tips you’d like to add?
Feel free to drop them in the comments below!

Thanks for taking the time to read my article!

— Sagor

Top comments (1)

Collapse
 
xwero profile image
david duymelinck

If there is a php setup solution that doesn't comply with the php evolution it is Wordpress. It has php 7.4 as a minimum requirement. This version is two years out of date.

So please, don't rely on a developer solution that has backwards requirements.