Prepare your development environment for PHP and Javascript development in Ubuntu 20.04 based distros.
Setting up PHP/JS Development Environment Ubuntu 20.04 based distros
Prerequesites
sudo apt-get install software-properties-common curl
Install Git
sudo apt-get install git
Install Vim
sudo apt-get install vim
Install Maria DB
sudo apt-get install mariadb-server mariadb-client
Install apache and php and PhpMyAdmin
sudo apt-get install apache2 apache2-doc apache2-utils libapache2-mod-php php7.4 php7.4-common php7.4-gd php7.4-mysql php7.4-imap phpmyadmin php7.4-cli php7.4-cgi libapache2-mod-fcgid apache2-suexec-pristine php-pear mcrypt imagemagick php7.4-curl php7.4-intl php7.4-pspell php7.4-sqlite3 php7.4-tidy php7.4-xmlrpc php7.4-xsl memcached php-memcache php-imagick php7.4-zip php7.4-mbstring php-soap php7.4-soap
Select the following as answers:
Web server to reconfigure automatically: <– apache2
Configure database for phpmyadmin with dbconfig-common? <– Yes
MySQL application password for phpmyadmin: <– Press enter
Create DB User
sudo mysql
CREATE USER 'dbuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON * . * TO 'dbuser'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
exit
Check whether the db user is logging fine. Open browser and go to http://localhost/phpmyadmin/. Login using the credentials dbuser
and password
Install Mail Hog
Install the Go programming language
cd ~
sudo apt-get install golang-go
mkdir gocode
echo "export GOPATH=$HOME/gocode" >> ~/.profile
source ~/.profile
Download and configure MailHog
go get github.com/mailhog/MailHog
go get github.com/mailhog/mhsendmail
sudo cp ~/gocode/bin/MailHog /usr/local/bin/mailhog
sudo cp ~/gocode/bin/mhsendmail /usr/local/bin/mhsendmail
Letβs connect PHP with MailHog at php.ini. Find the sendmail_path setting and set it in the following way:
sendmail_path = /usr/local/bin/mhsendmail
The php.ini for both CLI and Apache should be configured. It can be found in the folder /etc/php/7.4/apache2 and /etc/php/7.4/cli. The location may change based on the distro.
Start MailHog when the system boots
- Create the file
/etc/systemd/system/mailhog.service
.
sudo vim /etc/systemd/system/mailhog.service
- Paste the following into it:
[Unit]
Description=MailHog service
[Service]
ExecStart=/usr/local/bin/mailhog \
-api-bind-addr 127.0.0.1:8025 \
-ui-bind-addr 127.0.0.1:8025 \
-smtp-bind-addr 127.0.0.1:1025
[Install]
WantedBy=multi-user.target
- Start the service :
sudo systemctl start mailhog
. Verify it is working by accessing the URL – http://127.0.0.1:8025 - Enable the service so it runs on bootup
sudo systemctl enable mailhog
- Restart your system
- After restarting, mail hog can be accessed in the URL – http://127.0.0.1:8025
Install Composer
cd ~
curl -sS https://getcomposer.org/installer -o composer-setup.php
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
#To switch composer 1
sudo composer self-update --1
Install Node Js using NVM
cd ~
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
#install Node v10
Close the terminal and reopen it again. Run the command
nvm install v10.24.0
Install Sublime Text
Install the GPG key:
wget -qO - https://download.sublimetext.com/sublimehq-pub.gpg | sudo apt-key add -
Ensure apt is set up to work with https sources:
sudo apt-get install apt-transport-https
Set the channel:
echo "deb https://download.sublimetext.com/ apt/stable/" | sudo tee /etc/apt/sources.list.d/sublime-text.list
Update apt sources and install Sublime Text :
sudo apt-get update
sudo apt-get install sublime-text
Enable Apache Mod Rewrite
Run the following command to enable mod-rewrite
sudo a2enmod rewrite
Then change AllowOverride None
to AllowOverride All
for directory /var/www/
in the file /etc/apache2/apache2.conf
Install VisualStudio Code
Download visual studio code from https://code.visualstudio.com/Download and download the .deb file. Install the deb file.
Install Wine
If your system is 64 bit, enable 32 bit architecture
sudo dpkg --add-architecture i386
Now run the commands
wget -nc https://dl.winehq.org/wine-builds/winehq.key
sudo apt-key add winehq.key
sudo add-apt-repository 'deb https://dl.winehq.org/wine-builds/ubuntu/ focal main'
sudo apt update
sudo apt install --install-recommends winehq-stable
Install DBeaver
sudo add-apt-repository ppa:serge-rider/dbeaver-ce
sudo apt-get update
sudo apt-get install dbeaver-ce
Install Docker
Run the following commands
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
Then run the following command
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io
sudo usermod -aG docker $USER
Install Docker Compose
Install the needed Docker composer version v1.27 is the latest stable version as of Sep 10, 2020.
Run
sudo curl -L "https://github.com/docker/compose/releases/download/1.27.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose