- BlueHolding-Technical-Test
- Setting Up Ubuntu 20.04 on a Virtual Machine
- Docker Engine Installation
- Git Installation
- Generate SSH Key Pair
- Clone the Repository
- Next.js Application Dockerization
- PHP Laravel Application Dockerization
- Environment Settings File Creation
- Docker Compose File Creation
- Applications Deployment
- Configure The PHP Container And Configure The App’s Virtual Host in Apache
- Access the Applications in The Browser
- Dockerize PHP Container Again
- Author
Before you begin, ensure you have the following:
- A virtualization software installed (Vmware Workstation for Linux)
- The Ubuntu 20.04 ISO image downloaded (Ubuntu 20.04)
- Adequate hardware resources (CPU, RAM, and storage) for your virtual machine.
-
Create a New Virtual Machine:
- Open your virtualization software.
- Click "New" to create a new virtual machine.
- Choose "Linux" as the type and "Ubuntu (64-bit)" as the version.
- Allocate 5GB ram and processor configuration .
- Create a new virtual hard disk with 30GB space .
-
Configure VM Settings:
- Select the newly created virtual machine in your virtualization software.
- Go to "Settings."
- Under the "CD/DVD" tab, select the Ubuntu 20.04 ISO image.
-
Start the Virtual Machine:
- Click "Start" to launch the virtual machine.
- The Ubuntu installation menu will appear. Choose "Install Ubuntu" and press Enter.
-
Choose Installation Options:
- Select your language and click "Continue."
- For "Updates and Other Software," choose to "Download updates while installing Ubuntu" .
-
Configure Time Zone and User:
- Select cairo as time zone on the map and click "Continue."
- Create a user account by providing name, username, password, and computer name.
- Click "Continue."
-
Install Ubuntu:
- The installation process will begin. Wait for it to complete.
- Once installation is done, click "Restart Now."
-
Post-Installation Setup:
-
update the system and install additional software using the package manager:
sudo apt update && sudo apt upgrade
-
install curl
sudo apt-get install curl
-
- Install docker:
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh ./get-docker.sh
- Start and enable the Docker service:
sudo systemctl start docker
sudo systemctl enable docker
- Install git:
sudo apt install git
- configure git:
git config --global user.name "mariohany98"
git config --global user.email "[email protected]"
- install ssh:
sudo apt install ssh
- generate a private and public key pair:
ssh-keygen -t rsa
- copy the public key to git server:
copy the content of the following file: /home/mario/.ssh/id_rsa.pub
navigate to GitHub settings on the UI >>>>>> SSH and GPG keys >>>>>> Add new SSh key
paste the public key and save
git clone [email protected]:mariohany98/BlueHolding-Technical-Test.git
- Navigate to the code repository:
cd ./BlueHolding-Technical-Test/intranet-front-main
- Create Dockerfile for Next.js App
vim Dockerfile
- Build docker image
sudo docker build -t next-app .
- login to DockerHub repository to push the image
sudo docker login
- Tag the Docker image
note:Before pushing the image to Docker Hub, I need to tag it with my Docker Hub username and the desired repository name
sudo docker tag next-app mariohany98/nextjs-app:latest
- Push the Docker Image to DockerHub:
sudo docker push mariohany98/nextjs-app:latest
- Navigate to the code repository:
cd ./BlueHolding-Technical-Test/blue-internal-back-master
- Create Dockerfile for PHP App
vim Dockerfile
- Build docker image
sudo docker build -t mariohany98/php-app:2 .
- Push the Docker Image to DockerHub:
sudo docker push mariohany98/php-app:2
- Navigate to the code repository:
cd ./BlueHolding-Technical-Test/blue-internal-back-master
- Create the file:
cat .env.example > .env
- Only modify the highlighted lines in .env file as the following:
- Navigate to the code repository:
cd ./BlueHolding-Technical-Test/blue-internal-back-master
- Create The Docker compose file:
sudo vim docker-compose.yml
Important Notes:
1- Both the .env file and the docker-compose.yaml file must be in the same directory.
2- The service name of the mysql-db container in the docker-compose.yaml file must be the same as the value of DB_HOST in the .env file.
- Navigate to the code repository:
cd ./BlueHolding-Technical-Test/blue-internal-back-master
- Run the containers:
sudo docker compose up -d
- Execute an interactive shell session (/bin/sh) inside the PHP Docker container:
sudo docker exec -it php /bin/sh
- Navigate to /var/www/html/ :
cd /var/www/html
- Run the following commands:
chown -R www-data:www-data /var/www/html
- This command changes the owner and group of the directory and everything in the directory to www-data. www-data is the default user web servers like Apache.
chmod -R 755 /var/www/html
- This command gives full permission to the user on the directory and everything in the directory. Also it gives only read and execute permission to group and others.
chmod -R 777 /var/www/html/storage
- This command gives full permissions on these directory, so that no matter what process executes the Laravel application, it will be able to read from and write to them.
- Install the dependencies specified in the composer.json
composer install
- Install Vim editor:
apt-get install vim
- Copy the 000-default.conf file and give it a new name (laravel.conf):
cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/laravel.conf
- Edit laravel.conf as follows:
vim /etc/apache2/sites-available/laravel.conf
- Disable the default Apache site:
a2dissite 000-default.conf
- Enable the Laravel App’s site and mod_rewrite:
a2enmod rewrite
a2ensite laravel.conf
- Reload apache service:
service apache2 reload
- Install Node.JS and npm:
apt update
apt install nodejs
apt install npm
- Check that the installation was successful:
node -v
- Navigate to /var/www/html/ :
cd /var/www/html
- Apply database migrations and seed the database:
php artisan migrate --seed
- Generate JWT secret key for JWT authentication:
php artisan jwt:secret
- Install all the dependencies listed in package.json and prepare the application for production use:
npm install && npm run production
- Start the web server:
php artisan serve
1.NextJS Application
- PHP Application
I have Dockerized the PHP container again so that i don't lose all the previous changes when the container stops
- Commit the changes to a new image:
sudo docker commit e0325 mariohany98/php-vuejs-app
- Push the image to a GitHub repository:
sudo docker push mariohany98/php-vuejs-app
- If the running PHP container has stopped unexpectedly or intentionally. Set the new Docker image (mariohany98/php-vuejs-app) in Docker Compose file before running it
Running containers on a single docker host may be good for development and test environment, but in production environment this is not a good idea as this is a single point of failure and to avoid it we should use an orchestration tools like Kubernetes or Docker swarm for high availability and load balancing.
Mario Hany
Feel free to contribute, report issues, or suggest improvements.