DEV Community

Cover image for Setup PHP Laravel (Postgresql & mysql) Development Environment on Ubuntu 22.04 Jammy
Awal Ariansyah
Awal Ariansyah

Posted on

 

Setup PHP Laravel (Postgresql & mysql) Development Environment on Ubuntu 22.04 Jammy

I'm not a big fan of PHP and mainly worked with Node.js project, this time I get a project using a legacy PHP/Laravel code bases and It's really frustrating for me to just run the code because I'm not getting used to the ecosystem.

In case you are running the same issues or maybe me, I decided to wrote it here.

OS Information

Image description

Installing PHP

Be sure which PHP version you want to install, because compatibility matter. A lot. Seriously.

The default APT repository is PHP 8. In my case, I need to install PHP 7.4.

sudo apt install -y apache2 php7.4 php7.4-common php7.4-cli php7.4-xml php7.4-mbstring php7.4-gd php7.4-pgsql
Enter fullscreen mode Exit fullscreen mode

Installing composer

curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/bin --filename=composer
Enter fullscreen mode Exit fullscreen mode

Laravel global installer

composer global require laravel/installer
Enter fullscreen mode Exit fullscreen mode

Installing mysql

sudo apt install -y mysql-server php7.4-mysql
Enter fullscreen mode Exit fullscreen mode

Installing postgresql

sudo apt install -y postgresql pgadmin4
Enter fullscreen mode Exit fullscreen mode

Setup postgresql & pgadmin

sudo /usr/pgadmin4/bin/setup-web.sh

sudo -i -u postgres

psql

ALTER USER postgres WITH PASSWORD 'yourpostgrespassword';

\q

logout
Enter fullscreen mode Exit fullscreen mode

The default postgresql information:

Hostname: localhost
Port: 5432
Username: postgres
Password: yourpostgrespassword
Enter fullscreen mode Exit fullscreen mode

Now you can access it via Pgadmin desktop app or the web version at http://127.0.0.1/pgadmin4/browser/

Run existing laravel project

  1. Clone the project to local
  2. cd into it
  3. Run composer install
  4. Fix every composer's lockfiles issues (usually missing php extension) (if there's any). Example:
sudo apt install -y php7.4-gd
sudo service apache2 restart
Enter fullscreen mode Exit fullscreen mode

Then run composer install again.

  1. Run npm install Make sure you have already installed python. In my case I need to install python2 and set the npm global variable.
sudo apt install python2
npm config set python /usr/bin/python2
Enter fullscreen mode Exit fullscreen mode
  1. Run npm run dev
  2. Run cp .env.example .env
  3. Edit the .env file configuration (especially in DB, make sure you created an empty database first)
  4. Run php artisan key:generate
  5. Run php artisan migrate
  6. Run php artisan serve

Hope it helps~

Top comments (0)

The AI Brief

AI generated git commit messages

Minimize the struggle of remembering what you just coded. AI-generated commits make it easier to manage projects and keep track of changes. The Nutlope/aicommits project demonstrates how AI can improve commit messages.

I open sourced an AI that creates any UI in seconds

Make AI-generated user interfaces a breeze. This open-source project harnesses the power of generative AI technologies like chatGPT to create versatile, quick, and intuitive UI components.

Use AI to commit like a PRO in 1 second

Upgrade your commit message game with AI. Boost your productivity by using ChatGPT to generate commit messages and avoid context switching. OpenCommit is an open-source library that helps you achieve this easily.

Build your own ChatGPT starter kit

Train AI models on custom data for improved domain-specific knowledge. Combine the power of WebView technologies and this starter kit to train your ChatGPT model on specific websites, allowing for better-optimized outcomes.