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
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
Installing composer
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/bin --filename=composer
Laravel global installer
composer global require laravel/installer
Installing mysql
sudo apt install -y mysql-server php7.4-mysql
Installing postgresql
sudo apt install -y postgresql pgadmin4
Setup postgresql & pgadmin
sudo /usr/pgadmin4/bin/setup-web.sh
sudo -i -u postgres
psql
ALTER USER postgres WITH PASSWORD 'yourpostgrespassword';
\q
logout
The default postgresql information:
Hostname: localhost
Port: 5432
Username: postgres
Password: yourpostgrespassword
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
- Clone the project to local
-
cd
into it - Run
composer install
- 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
Then run composer install
again.
- Run
npm install
Make sure you have already installed python. In my case I need to installpython2
and set the npm global variable.
sudo apt install python2
npm config set python /usr/bin/python2
- Run
npm run dev
- Run
cp .env.example .env
- Edit the
.env
file configuration (especially in DB, make sure you created an empty database first) - Run
php artisan key:generate
- Run
php artisan migrate
- Run
php artisan serve
Hope it helps~
Top comments (0)