This Document is actively being developed as a part of ongoing AlmaLinux learning efforts. Chapters will be added periodically.
This is the multi-page printable view of this section. Click here to print.
Development Environment Setup
- 1: How to Install the Latest Ruby Version on AlmaLinux
- 2: How to Install Ruby 3.0 on AlmaLinux
- 3: How to Install Ruby 3.1 on AlmaLinux
- 4: How to Install Ruby on Rails 7 on AlmaLinux
- 5: How to Install .NET Core 3.1 on AlmaLinux
- 6: How to Install .NET 6.0 on AlmaLinux
- 7: How to Install PHP 8.0 on AlmaLinux
- 8: How to Install PHP 8.1 on AlmaLinux
- 9: How to Install Laravel on AlmaLinux: A Step-by-Step Guide
- 10: How to Install CakePHP on AlmaLinux: A Comprehensive Guide
- 11: How to Install Node.js 16 on AlmaLinux: A Step-by-Step Guide
- 12: How to Install Node.js 18 on AlmaLinux: A Step-by-Step Guide
- 13: How to Install Angular 14 on AlmaLinux: A Comprehensive Guide
- 14: How to Install React on AlmaLinux: A Comprehensive Guide
- 15: How to Install Next.js on AlmaLinux: A Comprehensive Guide
- 16: How to Set Up Node.js and TypeScript on AlmaLinux
- 17: How to Install Python 3.9 on AlmaLinux
- 18: How to Install Django 4 on AlmaLinux
1 - How to Install the Latest Ruby Version on AlmaLinux
How to Install the Latest Ruby Version on AlmaLinux
Ruby is a versatile, open-source programming language renowned for its simplicity and productivity. It powers popular frameworks like Ruby on Rails, making it a staple for developers building web applications. If you’re using AlmaLinux, installing the latest version of Ruby ensures you have access to the newest features, performance improvements, and security updates.
This guide will walk you through the process of installing the latest Ruby version on AlmaLinux. We’ll cover multiple methods, allowing you to choose the one that best fits your needs and environment.
Why Install Ruby on AlmaLinux?
AlmaLinux, a popular Red Hat Enterprise Linux (RHEL) clone, provides a stable platform for deploying development environments. Ruby on AlmaLinux is essential for:
- Developing Ruby applications.
- Running Ruby-based frameworks like Rails.
- Automating tasks with Ruby scripts.
- Accessing Ruby’s extensive library of gems (pre-built packages).
Installing the latest version ensures compatibility with modern applications and libraries.
Prerequisites
Before starting, make sure your system is prepared:
A running AlmaLinux system: Ensure AlmaLinux is installed and up-to-date.
sudo dnf update -y
Sudo or root access: Most commands in this guide require administrative privileges.
Development tools: Some methods require essential development tools like
gcc
andmake
. Install them using:sudo dnf groupinstall "Development Tools" -y
Method 1: Installing Ruby Using AlmaLinux DNF Repository
AlmaLinux’s default DNF repositories may not include the latest Ruby version, but they provide a stable option.
Step 1: Install Ruby from DNF
Use the following command to install Ruby:
sudo dnf install ruby -y
Step 2: Verify the Installed Version
Check the installed Ruby version:
ruby --version
If you need the latest version, proceed to the other methods below.
Method 2: Installing Ruby Using RVM (Ruby Version Manager)
RVM is a popular tool for managing multiple Ruby environments on the same system. It allows you to install and switch between Ruby versions effortlessly.
Step 1: Install RVM
Install required dependencies:
sudo dnf install -y curl gnupg tar
Import the GPG key and install RVM:
curl -sSL https://rvm.io/mpapis.asc | gpg2 --import - curl -sSL https://get.rvm.io | bash -s stable
Load RVM into your shell session:
source ~/.rvm/scripts/rvm
Step 2: Install Ruby with RVM
To install the latest Ruby version:
rvm install ruby
You can also specify a specific version:
rvm install 3.2.0
Step 3: Set the Default Ruby Version
Set the installed version as the default:
rvm use ruby --default
Step 4: Verify the Installation
Check the Ruby version:
ruby --version
Method 3: Installing Ruby Using rbenv
rbenv is another tool for managing Ruby versions. It’s lightweight and straightforward, making it a good alternative to RVM.
Step 1: Install rbenv and Dependencies
Install dependencies:
sudo dnf install -y git bzip2 gcc make openssl-devel readline-devel zlib-devel
Clone rbenv from GitHub:
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
Add rbenv to your PATH:
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc echo 'eval "$(rbenv init -)"' >> ~/.bashrc source ~/.bashrc
Install
ruby-build
:git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
Step 2: Install Ruby Using rbenv
Install the latest Ruby version:
rbenv install 3.2.0
Set it as the global default version:
rbenv global 3.2.0
Step 3: Verify the Installation
Confirm the installed version:
ruby --version
Method 4: Compiling Ruby from Source
If you prefer complete control over the installation, compiling Ruby from source is an excellent option.
Step 1: Install Dependencies
Install the necessary libraries and tools:
sudo dnf install -y gcc make openssl-devel readline-devel zlib-devel
Step 2: Download Ruby Source Code
Visit the Ruby Downloads Page and download the latest stable version:
curl -O https://cache.ruby-lang.org/pub/ruby/3.2/ruby-3.2.0.tar.gz
Extract the tarball:
tar -xvzf ruby-3.2.0.tar.gz
cd ruby-3.2.0
Step 3: Compile and Install Ruby
Configure the build:
./configure
Compile Ruby:
make
Install Ruby:
sudo make install
Step 4: Verify the Installation
Check the installed version:
ruby --version
Installing RubyGems and Bundler
Once Ruby is installed, you’ll want to install RubyGems and Bundler for managing Ruby libraries and dependencies.
Install Bundler
Bundler is a tool for managing gem dependencies:
gem install bundler
Verify the installation:
bundler --version
Testing Your Ruby Installation
Create a simple Ruby script to ensure your installation is working:
Create a file called
test.rb
:nano test.rb
Add the following content:
puts "Hello, Ruby on AlmaLinux!"
Run the script:
ruby test.rb
You should see:
Hello, Ruby on AlmaLinux!
Conclusion
Installing the latest Ruby version on AlmaLinux can be achieved through multiple methods, each tailored to different use cases. The DNF repository offers simplicity but may not always have the latest version. Tools like RVM and rbenv provide flexibility, while compiling Ruby from source offers complete control.
With Ruby installed, you’re ready to explore its vast ecosystem of gems, frameworks, and tools. Whether you’re building web applications, automating tasks, or experimenting with programming, Ruby on AlmaLinux provides a robust foundation for your development needs.
2 - How to Install Ruby 3.0 on AlmaLinux
Ruby 3.0, released as a major update to the Ruby programming language, brings significant improvements in performance, features, and usability. It is particularly favored for its support of web development frameworks like Ruby on Rails and its robust library ecosystem. AlmaLinux, being a stable, enterprise-grade Linux distribution, is an excellent choice for running Ruby applications.
In this guide, we’ll cover step-by-step instructions on how to install Ruby 3.0 on AlmaLinux. By the end of this article, you’ll have a fully functional Ruby 3.0 setup, ready for development.
Why Ruby 3.0?
Ruby 3.0 introduces several noteworthy enhancements:
- Performance Boost: Ruby 3.0 is up to 3 times faster than Ruby 2.x due to the introduction of the MJIT (Method-based Just-in-Time) compiler.
- Ractor: A new actor-based parallel execution feature for writing thread-safe concurrent programs.
- Static Analysis: Improved static analysis features for identifying potential errors during development.
- Improved Syntax: Cleaner and more concise syntax for developers.
By installing Ruby 3.0, you ensure that your applications benefit from these modern features and performance improvements.
Prerequisites
Before installing Ruby 3.0, ensure the following:
Updated AlmaLinux System:
Update your system packages to avoid conflicts.sudo dnf update -y
Development Tools Installed:
Ruby requires essential development tools for compilation. Install them using:sudo dnf groupinstall "Development Tools" -y
Dependencies for Ruby:
Ensure the required libraries are installed:sudo dnf install -y gcc make openssl-devel readline-devel zlib-devel libffi-devel
Methods to Install Ruby 3.0 on AlmaLinux
There are multiple ways to install Ruby 3.0 on AlmaLinux. Choose the one that best suits your needs.
Method 1: Using RVM (Ruby Version Manager)
RVM is a popular tool for managing Ruby versions and environments. It allows you to install Ruby 3.0 effortlessly.
Step 1: Install RVM
Install required dependencies for RVM:
sudo dnf install -y curl gnupg tar
Import the RVM GPG key:
curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
Install RVM:
curl -sSL https://get.rvm.io | bash -s stable
Load RVM into your current shell session:
source ~/.rvm/scripts/rvm
Step 2: Install Ruby 3.0 with RVM
To install Ruby 3.0:
rvm install 3.0
Set Ruby 3.0 as the default version:
rvm use 3.0 --default
Step 3: Verify the Installation
Check the installed Ruby version:
ruby --version
It should output a version starting with 3.0
.
Method 2: Using rbenv
rbenv is another tool for managing Ruby installations. It is lightweight and designed to allow multiple Ruby versions to coexist.
Step 1: Install rbenv and Dependencies
Clone rbenv:
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
Add rbenv to your shell:
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc echo 'eval "$(rbenv init -)"' >> ~/.bashrc source ~/.bashrc
Install
ruby-build
:git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
Step 2: Install Ruby 3.0 with rbenv
Install Ruby 3.0:
rbenv install 3.0.0
Set Ruby 3.0 as the global version:
rbenv global 3.0.0
Step 3: Verify the Installation
Check the Ruby version:
ruby --version
Method 3: Installing Ruby 3.0 from Source
For complete control over the installation, compiling Ruby from source is a reliable option.
Step 1: Download Ruby Source Code
Visit the official Ruby Downloads Page to find the latest Ruby 3.0 version. Download it using:
curl -O https://cache.ruby-lang.org/pub/ruby/3.0/ruby-3.0.0.tar.gz
Extract the tarball:
tar -xvzf ruby-3.0.0.tar.gz
cd ruby-3.0.0
Step 2: Compile and Install Ruby
Configure the build:
./configure
Compile Ruby:
make
Install Ruby:
sudo make install
Step 3: Verify the Installation
Check the Ruby version:
ruby --version
Post-Installation Steps
Install Bundler
Bundler is a Ruby tool for managing application dependencies. Install it using:
gem install bundler
Verify the installation:
bundler --version
Test the Ruby Installation
Create a simple Ruby script to test your setup:
Create a file named
test.rb
:nano test.rb
Add the following code:
puts "Ruby 3.0 is successfully installed on AlmaLinux!"
Run the script:
ruby test.rb
You should see:
Ruby 3.0 is successfully installed on AlmaLinux!
Troubleshooting Common Issues
Ruby Command Not Found
Ensure Ruby’s binary directory is in your PATH. For RVM or rbenv, reinitialize your shell:
source ~/.bashrc
Library Errors
If you encounter missing library errors, recheck that all dependencies are installed:
sudo dnf install -y gcc make openssl-devel readline-devel zlib-devel libffi-devel
Permission Denied Errors
Run the command with sudo
or ensure your user has the necessary privileges.
Conclusion
Installing Ruby 3.0 on AlmaLinux provides access to the latest performance enhancements, features, and tools that Ruby offers. Whether you choose to install Ruby using RVM, rbenv, or by compiling from source, each method ensures a robust development environment tailored to your needs.
With Ruby 3.0 installed, you’re ready to build modern, high-performance applications. If you encounter issues, revisit the steps or consult the extensive Ruby documentation and community resources.
3 - How to Install Ruby 3.1 on AlmaLinux
Ruby 3.1 is a robust and efficient programming language release that builds on the enhancements introduced in Ruby 3.0. With improved performance, new features, and extended capabilities, it’s an excellent choice for developers creating web applications, scripts, or other software. AlmaLinux, a stable and enterprise-grade Linux distribution, provides an ideal environment for hosting Ruby applications.
In this guide, you’ll learn step-by-step how to install Ruby 3.1 on AlmaLinux, covering multiple installation methods to suit your preferences and requirements.
Why Install Ruby 3.1?
Ruby 3.1 includes significant improvements and updates:
- Performance Improvements: Ruby 3.1 continues the 3x speedup goal (“Ruby 3x3”) with faster execution and reduced memory usage.
- Enhanced Ractor API: Further refinements to Ractor, allowing safer and easier parallel execution.
- Improved Error Handling: Enhanced error messages and diagnostics for debugging.
- New Features: Additions like keyword argument consistency and extended gem support.
Upgrading to Ruby 3.1 ensures compatibility with the latest libraries and provides a solid foundation for your applications.
Prerequisites
Before starting, ensure the following:
Update AlmaLinux System:
Update all system packages to avoid compatibility issues.sudo dnf update -y
Install Development Tools:
Ruby requires certain tools and libraries for compilation. Install them using:sudo dnf groupinstall "Development Tools" -y sudo dnf install -y gcc make openssl-devel readline-devel zlib-devel libffi-devel
Administrative Privileges:
Ensure you have sudo or root access to execute system-level changes.
Methods to Install Ruby 3.1 on AlmaLinux
Method 1: Using RVM (Ruby Version Manager)
RVM is a popular tool for managing Ruby versions and environments. It allows you to install Ruby 3.1 easily and switch between multiple Ruby versions.
Step 1: Install RVM
Install prerequisites:
sudo dnf install -y curl gnupg tar
Import the RVM GPG key and install RVM:
curl -sSL https://rvm.io/mpapis.asc | gpg2 --import - curl -sSL https://get.rvm.io | bash -s stable
Load RVM into the current session:
source ~/.rvm/scripts/rvm
Step 2: Install Ruby 3.1 with RVM
To install Ruby 3.1:
rvm install 3.1
Set Ruby 3.1 as the default version:
rvm use 3.1 --default
Step 3: Verify Installation
Check the installed Ruby version:
ruby --version
You should see output indicating version 3.1.x
.
Method 2: Using rbenv
rbenv is another tool for managing multiple Ruby versions. It is lightweight and provides a straightforward way to install and switch Ruby versions.
Step 1: Install rbenv and Dependencies
Clone rbenv from GitHub:
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
Add rbenv to your PATH:
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc echo 'eval "$(rbenv init -)"' >> ~/.bashrc source ~/.bashrc
Install
ruby-build
:git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
Step 2: Install Ruby 3.1 with rbenv
Install Ruby 3.1:
rbenv install 3.1.0
Set Ruby 3.1 as the global version:
rbenv global 3.1.0
Step 3: Verify Installation
Check the installed Ruby version:
ruby --version
Method 3: Installing Ruby 3.1 from Source
Compiling Ruby from source gives you full control over the installation process.
Step 1: Download Ruby Source Code
Download the Ruby 3.1 source code from the official Ruby Downloads Page:
curl -O https://cache.ruby-lang.org/pub/ruby/3.1/ruby-3.1.0.tar.gz
Extract the downloaded archive:
tar -xvzf ruby-3.1.0.tar.gz
cd ruby-3.1.0
Step 2: Compile and Install Ruby
Configure the build:
./configure
Compile Ruby:
make
Install Ruby:
sudo make install
Step 3: Verify Installation
Check the Ruby version:
ruby --version
Post-Installation Setup
Install Bundler
Bundler is a Ruby gem used for managing application dependencies. Install it using:
gem install bundler
Verify Bundler installation:
bundler --version
Test Ruby Installation
To confirm Ruby is working correctly, create a simple script:
Create a file named
test.rb
:nano test.rb
Add the following code:
puts "Ruby 3.1 is successfully installed on AlmaLinux!"
Run the script:
ruby test.rb
You should see the output:
Ruby 3.1 is successfully installed on AlmaLinux!
Troubleshooting Common Issues
Command Not Found
Ensure Ruby binaries are in your system PATH. For RVM or rbenv, reinitialize the shell:
source ~/.bashrc
Missing Libraries
If Ruby installation fails, ensure all dependencies are installed:
sudo dnf install -y gcc make openssl-devel readline-devel zlib-devel libffi-devel
Permission Errors
Use sudo
for system-wide installations or ensure your user has the necessary permissions.
Conclusion
Installing Ruby 3.1 on AlmaLinux is straightforward and provides access to the latest features and improvements in the Ruby programming language. Whether you use RVM, rbenv, or compile from source, you can have a reliable Ruby environment tailored to your needs.
With Ruby 3.1 installed, you can start developing modern applications, exploring Ruby gems, and leveraging frameworks like Ruby on Rails. Happy coding!
4 - How to Install Ruby on Rails 7 on AlmaLinux
Ruby on Rails (commonly referred to as Rails) is a powerful, full-stack web application framework built on Ruby. It has gained immense popularity for its convention-over-configuration approach, enabling developers to build robust and scalable web applications quickly. Rails 7, the latest version of the framework, brings exciting new features like Hotwire integration, improved Active Record capabilities, and advanced JavaScript compatibility without requiring Node.js or Webpack by default.
AlmaLinux, as a stable and reliable RHEL-based distribution, provides an excellent environment for hosting Ruby on Rails applications. This blog will guide you through the installation of Ruby on Rails 7 on AlmaLinux, ensuring that you can start developing your applications efficiently.
Why Choose Ruby on Rails 7?
Ruby on Rails 7 introduces several cutting-edge features:
- Hotwire Integration: Real-time, server-driven updates without relying on heavy JavaScript libraries.
- No Node.js Dependency (Optional): Rails 7 embraces ESBuild and import maps, reducing reliance on Node.js for asset management.
- Turbo and Stimulus: Tools for building modern, dynamic frontends with minimal JavaScript.
- Enhanced Active Record: Improvements to database querying and handling.
- Encryption Framework: Built-in support for encryption, ensuring better security out of the box.
By installing Rails 7, you gain access to these features, empowering your web development projects.
Prerequisites
Before installing Ruby on Rails 7, make sure your AlmaLinux system is prepared:
Update Your System:
sudo dnf update -y
Install Development Tools and Libraries:
Rails relies on various libraries and tools. Install them using:sudo dnf groupinstall "Development Tools" -y sudo dnf install -y gcc make openssl-devel readline-devel zlib-devel libffi-devel git curl sqlite sqlite-devel nodejs
Install a Database (Optional):
Rails supports several databases like PostgreSQL and MySQL. If you plan to use PostgreSQL, install it using:sudo dnf install -y postgresql postgresql-server postgresql-devel
Administrative Privileges:
Ensure you have sudo or root access for system-level installations.
Step 1: Install Ruby
Ruby on Rails requires Ruby to function. While AlmaLinux’s default repositories might not have the latest Ruby version, you can install it using one of the following methods:
Option 1: Install Ruby Using RVM
Install RVM:
sudo dnf install -y curl gnupg tar curl -sSL https://rvm.io/mpapis.asc | gpg2 --import - curl -sSL https://get.rvm.io | bash -s stable source ~/.rvm/scripts/rvm
Install Ruby:
rvm install 3.1.0 rvm use 3.1.0 --default
Verify Ruby Installation:
ruby --version
Option 2: Install Ruby Using rbenv
Clone rbenv and ruby-build:
git clone https://github.com/rbenv/rbenv.git ~/.rbenv git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
Add rbenv to your PATH:
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc echo 'eval "$(rbenv init -)"' >> ~/.bashrc source ~/.bashrc
Install Ruby:
rbenv install 3.1.0 rbenv global 3.1.0
Verify Ruby Installation:
ruby --version
Step 2: Install RubyGems and Bundler
RubyGems is the package manager for Ruby, and Bundler is a tool for managing application dependencies. Both are essential for Rails development.
Install Bundler:
gem install bundler
Verify Bundler Installation:
bundler --version
Step 3: Install Rails 7
With Ruby and Bundler installed, you can now install Rails 7:
Install Rails:
gem install rails -v 7.0.0
Verify Rails Installation:
rails --version
It should output
Rails 7.0.0
or a newer version, depending on updates.
Step 4: Set Up a New Rails Application
Now that Rails is installed, create a new application to test the setup:
Step 4.1: Install Node.js or ESBuild (Optional)
Rails 7 supports JavaScript-free applications using import maps. However, if you prefer a traditional setup, ensure Node.js is installed:
sudo dnf install -y nodejs
Step 4.2: Create a New Rails Application
Create a new Rails application named myapp
:
rails new myapp
The rails new
command will create a folder named myapp
and set up all necessary files and directories.
Step 4.3: Navigate to the Application Directory
cd myapp
Step 4.4: Install Gems and Dependencies
Run Bundler to install the required gems:
bundle install
Step 4.5: Start the Rails Server
Start the Rails development server:
rails server
The server will start on http://localhost:3000
.
Step 4.6: Access Your Application
Open a web browser and navigate to http://<your-server-ip>:3000
to see the Rails welcome page.
Step 5: Database Configuration (Optional)
Rails supports various databases, and you may want to configure your application to use PostgreSQL or MySQL instead of the default SQLite.
Example: PostgreSQL Setup
Install PostgreSQL:
sudo dnf install -y postgresql postgresql-server postgresql-devel
Initialize and Start PostgreSQL:
sudo postgresql-setup --initdb sudo systemctl enable --now postgresql
Update the
database.yml
file in your Rails project to use PostgreSQL:development: adapter: postgresql encoding: unicode database: myapp_development pool: 5 username: your_postgres_user password: your_password
Create the database:
rails db:create
Step 6: Deploy Your Rails Application
Once your application is ready for deployment, consider using production-grade tools like Puma, Nginx, and Passenger for hosting. For a full-stack deployment, tools like Capistrano or Docker can streamline the process.
Troubleshooting Common Issues
1. Missing Gems or Bundler Errors
Run the following to ensure all dependencies are installed:
bundle install
2. Port Access Issues
If you can’t access the Rails server, ensure that the firewall allows traffic on port 3000:
sudo firewall-cmd --add-port=3000/tcp --permanent
sudo firewall-cmd --reload
3. Permission Errors
Ensure your user has sufficient privileges to access necessary files and directories. Use sudo
if required.
Conclusion
Installing Ruby on Rails 7 on AlmaLinux equips you with the latest tools and features for web development. With its streamlined asset management, improved Active Record, and enhanced JavaScript integration, Rails 7 empowers developers to build modern, high-performance applications efficiently.
This guide covered everything from installing Ruby to setting up Rails and configuring a database. Now, you’re ready to start your journey into Rails 7 development on AlmaLinux!
5 - How to Install .NET Core 3.1 on AlmaLinux
How to Install .NET Core 3.1 on AlmaLinux
.NET Core 3.1, now part of the broader .NET platform, is a popular open-source and cross-platform framework for building modern applications. It supports web, desktop, mobile, cloud, and microservices development with high performance and flexibility. AlmaLinux, an enterprise-grade Linux distribution, is an excellent choice for hosting and running .NET Core applications due to its stability and RHEL compatibility.
This guide will walk you through the process of installing .NET Core 3.1 on AlmaLinux, covering prerequisites, step-by-step installation, and testing.
Why Choose .NET Core 3.1?
Although newer versions of .NET are available, .NET Core 3.1 remains a Long-Term Support (LTS) release. This means:
- Stability: Backed by long-term updates and security fixes until December 2022 (or beyond for enterprise).
- Compatibility: Supports building and running applications across multiple platforms.
- Proven Performance: Optimized for high performance in web and API applications.
- Extensive Libraries: Includes features like gRPC support, new JSON APIs, and enhanced desktop support.
If your project requires a stable environment, .NET Core 3.1 is a reliable choice.
Prerequisites
Before installing .NET Core 3.1 on AlmaLinux, ensure the following prerequisites are met:
Updated System:
Update all existing packages on your AlmaLinux system:sudo dnf update -y
Development Tools:
Install essential build tools to support .NET Core:sudo dnf groupinstall "Development Tools" -y
Administrative Privileges:
You need root or sudo access to install .NET Core packages and make system changes.Check AlmaLinux Version:
Ensure you are using AlmaLinux 8 or higher, as it provides the necessary dependencies.
Step 1: Enable Microsoft’s Package Repository
.NET Core packages are provided directly by Microsoft. To install .NET Core 3.1, you first need to enable the Microsoft package repository.
Import the Microsoft GPG key:
sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
Add the Microsoft repository:
sudo dnf install -y https://packages.microsoft.com/config/rhel/8/packages-microsoft-prod.rpm
Update the repository cache:
sudo dnf update -y
Step 2: Install .NET Core 3.1 Runtime or SDK
You can choose between the .NET Core Runtime or the SDK depending on your requirements:
- Runtime: For running .NET Core applications.
- SDK: For developing and running .NET Core applications.
Install .NET Core 3.1 Runtime
If you only need to run .NET Core applications:
sudo dnf install -y dotnet-runtime-3.1
Install .NET Core 3.1 SDK
If you are a developer and need to build applications:
sudo dnf install -y dotnet-sdk-3.1
Step 3: Verify the Installation
Check if .NET Core 3.1 has been installed successfully:
Verify the installed runtime:
dotnet --list-runtimes
You should see an entry similar to:
Microsoft.NETCore.App 3.1.x [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Verify the installed SDK:
dotnet --list-sdks
The output should include:
3.1.x [/usr/share/dotnet/sdk]
Check the .NET version:
dotnet --version
This should display
3.1.x
.
Step 4: Create and Run a Sample .NET Core Application
To ensure everything is working correctly, create a simple .NET Core application.
Create a New Console Application:
dotnet new console -o MyApp
This command creates a new directory
MyApp
and initializes a basic .NET Core console application.Navigate to the Application Directory:
cd MyApp
Run the Application:
dotnet run
You should see the output:
Hello, World!
Step 5: Configure .NET Core for Web Applications (Optional)
If you are building web applications, you may want to set up ASP.NET Core.
Install ASP.NET Core Runtime
To support web applications, install the ASP.NET Core runtime:
sudo dnf install -y aspnetcore-runtime-3.1
Test an ASP.NET Core Application
Create a new web application:
dotnet new webapp -o MyWebApp
Navigate to the application directory:
cd MyWebApp
Run the web application:
dotnet run
Access the application in your browser at
http://localhost:5000
.
Step 6: Manage .NET Core Applications
Start and Stop Applications
You can start a .NET Core application using:
dotnet MyApp.dll
Replace MyApp.dll
with your application file name.
Publish Applications
To deploy your application, publish it to a folder:
dotnet publish -c Release -o /path/to/publish
The -c Release
flag creates a production-ready build.
Step 7: Troubleshooting Common Issues
1. Dependency Issues
Ensure all dependencies are installed:
sudo dnf install -y gcc libunwind libicu
2. Application Fails to Start
Check the application logs for errors:
journalctl -u myapp.service
3. Firewall Blocks ASP.NET Applications
If your ASP.NET application cannot be accessed, allow traffic on the required ports:
sudo firewall-cmd --add-port=5000/tcp --permanent
sudo firewall-cmd --reload
Step 8: Uninstall .NET Core 3.1 (If Needed)
If you need to remove .NET Core 3.1 from your system:
Uninstall the SDK and runtime:
sudo dnf remove dotnet-sdk-3.1 dotnet-runtime-3.1
Remove the Microsoft repository:
sudo rm -f /etc/yum.repos.d/microsoft-prod.repo
Conclusion
Installing .NET Core 3.1 on AlmaLinux is a straightforward process, enabling you to leverage the framework’s power and versatility. Whether you’re building APIs, web apps, or microservices, this guide ensures that you have a stable development and runtime environment.
With .NET Core 3.1 installed, you can now start creating high-performance applications that run seamlessly across multiple platforms. If you’re ready for a more cutting-edge experience, consider exploring .NET 6 or later versions once your project’s requirements align.
6 - How to Install .NET 6.0 on AlmaLinux
.NET 6.0 is a cutting-edge, open-source framework that supports a wide range of applications, including web, desktop, cloud, mobile, and IoT solutions. It is a Long-Term Support (LTS) release, providing stability and support through November 2024. AlmaLinux, as a reliable and enterprise-grade Linux distribution, is an excellent platform for hosting .NET applications due to its compatibility with Red Hat Enterprise Linux (RHEL).
This guide provides a detailed, step-by-step tutorial for installing .NET 6.0 on AlmaLinux, along with configuration and testing steps to ensure a seamless development experience.
Why Choose .NET 6.0?
.NET 6.0 introduces several key features and improvements:
- Unified Development Platform: One framework for building apps across all platforms (web, desktop, mobile, and cloud).
- Performance Enhancements: Improved execution speed and reduced memory usage, especially for web APIs and microservices.
- C# 10 and F# 6 Support: Access to the latest language features.
- Simplified Development: Minimal APIs for quick web API development.
- Long-Term Support: Backed by updates and fixes for the long term.
If you’re looking to build modern, high-performance applications, .NET 6.0 is the perfect choice.
Prerequisites
Before you begin, ensure the following prerequisites are met:
AlmaLinux System Requirements:
- AlmaLinux 8 or newer.
- Sudo or root access to perform administrative tasks.
Update Your System:
sudo dnf update -y
Install Development Tools:
Install essential build tools and libraries:sudo dnf groupinstall "Development Tools" -y sudo dnf install -y gcc make openssl-devel readline-devel zlib-devel libffi-devel git curl
Firewall Configuration:
Ensure ports required by your applications (e.g., 5000, 5001 for ASP.NET) are open:sudo firewall-cmd --add-port=5000/tcp --permanent sudo firewall-cmd --add-port=5001/tcp --permanent sudo firewall-cmd --reload
Step 1: Enable Microsoft’s Package Repository
.NET packages are provided by Microsoft’s official repository. You must add it to your AlmaLinux system.
Import Microsoft’s GPG Key:
sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
Add the Repository:
sudo dnf install -y https://packages.microsoft.com/config/rhel/8/packages-microsoft-prod.rpm
Update the Repository Cache:
sudo dnf update -y
Step 2: Install .NET 6.0 Runtime or SDK
You can install the Runtime or the SDK, depending on your needs:
- Runtime: For running .NET applications.
- SDK: For developing and running .NET applications.
Install .NET 6.0 Runtime
If you only need to run applications, install the runtime:
sudo dnf install -y dotnet-runtime-6.0
Install .NET 6.0 SDK
For development purposes, install the SDK:
sudo dnf install -y dotnet-sdk-6.0
Step 3: Verify the Installation
To confirm that .NET 6.0 has been installed successfully:
Check the Installed Runtime Versions:
dotnet --list-runtimes
Example output:
Microsoft.NETCore.App 6.0.x [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Check the Installed SDK Versions:
dotnet --list-sdks
Example output:
6.0.x [/usr/share/dotnet/sdk]
Verify the .NET Version:
dotnet --version
The output should display the installed version, e.g.,
6.0.x
.
Step 4: Create and Run a Sample .NET 6.0 Application
To test your installation, create a simple application.
Create a New Console Application:
dotnet new console -o MyApp
This command generates a basic .NET console application in a folder named
MyApp
.Navigate to the Application Directory:
cd MyApp
Run the Application:
dotnet run
You should see:
Hello, World!
Step 5: Set Up an ASP.NET Core Application (Optional)
.NET 6.0 includes ASP.NET Core for building web applications and APIs.
Create a New Web Application:
dotnet new webapp -o MyWebApp
Navigate to the Application Directory:
cd MyWebApp
Run the Application:
dotnet run
Access the Application:
Open your browser and navigate tohttp://localhost:5000
(or the displayed URL in the terminal).
Step 6: Deploying .NET 6.0 Applications
Publishing an Application
To deploy a .NET 6.0 application, publish it as a self-contained or framework-dependent application:
Publish the Application:
dotnet publish -c Release -o /path/to/publish
Run the Published Application:
dotnet /path/to/publish/MyApp.dll
Running as a Service
You can configure your application to run as a systemd service for production environments:
Create a service file:
sudo nano /etc/systemd/system/myapp.service
Add the following content:
[Unit] Description=My .NET 6.0 Application After=network.target [Service] WorkingDirectory=/path/to/publish ExecStart=/usr/bin/dotnet /path/to/publish/MyApp.dll Restart=always RestartSec=10 KillSignal=SIGINT SyslogIdentifier=myapp User=www-data Environment=ASPNETCORE_ENVIRONMENT=Production [Install] WantedBy=multi-user.target
Enable and start the service:
sudo systemctl enable myapp.service sudo systemctl start myapp.service
Check the service status:
sudo systemctl status myapp.service
Step 7: Troubleshooting Common Issues
1. Dependency Errors
Ensure all required dependencies are installed:
sudo dnf install -y libunwind libicu
2. Application Fails to Start
Check the application logs:
journalctl -u myapp.service
3. Firewall Blocking Ports
Ensure the firewall is configured to allow the necessary ports:
sudo firewall-cmd --add-port=5000/tcp --permanent
sudo firewall-cmd --reload
Conclusion
Installing .NET 6.0 on AlmaLinux is a straightforward process, enabling you to build and run high-performance, cross-platform applications. With the powerful features of .NET 6.0 and the stability of AlmaLinux, you have a reliable foundation for developing and deploying modern solutions.
From creating basic console applications to hosting scalable web APIs, .NET 6.0 offers the tools you need for any project. Follow this guide to set up your environment and start leveraging the capabilities of this versatile framework.
7 - How to Install PHP 8.0 on AlmaLinux
PHP 8.0 is a significant release in the PHP ecosystem, offering new features, performance improvements, and security updates. It introduces features like the JIT (Just-In-Time) compiler, union types, attributes, and improved error handling. If you’re using AlmaLinux, a stable and enterprise-grade Linux distribution, installing PHP 8.0 will provide a robust foundation for developing or hosting modern PHP applications.
In this guide, we will walk you through the process of installing PHP 8.0 on AlmaLinux. Whether you’re setting up a new server or upgrading an existing PHP installation, this step-by-step guide will cover everything you need to know.
Why Choose PHP 8.0?
PHP 8.0 offers several enhancements that make it a compelling choice for developers:
- JIT Compiler: Boosts performance for specific workloads by compiling code at runtime.
- Union Types: Allows a single parameter or return type to accept multiple types.
- Attributes: Provides metadata for functions, classes, and methods, replacing doc comments.
- Named Arguments: Improves readability and flexibility by allowing parameters to be passed by name.
- Improved Error Handling: Includes clearer exception messages and better debugging support.
With these improvements, PHP 8.0 enhances both performance and developer productivity.
Prerequisites
Before installing PHP 8.0, ensure the following prerequisites are met:
Update the AlmaLinux System:
Ensure your system is up-to-date with the latest packages:sudo dnf update -y
Install Required Tools:
PHP depends on various tools and libraries. Install them using:sudo dnf install -y gcc libxml2 libxml2-devel curl curl-devel oniguruma oniguruma-devel
Administrative Access:
You need sudo or root privileges to install and configure PHP.
Step 1: Enable EPEL and Remi Repositories
PHP 8.0 is not available in the default AlmaLinux repositories, so you’ll need to enable the EPEL (Extra Packages for Enterprise Linux) and Remi repositories, which provide updated PHP packages.
1.1 Enable EPEL Repository
Install the EPEL repository:
sudo dnf install -y epel-release
1.2 Install Remi Repository
Install the Remi repository, which provides PHP 8.0 packages:
sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm
1.3 Enable the PHP 8.0 Module
Reset the default PHP module to ensure compatibility with PHP 8.0:
sudo dnf module reset php -y
sudo dnf module enable php:remi-8.0 -y
Step 2: Install PHP 8.0
Now that the necessary repositories are set up, you can install PHP 8.0.
2.1 Install the PHP 8.0 Core Package
Install PHP and its core components:
sudo dnf install -y php
2.2 Install Additional PHP Extensions
Depending on your application requirements, you may need additional PHP extensions. Here are some commonly used extensions:
sudo dnf install -y php-mysqlnd php-pdo php-mbstring php-xml php-curl php-json php-intl php-soap php-zip php-bcmath php-gd
2.3 Verify the PHP Installation
Check the installed PHP version:
php -v
You should see output similar to:
PHP 8.0.x (cli) (built: ...)
Step 3: Configure PHP 8.0
Once installed, you’ll need to configure PHP 8.0 to suit your application and server requirements.
3.1 Locate the PHP Configuration File
The main PHP configuration file is php.ini
. Use the following command to locate it:
php --ini
3.2 Modify the Configuration
Edit the php.ini
file to adjust settings like maximum file upload size, memory limits, and execution time.
sudo nano /etc/php.ini
Common settings to modify:
Maximum Execution Time:
max_execution_time = 300
Memory Limit:
memory_limit = 256M
File Upload Size:
upload_max_filesize = 50M post_max_size = 50M
3.3 Restart the Web Server
Restart your web server to apply the changes:
For Apache:
sudo systemctl restart httpd
For Nginx with PHP-FPM:
sudo systemctl restart php-fpm sudo systemctl restart nginx
Step 4: Test PHP 8.0 Installation
4.1 Create a PHP Info File
Create a simple PHP script to test the installation:
sudo nano /var/www/html/info.php
Add the following content:
<?php
phpinfo();
?>
4.2 Access the Test File
Open your web browser and navigate to:
http://<your-server-ip>/info.php
You should see a detailed PHP information page confirming that PHP 8.0 is installed and configured.
4.3 Remove the Test File
For security reasons, delete the test file after verification:
sudo rm /var/www/html/info.php
Step 5: Troubleshooting Common Issues
5.1 PHP Command Not Found
Ensure the PHP binary is in your PATH. If not, add it manually:
export PATH=$PATH:/usr/bin/php
5.2 PHP Extensions Missing
Install the required PHP extensions from the Remi repository:
sudo dnf install -y php-<extension-name>
5.3 Web Server Issues
If your web server cannot process PHP files:
Verify that PHP-FPM is running:
sudo systemctl status php-fpm
Restart your web server:
sudo systemctl restart httpd
Step 6: Installing Composer (Optional)
Composer is a dependency manager for PHP that simplifies package management.
6.1 Download Composer
Download and install Composer:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php --install-dir=/usr/local/bin --filename=composer
php -r "unlink('composer-setup.php');"
6.2 Verify Installation
Check the Composer version:
composer --version
Step 7: Upgrade from Previous PHP Versions (Optional)
If you’re upgrading from PHP 7.x, ensure compatibility with your applications by testing them in a staging environment. You may need to adjust deprecated functions or update frameworks like Laravel or WordPress to their latest versions.
Conclusion
Installing PHP 8.0 on AlmaLinux enables you to take advantage of its improved performance, modern syntax, and robust features. Whether you’re hosting a WordPress site, developing custom web applications, or running APIs, PHP 8.0 offers the tools needed to build fast and scalable solutions.
By following this guide, you’ve successfully installed and configured PHP 8.0, added essential extensions, and verified the installation. With your setup complete, you’re ready to start developing or hosting modern PHP applications on AlmaLinux!
8 - How to Install PHP 8.1 on AlmaLinux
PHP 8.1 is one of the most significant updates in the PHP ecosystem, offering developers new features, enhanced performance, and improved security. With features such as enums, read-only properties, fibers, and intersection types, PHP 8.1 takes modern application development to the next level. AlmaLinux, an enterprise-grade Linux distribution, provides a stable platform for hosting PHP applications, making it an ideal choice for setting up PHP 8.1.
This comprehensive guide will walk you through the steps to install PHP 8.1 on AlmaLinux, configure essential extensions, and ensure your environment is ready for modern PHP development.
Why Choose PHP 8.1?
PHP 8.1 introduces several noteworthy features and improvements:
- Enums: A powerful feature for managing constants more efficiently.
- Fibers: Simplifies asynchronous programming and enhances concurrency handling.
- Read-Only Properties: Ensures immutability for class properties.
- Intersection Types: Allows greater flexibility in type declarations.
- Performance Boosts: JIT improvements and better memory handling.
These enhancements make PHP 8.1 an excellent choice for developers building scalable, high-performance applications.
Prerequisites
Before installing PHP 8.1, ensure the following prerequisites are met:
Update Your AlmaLinux System:
sudo dnf update -y
Install Required Tools and Libraries:
Install essential dependencies required by PHP:sudo dnf install -y gcc libxml2 libxml2-devel curl curl-devel oniguruma oniguruma-devel
Administrative Access:
Ensure you have root or sudo privileges to install and configure PHP.
Step 1: Enable EPEL and Remi Repositories
PHP 8.1 is not included in AlmaLinux’s default repositories. You need to enable the EPEL (Extra Packages for Enterprise Linux) and Remi repositories to access updated PHP packages.
1.1 Install the EPEL Repository
Install the EPEL repository:
sudo dnf install -y epel-release
1.2 Install the Remi Repository
Install the Remi repository, which provides PHP 8.1 packages:
sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm
1.3 Enable the PHP 8.1 Module
Reset any existing PHP modules and enable the PHP 8.1 module:
sudo dnf module reset php -y
sudo dnf module enable php:remi-8.1 -y
Step 2: Install PHP 8.1
Now that the repositories are set up, you can proceed with installing PHP 8.1.
2.1 Install PHP 8.1 Core Package
Install the PHP 8.1 core package:
sudo dnf install -y php
2.2 Install Common PHP Extensions
Depending on your application, you may need additional PHP extensions. Here are some commonly used ones:
sudo dnf install -y php-mysqlnd php-pdo php-mbstring php-xml php-curl php-json php-intl php-soap php-zip php-bcmath php-gd php-opcache
2.3 Verify PHP Installation
Check the installed PHP version:
php -v
You should see output similar to:
PHP 8.1.x (cli) (built: ...)
Step 3: Configure PHP 8.1
Once PHP is installed, you may need to configure it according to your application’s requirements.
3.1 Locate the PHP Configuration File
To locate the main php.ini
file, use:
php --ini
3.2 Edit the PHP Configuration File
Open the php.ini
file for editing:
sudo nano /etc/php.ini
Modify these common settings:
Maximum Execution Time:
max_execution_time = 300
Memory Limit:
memory_limit = 512M
Upload File Size:
upload_max_filesize = 50M post_max_size = 50M
Save the changes and exit the editor.
3.3 Restart the Web Server
After making changes to PHP settings, restart your web server to apply them:
For Apache:
sudo systemctl restart httpd
For Nginx with PHP-FPM:
sudo systemctl restart php-fpm sudo systemctl restart nginx
Step 4: Test PHP 8.1 Installation
4.1 Create a PHP Info File
Create a simple PHP script to test the installation:
sudo nano /var/www/html/info.php
Add the following content:
<?php
phpinfo();
?>
4.2 Access the Test Page
Open a browser and navigate to:
http://<your-server-ip>/info.php
You should see a detailed PHP information page confirming the PHP 8.1 installation.
4.3 Remove the Test File
For security reasons, delete the test file after verification:
sudo rm /var/www/html/info.php
Step 5: Install Composer (Optional)
Composer is a dependency manager for PHP and is essential for modern PHP development.
5.1 Download and Install Composer
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php --install-dir=/usr/local/bin --filename=composer
php -r "unlink('composer-setup.php');"
5.2 Verify Installation
Check the Composer version:
composer --version
Step 6: Upgrade from Previous PHP Versions (Optional)
If you’re upgrading from PHP 7.x or 8.0 to PHP 8.1, follow these steps:
Backup Configuration and Applications:
Create backups of your existing configurations and applications.Switch to PHP 8.1 Module:
sudo dnf module reset php -y sudo dnf module enable php:remi-8.1 -y sudo dnf install -y php
Verify Application Compatibility:
Test your application in a staging environment to ensure compatibility with PHP 8.1.
Step 7: Troubleshooting Common Issues
7.1 PHP Command Not Found
Ensure the PHP binary is in your system PATH:
export PATH=$PATH:/usr/bin/php
7.2 Missing Extensions
Install the required extensions from the Remi repository:
sudo dnf install -y php-<extension-name>
7.3 Web Server Issues
Ensure PHP-FPM is running:
sudo systemctl status php-fpm
Restart your web server:
sudo systemctl restart httpd sudo systemctl restart php-fpm
Conclusion
Installing PHP 8.1 on AlmaLinux equips your server with the latest features, performance enhancements, and security updates. This guide covered all the essential steps, from enabling the required repositories to configuring PHP settings and testing the installation.
Whether you’re developing web applications, hosting WordPress sites, or building APIs, PHP 8.1 ensures you have the tools to create high-performance and scalable solutions. Follow this guide to set up a robust environment for modern PHP development on AlmaLinux!
9 - How to Install Laravel on AlmaLinux: A Step-by-Step Guide
Laravel is one of the most popular PHP frameworks, known for its elegant syntax, scalability, and robust features for building modern web applications. AlmaLinux, a community-driven Linux distribution designed to be an alternative to CentOS, is a perfect server environment for hosting Laravel applications due to its stability and security. If you’re looking to set up Laravel on AlmaLinux, this guide will take you through the process step-by-step.
Table of Contents
- Prerequisites
- Step 1: Update Your System
- Step 2: Install Apache (or Nginx) and PHP
- Step 3: Install Composer
- Step 4: Install MySQL (or MariaDB)
- Step 5: Download and Set Up Laravel
- Step 6: Configure Apache or Nginx for Laravel
- Step 7: Verify Laravel Installation
- Conclusion
Prerequisites
Before diving into the installation process, ensure you have the following:
- A server running AlmaLinux.
- Root or sudo privileges to execute administrative commands.
- A basic understanding of the Linux command line.
- PHP version 8.0 or later (required by Laravel).
- Composer (a dependency manager for PHP).
- A database such as MySQL or MariaDB for your Laravel application.
Step 1: Update Your System
Begin by ensuring your system is up-to-date. Open the terminal and run the following commands:
sudo dnf update -y
sudo dnf upgrade -y
This ensures you have the latest security patches and software updates.
Step 2: Install Apache (or Nginx) and PHP
Laravel requires a web server and PHP to function. Apache is a common choice for hosting Laravel, but you can also use Nginx if preferred. For simplicity, we’ll focus on Apache here.
Install Apache
sudo dnf install httpd -y
Start and enable Apache to ensure it runs on boot:
sudo systemctl start httpd
sudo systemctl enable httpd
Install PHP
Laravel requires PHP 8.0 or later. Install PHP and its required extensions:
sudo dnf install php php-cli php-common php-mysqlnd php-xml php-mbstring php-json php-tokenizer php-curl php-zip -y
After installation, check the PHP version:
php -v
You should see something like:
PHP 8.0.x (cli) (built: ...)
Restart Apache to load PHP modules:
sudo systemctl restart httpd
Step 3: Install Composer
Composer is a crucial dependency manager for PHP and is required to install Laravel.
Download the Composer installer:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
Verify the installer integrity:
php -r "if (hash_file('sha384', 'composer-setup.php') === 'HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
Replace
HASH
with the latest hash from the Composer website.Install Composer globally:
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
Check Composer installation:
composer --version
Step 4: Install MySQL (or MariaDB)
Laravel requires a database for storing application data. Install MariaDB (a popular MySQL fork) as follows:
Install MariaDB:
sudo dnf install mariadb-server -y
Start and enable the service:
sudo systemctl start mariadb sudo systemctl enable mariadb
Secure the installation:
sudo mysql_secure_installation
Follow the prompts to set a root password, remove anonymous users, disallow remote root login, and remove the test database.
Log in to MariaDB to create a Laravel database:
sudo mysql -u root -p
Run the following commands:
CREATE DATABASE laravel_db; CREATE USER 'laravel_user'@'localhost' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON laravel_db.* TO 'laravel_user'@'localhost'; FLUSH PRIVILEGES; EXIT;
Step 5: Download and Set Up Laravel
Navigate to your Apache document root (or create a directory for Laravel):
cd /var/www sudo mkdir laravel-app cd laravel-app
Use Composer to create a new Laravel project:
composer create-project --prefer-dist laravel/laravel .
Set the correct permissions for Laravel:
sudo chown -R apache:apache /var/www/laravel-app sudo chmod -R 775 /var/www/laravel-app/storage /var/www/laravel-app/bootstrap/cache
Step 6: Configure Apache for Laravel
Laravel uses the /public
directory as its document root. Configure Apache to serve Laravel:
Create a new virtual host configuration file:
sudo nano /etc/httpd/conf.d/laravel-app.conf
Add the following configuration:
<VirtualHost *:80> ServerName yourdomain.com DocumentRoot /var/www/laravel-app/public <Directory /var/www/laravel-app/public> AllowOverride All Require all granted </Directory> ErrorLog /var/log/httpd/laravel-app-error.log CustomLog /var/log/httpd/laravel-app-access.log combined </VirtualHost>
Save and exit the file, then enable mod_rewrite:
sudo dnf install mod_rewrite -y sudo systemctl restart httpd
Test your configuration:
sudo apachectl configtest
Step 7: Verify Laravel Installation
Open your browser and navigate to your server’s IP address or domain. You should see Laravel’s default welcome page.
If you encounter issues, check the Apache logs:
sudo tail -f /var/log/httpd/laravel-app-error.log
Conclusion
You have successfully installed Laravel on AlmaLinux! This setup provides a robust foundation for building your Laravel applications. From here, you can start developing your project, integrating APIs, configuring additional services, or deploying your application to production.
By following the steps outlined in this guide, you’ve not only set up Laravel but also gained insight into managing a Linux-based web server. With Laravel’s rich ecosystem and AlmaLinux’s stability, your development journey is set for success. Happy coding!
10 - How to Install CakePHP on AlmaLinux: A Comprehensive Guide
CakePHP is a widely used PHP framework that simplifies the development of web applications by offering a well-organized structure, built-in tools, and conventions for coding. If you’re running AlmaLinux—a community-driven, enterprise-level Linux distribution based on RHEL (Red Hat Enterprise Linux)—you can set up CakePHP as a reliable foundation for your web projects.
This blog post will walk you through installing and configuring CakePHP on AlmaLinux step-by-step. By the end of this guide, you’ll have a functional CakePHP installation ready for development.
Table of Contents
- Introduction to CakePHP and AlmaLinux
- Prerequisites
- Step 1: Update Your System
- Step 2: Install Apache (or Nginx) and PHP
- Step 3: Install Composer
- Step 4: Install MySQL (or MariaDB)
- Step 5: Download and Set Up CakePHP
- Step 6: Configure Apache or Nginx for CakePHP
- Step 7: Test CakePHP Installation
- Conclusion
1. Introduction to CakePHP and AlmaLinux
CakePHP is an open-source framework built around the Model-View-Controller (MVC) design pattern, which provides a streamlined environment for building robust applications. With features like scaffolding, ORM (Object Relational Mapping), and validation, it’s ideal for developers seeking efficiency.
AlmaLinux is a free and open-source Linux distribution that offers the stability and performance required for hosting CakePHP applications. It is a drop-in replacement for CentOS, making it an excellent choice for enterprise environments.
2. Prerequisites
Before beginning, make sure you have the following:
- A server running AlmaLinux.
- Root or sudo privileges.
- A basic understanding of the Linux terminal.
- PHP version 8.1 or higher (required for CakePHP 4.x).
- Composer installed (dependency manager for PHP).
- A database (MySQL or MariaDB) configured for your application.
3. Step 1: Update Your System
Start by updating your system to ensure it has the latest security patches and software versions. Open the terminal and run:
sudo dnf update -y
sudo dnf upgrade -y
4. Step 2: Install Apache (or Nginx) and PHP
CakePHP requires a web server and PHP to function. This guide will use Apache as the web server.
Install Apache:
sudo dnf install httpd -y
Start and enable Apache to ensure it runs on boot:
sudo systemctl start httpd
sudo systemctl enable httpd
Install PHP and Required Extensions:
CakePHP requires PHP 8.1 or later. Install PHP and its necessary extensions as follows:
sudo dnf install php php-cli php-common php-mbstring php-intl php-xml php-opcache php-curl php-mysqlnd php-zip -y
Verify the PHP installation:
php -v
Expected output:
PHP 8.1.x (cli) (built: ...)
Restart Apache to load PHP modules:
sudo systemctl restart httpd
5. Step 3: Install Composer
Composer is an essential tool for managing PHP dependencies, including CakePHP.
Install Composer:
Download the Composer installer:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
Install Composer globally:
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
Verify the installation:
composer --version
6. Step 4: Install MySQL (or MariaDB)
CakePHP requires a database to manage application data. You can use either MySQL or MariaDB. For this guide, we’ll use MariaDB.
Install MariaDB:
sudo dnf install mariadb-server -y
Start and Enable MariaDB:
sudo systemctl start mariadb
sudo systemctl enable mariadb
Secure the Installation:
Run the security script to set up a root password and other configurations:
sudo mysql_secure_installation
Create a Database for CakePHP:
Log in to MariaDB and create a database and user for your CakePHP application:
sudo mysql -u root -p
Execute the following SQL commands:
CREATE DATABASE cakephp_db;
CREATE USER 'cakephp_user'@'localhost' IDENTIFIED BY 'secure_password';
GRANT ALL PRIVILEGES ON cakephp_db.* TO 'cakephp_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
7. Step 5: Download and Set Up CakePHP
Create a Directory for CakePHP:
Navigate to the web server’s root directory and create a folder for your CakePHP project:
cd /var/www
sudo mkdir cakephp-app
cd cakephp-app
Download CakePHP:
Use Composer to create a new CakePHP project:
composer create-project --prefer-dist cakephp/app:~4.0 .
Set Correct Permissions:
Ensure that the web server has proper access to the CakePHP files:
sudo chown -R apache:apache /var/www/cakephp-app
sudo chmod -R 775 /var/www/cakephp-app/tmp /var/www/cakephp-app/logs
8. Step 6: Configure Apache for CakePHP
Create a Virtual Host Configuration:
Set up a virtual host for your CakePHP application:
sudo nano /etc/httpd/conf.d/cakephp-app.conf
Add the following configuration:
<VirtualHost *:80>
ServerName yourdomain.com
DocumentRoot /var/www/cakephp-app/webroot
<Directory /var/www/cakephp-app/webroot>
AllowOverride All
Require all granted
</Directory>
ErrorLog /var/log/httpd/cakephp-app-error.log
CustomLog /var/log/httpd/cakephp-app-access.log combined
</VirtualHost>
Save and exit the file.
Enable Apache mod_rewrite:
CakePHP requires URL rewriting to work. Enable mod_rewrite
:
sudo dnf install mod_rewrite -y
sudo systemctl restart httpd
Test your configuration:
sudo apachectl configtest
9. Step 7: Test CakePHP Installation
Open your web browser and navigate to your server’s IP address or domain. If everything is configured correctly, you should see CakePHP’s default welcome page.
If you encounter any issues, check the Apache logs for debugging:
sudo tail -f /var/log/httpd/cakephp-app-error.log
10. Conclusion
Congratulations! You’ve successfully installed CakePHP on AlmaLinux. With this setup, you now have a solid foundation for building web applications using CakePHP’s powerful features.
From here, you can start creating your models, controllers, and views to develop dynamic and interactive web applications. AlmaLinux’s stability and CakePHP’s flexibility make for an excellent combination, ensuring reliable performance for your projects.
Happy coding!
11 - How to Install Node.js 16 on AlmaLinux: A Step-by-Step Guide
Node.js is a widely-used, cross-platform JavaScript runtime environment that empowers developers to build scalable server-side applications. The release of Node.js 16 introduced several features, including Apple M1 support, npm v7, and updated V8 JavaScript engine capabilities. AlmaLinux, a reliable and secure Linux distribution, is an excellent choice for running Node.js applications.
In this guide, we’ll walk through the steps to install Node.js 16 on AlmaLinux, ensuring you’re equipped to start building and deploying powerful JavaScript-based applications.
Table of Contents
- Introduction
- Prerequisites
- Step 1: Update Your System
- Step 2: Install Node.js 16 from NodeSource Repository
- Step 3: Verify Node.js and npm Installation
- Step 4: Manage Multiple Node.js Versions with NVM
- Step 5: Build and Run a Simple Node.js Application
- Step 6: Enable Firewall and Security Considerations
- Conclusion
1. Introduction
Node.js has gained immense popularity in the developer community for its ability to handle asynchronous I/O and real-time applications seamlessly. Its package manager, npm, further simplifies managing dependencies for projects. Installing Node.js 16 on AlmaLinux provides the perfect environment for modern web and backend development.
2. Prerequisites
Before starting, ensure you have:
- A server running AlmaLinux with root or sudo privileges.
- Basic knowledge of the Linux command line.
- Internet access to download packages.
3. Step 1: Update Your System
Keeping your system updated ensures it has the latest security patches and a stable software environment. Run the following commands:
sudo dnf update -y
sudo dnf upgrade -y
Once the update is complete, reboot the system to apply the changes:
sudo reboot
4. Step 2: Install Node.js 16 from NodeSource Repository
AlmaLinux’s default repositories may not always include the latest Node.js versions. To install Node.js 16, we’ll use the NodeSource repository.
Step 2.1: Add the NodeSource Repository
NodeSource provides a script to set up the repository for Node.js. Download and execute the setup script for Node.js 16:
curl -fsSL https://rpm.nodesource.com/setup_16.x | sudo bash -
Step 2.2: Install Node.js
After adding the repository, install Node.js with the following command:
sudo dnf install -y nodejs
Step 2.3: Install Build Tools (Optional but Recommended)
Some Node.js packages require compilation during installation. Install the necessary build tools to avoid errors:
sudo dnf groupinstall -y "Development Tools"
sudo dnf install -y gcc-c++ make
5. Step 3: Verify Node.js and npm Installation
After installation, verify that Node.js and its package manager, npm, were successfully installed:
node -v
You should see the version of Node.js, which should be 16.x.x
.
npm -v
This command will display the version of npm, which ships with Node.js.
6. Step 4: Manage Multiple Node.js Versions with NVM
If you want the flexibility to switch between different Node.js versions, the Node Version Manager (NVM) is a useful tool. Here’s how to set it up:
Step 4.1: Install NVM
Download and install NVM using the official script:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
Activate NVM by sourcing the profile:
source ~/.bashrc
Step 4.2: Install Node.js 16 with NVM
With NVM installed, use it to install Node.js 16:
nvm install 16
Verify the installation:
node -v
Step 4.3: Switch Between Node.js Versions
You can list all installed Node.js versions:
nvm list
Switch to a specific version (e.g., Node.js 16):
nvm use 16
7. Step 5: Build and Run a Simple Node.js Application
Now that Node.js 16 is installed, test your setup by building and running a simple Node.js application.
Step 5.1: Create a New Project Directory
Create a new directory for your project and navigate to it:
mkdir my-node-app
cd my-node-app
Step 5.2: Initialize a Node.js Project
Run the following command to create a package.json
file:
npm init -y
This file holds the project’s metadata and dependencies.
Step 5.3: Create a Simple Application
Use a text editor to create a file named app.js
:
nano app.js
Add the following code:
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello, Node.js on AlmaLinux!\n');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
Save and close the file.
Step 5.4: Run the Application
Run the application using Node.js:
node app.js
You should see the message:
Server running at http://127.0.0.1:3000/
Open a browser and navigate to http://127.0.0.1:3000/
to see your application in action.
8. Step 6: Enable Firewall and Security Considerations
If your server uses a firewall, ensure the necessary ports are open. For the above example, you need to open port 3000.
Open Port 3000:
sudo firewall-cmd --permanent --add-port=3000/tcp
sudo firewall-cmd --reload
Use a Process Manager (Optional):
For production environments, use a process manager like PM2 to manage your Node.js application. Install PM2 globally:
sudo npm install -g pm2
Start your application with PM2:
pm2 start app.js
9. Conclusion
Congratulations! You’ve successfully installed Node.js 16 on AlmaLinux. You’ve also set up a simple Node.js application and explored how to manage multiple Node.js versions with NVM. With this setup, you’re ready to develop, test, and deploy powerful JavaScript applications on a stable AlmaLinux environment.
By following this guide, you’ve taken the first step in leveraging Node.js’s capabilities for real-time, scalable, and efficient applications. Whether you’re building APIs, single-page applications, or server-side solutions, Node.js and AlmaLinux provide a robust foundation for your projects. Happy coding!
12 - How to Install Node.js 18 on AlmaLinux: A Step-by-Step Guide
Node.js is an open-source, cross-platform JavaScript runtime environment built on Chrome’s V8 engine. It’s widely used for developing scalable, server-side applications. With the release of Node.js 18, developers gain access to long-term support (LTS) features, enhanced performance, and security updates. AlmaLinux, a stable, enterprise-grade Linux distribution, is an excellent choice for hosting Node.js applications.
This detailed guide will walk you through installing Node.js 18 on AlmaLinux, managing its dependencies, and verifying the setup to ensure everything works seamlessly.
Table of Contents
- Introduction to Node.js 18
- Prerequisites
- Step 1: Update Your System
- Step 2: Install Node.js 18 from NodeSource
- Step 3: Verify Node.js and npm Installation
- Step 4: Manage Multiple Node.js Versions with NVM
- Step 5: Create and Run a Simple Node.js Application
- Step 6: Security and Firewall Configurations
- Conclusion
1. Introduction to Node.js 18
Node.js 18 introduces several key features, including:
- Global Fetch API: Native support for the Fetch API in Node.js applications.
- Improved Performance: Enhanced performance for asynchronous streams and timers.
- Enhanced Test Runner Module: Built-in tools for testing JavaScript code.
- Long-Term Support (LTS): Ensuring stability and extended support for production environments.
By installing Node.js 18 on AlmaLinux, you can take advantage of these features while leveraging AlmaLinux’s stability and security.
2. Prerequisites
Before proceeding, ensure the following prerequisites are met:
- A server running AlmaLinux.
- Root or sudo access to the server.
- Basic understanding of Linux commands.
- An active internet connection for downloading packages.
3. Step 1: Update Your System
Keeping your system up-to-date ensures that you have the latest security patches and system stability improvements. Run the following commands to update your AlmaLinux server:
sudo dnf update -y
sudo dnf upgrade -y
After completing the update, reboot your system to apply the changes:
sudo reboot
4. Step 2: Install Node.js 18 from NodeSource
AlmaLinux’s default repositories may not include the latest Node.js version. To install Node.js 18, we’ll use the official NodeSource repository.
Step 4.1: Add the NodeSource Repository
NodeSource provides a script to set up its repository for specific Node.js versions. Download and execute the setup script for Node.js 18:
curl -fsSL https://rpm.nodesource.com/setup_18.x | sudo bash -
Step 4.2: Install Node.js 18
Once the repository is added, install Node.js 18 with the following command:
sudo dnf install -y nodejs
Step 4.3: Install Development Tools (Optional)
Some Node.js packages require compilation during installation. Install development tools to ensure compatibility:
sudo dnf groupinstall -y "Development Tools"
sudo dnf install -y gcc-c++ make
5. Step 3: Verify Node.js and npm Installation
To confirm that Node.js and its package manager npm were installed correctly, check their versions:
Check Node.js Version:
node -v
Expected output:
v18.x.x
Check npm Version:
npm -v
npm is installed automatically with Node.js and allows you to manage JavaScript libraries and frameworks.
6. Step 4: Manage Multiple Node.js Versions with NVM
The Node Version Manager (NVM) is a useful tool for managing multiple Node.js versions on the same system. This is particularly helpful for developers working on projects that require different Node.js versions.
Step 6.1: Install NVM
Install NVM using its official script:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
Step 6.2: Load NVM
Activate NVM by sourcing your shell configuration file:
source ~/.bashrc
Step 6.3: Install Node.js 18 Using NVM
Use NVM to install Node.js 18:
nvm install 18
Step 6.4: Verify Installation
Check the installed Node.js version:
node -v
Step 6.5: Switch Between Versions
If you have multiple Node.js versions installed, you can list them:
nvm list
Switch to Node.js 18:
nvm use 18
7. Step 5: Create and Run a Simple Node.js Application
Now that Node.js 18 is installed, test it by creating and running a simple Node.js application.
Step 7.1: Create a Project Directory
Create a directory for your Node.js application and navigate to it:
mkdir my-node-app
cd my-node-app
Step 7.2: Initialize a Node.js Project
Run the following command to generate a package.json
file:
npm init -y
Step 7.3: Write a Simple Node.js Application
Create a file named app.js
:
nano app.js
Add the following code to create a basic HTTP server:
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello, Node.js 18 on AlmaLinux!\n');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
Save and close the file.
Step 7.4: Run the Application
Execute the application using Node.js:
node app.js
You should see the following message in the terminal:
Server running at http://127.0.0.1:3000/
Step 7.5: Test the Application
Open a web browser or use curl
to visit http://127.0.0.1:3000/
. You should see the message:
Hello, Node.js 18 on AlmaLinux!
8. Step 6: Security and Firewall Configurations
If your server is secured with a firewall, ensure the necessary port (e.g., 3000) is open for your Node.js application.
Open Port 3000:
sudo firewall-cmd --permanent --add-port=3000/tcp
sudo firewall-cmd --reload
Use PM2 for Process Management:
For production environments, use PM2, a process manager for Node.js applications. Install PM2 globally:
sudo npm install -g pm2
Start your application with PM2:
pm2 start app.js
PM2 ensures your Node.js application runs in the background and restarts automatically in case of failures.
9. Conclusion
Congratulations! You’ve successfully installed Node.js 18 on AlmaLinux. With this setup, you’re ready to develop modern, scalable JavaScript applications using the latest features and improvements in Node.js. Additionally, you’ve learned how to manage multiple Node.js versions with NVM and set up a basic Node.js server.
Whether you’re building APIs, real-time applications, or microservices, Node.js 18 and AlmaLinux provide a robust and reliable foundation for your development needs. Don’t forget to explore the new features in Node.js 18 and leverage its full potential for your projects.
Happy coding!
13 - How to Install Angular 14 on AlmaLinux: A Comprehensive Guide
Angular, a widely-used TypeScript-based framework, is a go-to choice for building scalable and dynamic web applications. With the release of Angular 14, developers enjoy enhanced features such as typed forms, standalone components, and streamlined Angular CLI commands. If you’re using AlmaLinux, a robust and enterprise-grade Linux distribution, this guide will walk you through the process of installing and setting up Angular 14 step-by-step.
Table of Contents
- What is Angular 14?
- Prerequisites
- Step 1: Update Your AlmaLinux System
- Step 2: Install Node.js (LTS Version)
- Step 3: Install Angular CLI
- Step 4: Create a New Angular Project
- Step 5: Serve and Test the Angular Application
- Step 6: Configure Angular for Production
- Conclusion
1. What is Angular 14?
Angular 14 is the latest iteration of Google’s Angular framework. It includes significant improvements like:
- Standalone Components: Simplifies module management by making components self-contained.
- Typed Reactive Forms: Adds strong typing to Angular forms, improving type safety and developer productivity.
- Optional Injectors in Embedded Views: Simplifies dependency injection for embedded views.
- Extended Developer Command Line Interface (CLI): Enhances the commands for generating components, services, and other resources.
By leveraging Angular 14, you can create efficient, maintainable, and future-proof applications.
2. Prerequisites
Before diving into the installation process, ensure you have:
- A server or workstation running AlmaLinux.
- Root or sudo access to install software and configure the system.
- An active internet connection for downloading dependencies.
- Familiarity with the command line and basic knowledge of web development.
3. Step 1: Update Your AlmaLinux System
Keeping your system updated ensures you have the latest security patches and software versions. Use the following commands to update AlmaLinux:
sudo dnf update -y
sudo dnf upgrade -y
After the update, reboot your system to apply changes:
sudo reboot
4. Step 2: Install Node.js (LTS Version)
Angular requires Node.js to run its development server and manage dependencies. For Angular 14, you’ll need Node.js version 16.x or higher.
Step 4.1: Add the NodeSource Repository
Install Node.js 16 (or later) from the official NodeSource repository:
curl -fsSL https://rpm.nodesource.com/setup_16.x | sudo bash -
Step 4.2: Install Node.js
Install Node.js along with npm (Node Package Manager):
sudo dnf install -y nodejs
Step 4.3: Verify Installation
After installation, verify the versions of Node.js and npm:
node -v
Expected output:
v16.x.x
npm -v
5. Step 3: Install Angular CLI
The Angular CLI (Command Line Interface) is a powerful tool that simplifies Angular project creation, management, and builds.
Step 5.1: Install Angular CLI
Install Angular CLI globally using npm:
sudo npm install -g @angular/cli
Step 5.2: Verify Angular CLI Installation
Check the installed version of Angular CLI to confirm it’s set up correctly:
ng version
Expected output:
Angular CLI: 14.x.x
6. Step 4: Create a New Angular Project
Once the Angular CLI is installed, you can create a new Angular project.
Step 6.1: Generate a New Angular Project
Run the following command to create a new project. Replace my-angular-app
with your desired project name:
ng new my-angular-app
The CLI will prompt you to:
- Choose whether to add Angular routing (type
Yes
orNo
based on your requirements). - Select a stylesheet format (e.g., CSS, SCSS, or LESS).
Step 6.2: Navigate to the Project Directory
After the project is created, move into the project directory:
cd my-angular-app
7. Step 5: Serve and Test the Angular Application
With the project set up, you can now serve it locally and test it.
Step 7.1: Start the Development Server
Run the following command to start the Angular development server:
ng serve
By default, the application will be available at http://localhost:4200/
. If you’re running on a remote server, you may need to bind the server to your system’s IP address:
ng serve --host 0.0.0.0 --port 4200
Step 7.2: Access the Application
Open a web browser and navigate to:
http://<your-server-ip>:4200/
You should see the default Angular welcome page. This confirms that your Angular 14 project is working correctly.
8. Step 6: Configure Angular for Production
Before deploying your Angular application, it’s essential to build it for production.
Step 8.1: Build the Application
Use the following command to create a production-ready build of your Angular application:
ng build --configuration production
This command will generate optimized files in the dist/
directory.
Step 8.2: Deploy the Application
You can deploy the contents of the dist/
folder to a web server like Apache, Nginx, or a cloud platform.
Example: Deploying with Apache
Install Apache on AlmaLinux:
sudo dnf install httpd -y sudo systemctl start httpd sudo systemctl enable httpd
Copy the built files to the Apache root directory:
sudo cp -r dist/my-angular-app/* /var/www/html/
Adjust permissions:
sudo chown -R apache:apache /var/www/html/
Restart Apache to serve the application:
sudo systemctl restart httpd
Your Angular application should now be accessible via your server’s IP or domain.
9. Conclusion
By following this guide, you’ve successfully installed and set up Angular 14 on AlmaLinux. You’ve also created, served, and prepared a production-ready Angular application. With the powerful features of Angular 14 and the stability of AlmaLinux, you’re equipped to build robust and scalable web applications.
Whether you’re a beginner exploring Angular or an experienced developer, this setup provides a solid foundation for creating modern, dynamic applications. As you dive deeper into Angular, explore advanced topics such as state management with NgRx, lazy loading, and server-side rendering to enhance your projects.
Happy coding!
14 - How to Install React on AlmaLinux: A Comprehensive Guide
React, a powerful JavaScript library developed by Facebook, is a popular choice for building dynamic and interactive user interfaces. React’s component-based architecture and reusable code modules make it ideal for creating scalable web applications. If you’re using AlmaLinux, an enterprise-grade Linux distribution, this guide will show you how to install and set up React for web development.
In this tutorial, we’ll cover everything from installing the prerequisites to creating a new React application, testing it, and preparing it for deployment.
Table of Contents
- What is React and Why Use It?
- Prerequisites
- Step 1: Update AlmaLinux
- Step 2: Install Node.js and npm
- Step 3: Install the Create React App Tool
- Step 4: Create a React Application
- Step 5: Run and Test the React Application
- Step 6: Build and Deploy the React Application
- Step 7: Security and Firewall Configurations
- Conclusion
1. What is React and Why Use It?
React is a JavaScript library used for building user interfaces, particularly for single-page applications (SPAs). It allows developers to create reusable UI components, manage state efficiently, and render updates quickly.
Key features of React include:
- Virtual DOM: Efficiently updates and renders only the components that change.
- Component-Based Architecture: Encourages modular and reusable code.
- Strong Ecosystem: A vast collection of tools, libraries, and community support.
- Flexibility: Can be used with other libraries and frameworks.
Setting up React on AlmaLinux ensures a stable and reliable development environment for building modern web applications.
2. Prerequisites
Before you begin, make sure you have:
- AlmaLinux server or workstation.
- Sudo privileges to install packages.
- A basic understanding of the Linux command line.
- An active internet connection for downloading dependencies.
3. Step 1: Update AlmaLinux
Start by updating your AlmaLinux system to ensure you have the latest packages and security updates:
sudo dnf update -y
sudo dnf upgrade -y
Reboot the system to apply updates:
sudo reboot
4. Step 2: Install Node.js and npm
React relies on Node.js and its package manager, npm, for running its development server and managing dependencies.
Step 4.1: Add the NodeSource Repository
Install Node.js (LTS version) from the official NodeSource repository:
curl -fsSL https://rpm.nodesource.com/setup_16.x | sudo bash -
Step 4.2: Install Node.js
Once the repository is added, install Node.js and npm:
sudo dnf install -y nodejs
Step 4.3: Verify Installation
After installation, check the versions of Node.js and npm:
node -v
Expected output:
v16.x.x
npm -v
npm is installed automatically with Node.js and is essential for managing React dependencies.
5. Step 3: Install the Create React App Tool
The easiest way to create a React application is by using the create-react-app
tool. This CLI tool sets up a React project with all the necessary configurations.
Step 5.1: Install Create React App Globally
Run the following command to install the tool globally:
sudo npm install -g create-react-app
Step 5.2: Verify Installation
Confirm that create-react-app
is installed correctly:
create-react-app --version
6. Step 4: Create a React Application
Now that the setup is complete, you can create a new React application.
Step 6.1: Create a New React Project
Navigate to your desired directory (e.g., /var/www/
) and create a new React project. Replace my-react-app
with your desired project name:
create-react-app my-react-app
This command will download and set up all the dependencies required for a React application.
Step 6.2: Navigate to the Project Directory
Change to the newly created directory:
cd my-react-app
7. Step 5: Run and Test the React Application
Step 7.1: Start the Development Server
Run the following command to start the React development server:
npm start
By default, the development server runs on port 3000
. If you’re running this on a remote server, you may need to bind the server to the system’s IP address:
npm start -- --host 0.0.0.0
Step 7.2: Access the React Application
Open a browser and navigate to:
http://<your-server-ip>:3000/
You should see the default React welcome page, confirming that your React application is up and running.
8. Step 6: Build and Deploy the React Application
Once your application is ready for deployment, you need to create a production build.
Step 8.1: Build the Application
Run the following command to create a production-ready build:
npm run build
This will generate optimized files in the build/
directory.
Step 8.2: Deploy Using a Web Server
You can serve the built files using a web server like Apache or Nginx.
Example: Deploying with Nginx
Install Nginx:
sudo dnf install nginx -y
Configure Nginx: Open the Nginx configuration file:
sudo nano /etc/nginx/conf.d/react-app.conf
Add the following configuration:
server { listen 80; server_name yourdomain.com; root /path/to/my-react-app/build; index index.html; location / { try_files $uri /index.html; } }
Replace
/path/to/my-react-app/build
with the actual path to your React app’s build directory.Restart Nginx:
sudo systemctl restart nginx
Your React application will now be accessible via your domain or server IP.
9. Step 7: Security and Firewall Configurations
If you’re using a firewall, ensure that necessary ports are open for both development and production environments.
Open Port 3000 (for Development Server):
sudo firewall-cmd --permanent --add-port=3000/tcp
sudo firewall-cmd --reload
Open Port 80 (for Nginx Production):
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --reload
10. Conclusion
By following this guide, you’ve successfully installed React on AlmaLinux and created your first React application. React’s flexibility and AlmaLinux’s stability make for an excellent combination for developing modern web applications. You’ve also learned how to serve and deploy your application, ensuring it’s accessible for end-users.
As you dive deeper into React, explore its ecosystem of libraries like React Router, Redux for state management, and tools like Next.js for server-side rendering. Whether you’re a beginner or an experienced developer, this setup provides a robust foundation for building dynamic and interactive web applications.
Happy coding!
15 - How to Install Next.js on AlmaLinux: A Comprehensive Guide
Next.js is a popular React framework for building server-rendered applications, static websites, and modern web applications with ease. Developed by Vercel, Next.js provides powerful features like server-side rendering (SSR), static site generation (SSG), and API routes, making it an excellent choice for developers who want to create scalable and high-performance web applications.
If you’re running AlmaLinux, an enterprise-grade Linux distribution, this guide will walk you through installing and setting up Next.js on your system. By the end of this tutorial, you’ll have a functional Next.js project ready for development or deployment.
Table of Contents
- What is Next.js and Why Use It?
- Prerequisites
- Step 1: Update Your AlmaLinux System
- Step 2: Install Node.js and npm
- Step 3: Create a New Next.js Application
- Step 4: Start and Test the Next.js Development Server
- Step 5: Build and Deploy the Next.js Application
- Step 6: Deploy Next.js with Nginx
- Step 7: Security and Firewall Considerations
- Conclusion
1. What is Next.js and Why Use It?
Next.js is an open-source React framework that extends React’s capabilities by adding server-side rendering (SSR) and static site generation (SSG). These features make it ideal for creating fast, SEO-friendly web applications.
Key features of Next.js include:
- Server-Side Rendering (SSR): Improves SEO and user experience by rendering content on the server.
- Static Site Generation (SSG): Builds static HTML pages at build time for faster loading.
- Dynamic Routing: Supports route-based code splitting and dynamic routing.
- API Routes: Enables serverless API functionality.
- Integrated TypeScript Support: Simplifies development with built-in TypeScript support.
By combining React’s component-based architecture with Next.js’s performance optimizations, you can build robust web applications with minimal effort.
2. Prerequisites
Before proceeding, ensure the following prerequisites are met:
- A server running AlmaLinux.
- Root or sudo access to install software and configure the system.
- Familiarity with basic Linux commands and web development concepts.
- An active internet connection for downloading dependencies.
3. Step 1: Update Your AlmaLinux System
Start by updating your AlmaLinux system to ensure you have the latest packages and security patches:
sudo dnf update -y
sudo dnf upgrade -y
Reboot the system to apply the updates:
sudo reboot
4. Step 2: Install Node.js and npm
Next.js requires Node.js to run its development server and manage dependencies.
Step 4.1: Add the NodeSource Repository
Install the latest Long-Term Support (LTS) version of Node.js (currently Node.js 18) using the NodeSource repository:
curl -fsSL https://rpm.nodesource.com/setup_18.x | sudo bash -
Step 4.2: Install Node.js and npm
Install Node.js and its package manager npm:
sudo dnf install -y nodejs
Step 4.3: Verify Installation
After installation, verify the versions of Node.js and npm:
node -v
Expected output:
v18.x.x
npm -v
5. Step 3: Create a New Next.js Application
With Node.js and npm installed, you can now create a new Next.js application using the create-next-app
command.
Step 5.1: Install Create Next App
Run the following command to install the create-next-app
tool globally:
sudo npm install -g create-next-app
Step 5.2: Create a New Project
Generate a new Next.js application by running:
npx create-next-app my-nextjs-app
You’ll be prompted to:
- Specify the project name (you can press Enter to use the default name).
- Choose whether to use TypeScript (recommended for better type safety).
Once the command finishes, it will set up a new Next.js application in the my-nextjs-app
directory.
Step 5.3: Navigate to the Project Directory
Move into your project directory:
cd my-nextjs-app
6. Step 4: Start and Test the Next.js Development Server
Next.js includes a built-in development server that you can use to test your application locally.
Step 6.1: Start the Development Server
Run the following command to start the server:
npm run dev
By default, the server runs on port 3000
. If you’re running this on a remote server, bind the server to all available IP addresses:
npm run dev -- --host 0.0.0.0
Step 6.2: Access the Application
Open your browser and navigate to:
http://<your-server-ip>:3000/
You should see the default Next.js welcome page, confirming that your application is running successfully.
7. Step 5: Build and Deploy the Next.js Application
When your application is ready for production, you need to create a production build.
Step 7.1: Build the Application
Run the following command to generate optimized production files:
npm run build
The build process will generate static and server-rendered files in the .next/
directory.
Step 7.2: Start the Production Server
To serve the production build locally, use the following command:
npm run start
8. Step 6: Deploy Next.js with Nginx
For production, you’ll typically use a web server like Nginx to serve your Next.js application.
Step 8.1: Install Nginx
Install Nginx on AlmaLinux:
sudo dnf install nginx -y
Step 8.2: Configure Nginx
Open a new Nginx configuration file:
sudo nano /etc/nginx/conf.d/nextjs-app.conf
Add the following configuration:
server {
listen 80;
server_name yourdomain.com;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
Replace yourdomain.com
with your domain name or server IP.
Step 8.3: Restart Nginx
Restart Nginx to apply the configuration:
sudo systemctl restart nginx
Now, your Next.js application will be accessible via your domain or server IP.
9. Step 7: Security and Firewall Considerations
Open Necessary Ports
If you’re using a firewall, open port 3000
for development or port 80
for production:
sudo firewall-cmd --permanent --add-port=3000/tcp
sudo firewall-cmd --add-service=http --permanent
sudo firewall-cmd --reload
10. Conclusion
By following this guide, you’ve successfully installed and set up Next.js on AlmaLinux. You’ve learned how to create a new Next.js project, test it using the built-in development server, and deploy it in a production environment using Nginx.
With Next.js, you have a powerful framework for building fast, scalable, and SEO-friendly web applications. As you dive deeper, explore advanced features like API routes, dynamic routing, and server-side rendering to maximize Next.js’s potential.
Happy coding!
16 - How to Set Up Node.js and TypeScript on AlmaLinux
Node.js is a powerful runtime for building scalable, server-side applications, and TypeScript adds a layer of type safety to JavaScript, enabling developers to catch errors early in the development cycle. Combining these two tools creates a strong foundation for developing modern web applications. If you’re using AlmaLinux, a robust, community-driven Linux distribution derived from RHEL, this guide will walk you through the steps to set up Node.js with TypeScript.
Why Choose Node.js with TypeScript?
Node.js is popular for its non-blocking, event-driven architecture, which makes it ideal for building real-time applications. However, JavaScript’s dynamic typing can sometimes lead to runtime errors that are hard to debug. TypeScript mitigates these issues by introducing static typing and powerful development tools, including better editor support, auto-completion, and refactoring capabilities.
AlmaLinux, as an enterprise-grade Linux distribution, provides a stable and secure environment for deploying applications. Setting up Node.js and TypeScript on AlmaLinux ensures you’re working on a reliable platform optimized for performance.
Prerequisites
Before starting, ensure you have the following:
- A fresh AlmaLinux installation: This guide assumes you have administrative access.
- Root or sudo privileges: Most commands will require superuser permissions.
- Basic knowledge of the terminal: Familiarity with Linux commands will help you navigate through this guide.
Step 1: Update the System
Start by ensuring your system is up-to-date:
sudo dnf update -y
This command updates all installed packages and ensures you have the latest security patches and features.
Step 2: Install Node.js
There are multiple ways to install Node.js on AlmaLinux, but the recommended method is using the NodeSource repository to get the latest version.
Add the NodeSource Repository
NodeSource provides RPM packages for Node.js. Use the following commands to add the repository and install Node.js:
curl -fsSL https://rpm.nodesource.com/setup_18.x | sudo bash -
Replace 18.x
with the version you want to install. This script sets up the Node.js repository.
Install Node.js
After adding the repository, install Node.js with:
sudo dnf install -y nodejs
Verify the Installation
Check if Node.js and npm (Node Package Manager) were installed successfully:
node -v
npm -v
These commands should output the installed versions of Node.js and npm.
Step 3: Install TypeScript
TypeScript can be installed globally using npm. Run the following command to install it:
sudo npm install -g typescript
After installation, verify the TypeScript version:
tsc -v
The tsc
command is the TypeScript compiler, and its version number confirms a successful installation.
Step 4: Set Up a TypeScript Project
Once Node.js and TypeScript are installed, you can create a new TypeScript project.
Create a Project Directory
Navigate to your workspace and create a new directory for your project:
mkdir my-typescript-app
cd my-typescript-app
Initialize a Node.js Project
Run the following command to generate a package.json
file, which manages your project’s dependencies:
npm init -y
This creates a default package.json
file with basic settings.
Install TypeScript Locally
While TypeScript is installed globally, it’s good practice to also include it as a local dependency for the project:
npm install typescript --save-dev
Generate a TypeScript Configuration File
The tsconfig.json
file configures the TypeScript compiler. Generate it with:
npx tsc --init
A basic tsconfig.json
file will look like this:
{
"compilerOptions": {
"target": "ES6",
"module": "commonjs",
"outDir": "./dist",
"strict": true
},
"include": ["src/**/*"],
"exclude": ["node_modules"]
}
target
: Specifies the ECMAScript version for the compiled JavaScript.module
: Defines the module system (e.g.,commonjs
for Node.js).outDir
: Specifies the output directory for compiled files.strict
: Enables strict type checking.include
andexclude
: Define which files should be included or excluded from compilation.
Create the Project Structure
Organize your project files by creating a src
directory for TypeScript files:
mkdir src
Create a sample TypeScript file:
nano src/index.ts
Add the following code to index.ts
:
const message: string = "Hello, TypeScript on AlmaLinux!";
console.log(message);
Step 5: Compile and Run the TypeScript Code
To compile the TypeScript code into JavaScript, run:
npx tsc
This command compiles all .ts
files in the src
directory into .js
files in the dist
directory (as configured in tsconfig.json
).
Navigate to the dist
directory and run the compiled JavaScript file:
node dist/index.js
You should see the following output:
Hello, TypeScript on AlmaLinux!
Step 6: Add Type Definitions
Type definitions provide type information for JavaScript libraries and are essential when working with TypeScript. Install type definitions for Node.js:
npm install --save-dev @types/node
If you use other libraries, you can search and install their type definitions using:
npm install --save-dev @types/<library-name>
Step 7: Automate with npm Scripts
To streamline your workflow, add scripts to your package.json
file:
"scripts": {
"build": "tsc",
"start": "node dist/index.js",
"dev": "tsc && node dist/index.js"
}
build
: Compiles the TypeScript code.start
: Runs the compiled JavaScript.dev
: Compiles and runs the code in a single step.
Run these scripts using:
npm run build
npm run start
Step 8: Debugging TypeScript
TypeScript integrates well with modern editors like Visual Studio Code, which provides debugging tools, IntelliSense, and error checking. Use the tsconfig.json
file to fine-tune debugging settings, such as enabling source maps.
Add the following to tsconfig.json
for better debugging:
"compilerOptions": {
"sourceMap": true
}
This generates .map
files, linking the compiled JavaScript back to the original TypeScript code for easier debugging.
Step 9: Deployment Considerations
When deploying Node.js applications on AlmaLinux, consider these additional steps:
Process Management: Use a process manager like PM2 to keep your application running:
sudo npm install -g pm2 pm2 start dist/index.js
Firewall Configuration: Open necessary ports for your application using
firewalld
:sudo firewall-cmd --permanent --add-port=3000/tcp sudo firewall-cmd --reload
Reverse Proxy: Use Nginx or Apache as a reverse proxy for production environments.
Conclusion
Setting up Node.js with TypeScript on AlmaLinux provides a powerful stack for developing and deploying scalable applications. By following this guide, you’ve configured your system, set up a TypeScript project, and prepared it for development and production.
Embrace the benefits of static typing, better tooling, and AlmaLinux’s robust environment for your next application. With TypeScript and Node.js, you’re equipped to build reliable, maintainable, and modern software solutions.
17 - How to Install Python 3.9 on AlmaLinux
Python is one of the most popular programming languages in the world, valued for its simplicity, versatility, and extensive library support. Whether you’re a developer working on web applications, data analysis, or automation, Python 3.9 offers several new features and optimizations to enhance your productivity. This guide will walk you through the process of installing Python 3.9 on AlmaLinux, a community-driven enterprise operating system derived from RHEL.
Why Python 3.9?
Python 3.9 introduces several enhancements, including:
- New Syntax Features:
- Dictionary merge and update operators (
|
and|=
). - New string methods like
str.removeprefix()
andstr.removesuffix()
.
- Dictionary merge and update operators (
- Performance Improvements: Faster execution for some operations.
- Improved Typing: Type hints are more powerful and versatile.
- Module Enhancements: Updates to modules like
zoneinfo
for timezone handling.
Using Python 3.9 ensures compatibility with the latest libraries and frameworks while enabling you to take advantage of its new features.
Prerequisites
Before proceeding, ensure the following:
- AlmaLinux system: A fresh installation of AlmaLinux with root or sudo privileges.
- Terminal access: Familiarity with Linux command-line tools.
- Basic knowledge of Python: Understanding of Python basics will help in testing the installation.
Step 1: Update Your System
Begin by updating your AlmaLinux system to ensure all packages are up-to-date:
sudo dnf update -y
This ensures that you have the latest security patches and package versions.
Step 2: Check the Default Python Version
AlmaLinux comes with a default version of Python, which is used for system utilities. Check the currently installed version:
python3 --version
The default version might not be Python 3.9. To avoid interfering with system utilities, we’ll install Python 3.9 separately.
Step 3: Enable the Required Repositories
To install Python 3.9 on AlmaLinux, you need to enable the EPEL (Extra Packages for Enterprise Linux) and PowerTools repositories.
Enable EPEL Repository
Install the EPEL repository by running:
sudo dnf install -y epel-release
Enable PowerTools Repository
Enable the PowerTools repository (renamed to crb
in AlmaLinux 9):
sudo dnf config-manager --set-enabled crb
These repositories provide additional packages and dependencies required for Python 3.9.
Step 4: Install Python 3.9
With the repositories enabled, install Python 3.9:
sudo dnf install -y python39
Verify the Installation
Once the installation is complete, check the Python version:
python3.9 --version
You should see an output like:
Python 3.9.x
Step 5: Set Python 3.9 as Default (Optional)
If you want to use Python 3.9 as the default version of Python 3, you can update the alternatives system. This is optional but helpful if you plan to primarily use Python 3.9.
Configure Alternatives
Run the following commands to configure alternatives
for Python:
sudo alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 1
sudo alternatives --config python3
You’ll be prompted to select the version of Python you want to use as the default. Choose the option corresponding to Python 3.9.
Verify the Default Version
Check the default version of Python 3:
python3 --version
Step 6: Install pip for Python 3.9
pip
is the package manager for Python and is essential for managing libraries and dependencies.
Install pip
Install pip
for Python 3.9 with the following command:
sudo dnf install -y python39-pip
Verify pip Installation
Check the installed version of pip:
pip3.9 --version
Now, you can use pip3.9
to install Python packages.
Step 7: Create a Virtual Environment
To manage dependencies effectively, it’s recommended to use virtual environments. Virtual environments isolate your projects, ensuring they don’t interfere with each other or the system Python installation.
Create a Virtual Environment
Run the following commands to create and activate a virtual environment:
python3.9 -m venv myenv
source myenv/bin/activate
You’ll notice your terminal prompt changes to indicate the virtual environment is active.
Install Packages in the Virtual Environment
While the virtual environment is active, you can use pip
to install packages. For example:
pip install numpy
Deactivate the Virtual Environment
When you’re done, deactivate the virtual environment by running:
deactivate
Step 8: Test the Installation
Let’s create a simple Python script to verify that everything is working correctly.
Create a Test Script
Create a new file named test.py
:
nano test.py
Add the following code:
print("Hello, Python 3.9 on AlmaLinux!")
Save the file and exit the editor.
Run the Script
Execute the script using Python 3.9:
python3.9 test.py
You should see the output:
Hello, Python 3.9 on AlmaLinux!
Step 9: Troubleshooting
Here are some common issues you might encounter during installation and their solutions:
python3.9: command not found
:- Ensure Python 3.9 is installed correctly using
sudo dnf install python39
. - Verify the installation path:
/usr/bin/python3.9
.
- Ensure Python 3.9 is installed correctly using
pip3.9: command not found
:- Reinstall pip using
sudo dnf install python39-pip
.
- Reinstall pip using
Conflicts with Default Python:
- Avoid replacing the system’s default Python version, as it might break system utilities. Use virtual environments instead.
Step 10: Keeping Python 3.9 Updated
To keep Python 3.9 updated, use dnf
to check for updates periodically:
sudo dnf upgrade python39
Alternatively, consider using pyenv
for managing multiple Python versions if you frequently work with different versions.
Conclusion
Installing Python 3.9 on AlmaLinux equips you with a powerful tool for developing modern applications. By following this guide, you’ve successfully installed Python 3.9, set up pip, created a virtual environment, and verified the installation. AlmaLinux provides a stable and secure foundation, making it an excellent choice for running Python applications in production.
Whether you’re building web applications, automating tasks, or diving into data science, Python 3.9 offers the features and stability to support your projects. Happy coding!
18 - How to Install Django 4 on AlmaLinux
Django is one of the most popular Python frameworks for building robust, scalable web applications. With its “batteries-included” approach, Django offers a range of tools and features to streamline web development, from handling user authentication to database migrations. In this guide, we will walk you through the steps to install Django 4 on AlmaLinux, a stable and secure enterprise Linux distribution derived from RHEL.
Why Choose Django 4?
Django 4 introduces several enhancements and optimizations, including:
- New Features:
- Async support for ORM queries.
- Functional middleware for better performance.
- Enhanced Security:
- More secure cookie settings.
- Improved cross-site scripting (XSS) protection.
- Modernized Codebase:
- Dropped support for older Python versions, ensuring compatibility with the latest tools.
Django 4 is ideal for developers seeking cutting-edge functionality without compromising stability.
Prerequisites
Before starting, ensure you have the following:
- AlmaLinux installed: This guide assumes you have administrative access.
- Python 3.8 or newer: Django 4 requires Python 3.8 or higher.
- Sudo privileges: Many steps require administrative rights.
Step 1: Update the System
Start by updating your system to ensure you have the latest packages and security updates:
sudo dnf update -y
Step 2: Install Python
Django requires Python 3.8 or newer. AlmaLinux may not have the latest Python version pre-installed, so follow these steps to install Python.
Enable the Required Repositories
First, enable the Extra Packages for Enterprise Linux (EPEL) and CodeReady Builder (CRB) repositories:
sudo dnf install -y epel-release
sudo dnf config-manager --set-enabled crb
Install Python
Next, install Python 3.9 or a newer version:
sudo dnf install -y python39 python39-pip python39-devel
Verify the Python Installation
Check the installed Python version:
python3.9 --version
You should see an output like:
Python 3.9.x
Step 3: Install and Configure Virtual Environment
It’s best practice to use a virtual environment to isolate your Django project dependencies. Virtual environments ensure your project doesn’t interfere with system-level Python packages or other projects.
Install venv
The venv
module comes with Python 3.9, so you don’t need to install it separately. If it’s not already installed, ensure the python39-devel
package is present.
Create a Virtual Environment
Create a directory for your project and initialize a virtual environment:
mkdir my_django_project
cd my_django_project
python3.9 -m venv venv
Activate the Virtual Environment
Activate the virtual environment with the following command:
source venv/bin/activate
Your terminal prompt will change to indicate the virtual environment is active, e.g., (venv)
.
Step 4: Install Django 4
With the virtual environment activated, install Django using pip
:
pip install django==4.2
You can verify the installation by checking the Django version:
python -m django --version
The output should show:
4.2.x
Step 5: Create a Django Project
With Django installed, you can now create a new Django project.
Create a New Project
Run the following command to create a Django project named myproject
:
django-admin startproject myproject .
This command initializes a Django project in the current directory. The project structure will look like this:
my_django_project/
├── manage.py
├── myproject/
│ ├── __init__.py
│ ├── asgi.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
└── venv/
Run the Development Server
Start the built-in Django development server to test the setup:
python manage.py runserver
Open your browser and navigate to http://127.0.0.1:8000
. You should see the Django welcome page, confirming that your installation was successful.
Step 6: Configure the Firewall
If you want to access your Django development server from other devices, configure the AlmaLinux firewall to allow traffic on port 8000.
Allow Port 8000
Run the following commands to open port 8000:
sudo firewall-cmd --permanent --add-port=8000/tcp
sudo firewall-cmd --reload
Now, you can access the server from another device using your AlmaLinux machine’s IP address.
Step 7: Configure Database Support
By default, Django uses SQLite, which is suitable for development. For production, consider using a more robust database like PostgreSQL or MySQL.
Install PostgreSQL
Install PostgreSQL and its Python adapter:
sudo dnf install -y postgresql-server postgresql-devel
pip install psycopg2
Update Django Settings
Edit the settings.py
file to configure PostgreSQL as the database:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'mydatabase',
'USER': 'myuser',
'PASSWORD': 'mypassword',
'HOST': 'localhost',
'PORT': '5432',
}
}
Apply Migrations
Run migrations to set up the database:
python manage.py migrate
Step 8: Deploy Django with a Production Server
The Django development server is not suitable for production. Use a WSGI server like Gunicorn with Nginx or Apache for a production environment.
Install Gunicorn
Install Gunicorn using pip
:
pip install gunicorn
Test Gunicorn
Run Gunicorn to serve your Django project:
gunicorn myproject.wsgi:application
Install and Configure Nginx
Install Nginx as a reverse proxy:
sudo dnf install -y nginx
Create a new configuration file for your Django project:
sudo nano /etc/nginx/conf.d/myproject.conf
Add the following configuration:
server {
listen 80;
server_name your_domain_or_ip;
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
Restart Nginx to apply the changes:
sudo systemctl restart nginx
Step 9: Secure the Application
For production, secure your application by enabling HTTPS with a free SSL certificate from Let’s Encrypt.
Install Certbot
Install Certbot for Nginx:
sudo dnf install -y certbot python3-certbot-nginx
Obtain an SSL Certificate
Run the following command to obtain and configure an SSL certificate:
sudo certbot --nginx -d your_domain
Certbot will automatically configure Nginx to use the SSL certificate.
Conclusion
By following this guide, you’ve successfully installed Django 4 on AlmaLinux, set up a project, configured the database, and prepared the application for production deployment. AlmaLinux provides a secure and stable platform for Django, making it a great choice for developing and hosting web applications.
Django 4’s features, combined with AlmaLinux’s reliability, enable you to build scalable, secure, and modern web applications. Whether you’re developing for personal projects or enterprise-grade systems, this stack is a powerful foundation for your web development journey. Happy coding!