{"id":20,"date":"2024-09-27T13:14:17","date_gmt":"2024-09-27T13:14:17","guid":{"rendered":"https:\/\/blog.akbv.dev\/?p=20"},"modified":"2024-09-27T14:59:23","modified_gmt":"2024-09-27T14:59:23","slug":"set-up-development-environment-in-ubuntu-22-04-lamp-and-more","status":"publish","type":"post","link":"https:\/\/blog.akbv.dev\/?p=20","title":{"rendered":"Set Up Development Environment in Ubuntu 22.04 &#8211; LAMP and More"},"content":{"rendered":"\n<div class=\"wp-block-cover is-light\"><span aria-hidden=\"true\" class=\"wp-block-cover__background has-background-dim\" style=\"background-color:#ac9f90\"><\/span><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"1024\" src=\"https:\/\/blog.akbv.dev\/wp-content\/uploads\/2024\/09\/generate-image-4.png\" class=\"wp-block-cover__image-background wp-post-image\" alt=\"\" data-object-fit=\"cover\" srcset=\"https:\/\/blog.akbv.dev\/wp-content\/uploads\/2024\/09\/generate-image-4.png 1024w, https:\/\/blog.akbv.dev\/wp-content\/uploads\/2024\/09\/generate-image-4-300x300.png 300w, https:\/\/blog.akbv.dev\/wp-content\/uploads\/2024\/09\/generate-image-4-150x150.png 150w, https:\/\/blog.akbv.dev\/wp-content\/uploads\/2024\/09\/generate-image-4-768x768.png 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><div class=\"wp-block-cover__inner-container is-layout-constrained wp-block-cover-is-layout-constrained\">\n<p><\/p>\n<\/div><\/div>\n\n\n\n<p>Are you an aspiring developer looking to set up your development environment in Ubuntu 22.04? Look no further! In this guide, we will walk you through the process of setting up a powerful development environment using the LAMP (Linux, Apache, MySQL, PHP) stack. We will also cover additional tools like Xdebug, Fail2ban, SSL, and firewall to ensure the security and smooth functioning of your development environment. So let&#8217;s get started!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"prerequisites\"><a href=\"https:\/\/akbv.dev\/blog\/set-up-development-environment-in-ubuntu-22-04-lamp-and-more#prerequisites\"><\/a>Prerequisites<\/h2>\n\n\n\n<p>Before we begin, make sure you have a fresh installation of Ubuntu 22.04. Once you have that, open up a terminal and let&#8217;s get started with the setup process.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"step-1-update-and-upgrade\"><a href=\"https:\/\/akbv.dev\/blog\/set-up-development-environment-in-ubuntu-22-04-lamp-and-more#step-1-update-and-upgrade\"><\/a>Step 1: Update and Upgrade<\/h2>\n\n\n\n<p>The first step is to update and upgrade your system. Run the following commands in your terminal:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update\nsudo apt dist-upgrade\n<\/code><\/pre>\n\n\n\n<p>These commands will update your package lists and upgrade any existing packages to their latest versions. This ensures that your system is up to date and ready for the installation of other components.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"step-2-install-essential-tools\"><a href=\"https:\/\/akbv.dev\/blog\/set-up-development-environment-in-ubuntu-22-04-lamp-and-more#step-2-install-essential-tools\"><\/a>Step 2: Install Essential Tools<\/h2>\n\n\n\n<p>Next, we will install some essential tools that will come in handy during the setup process. Run the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install sudo curl htop mc net-tools tree\n<\/code><\/pre>\n\n\n\n<p>This command will install&nbsp;<code>sudo<\/code>&nbsp;(if it&#8217;s not already installed),&nbsp;<code>curl<\/code>,&nbsp;<code>htop<\/code>,&nbsp;<code>mc<\/code>, and&nbsp;<code>net-tools<\/code>. These tools will make it easier for you to manage your system and perform various tasks.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"step-3-add-user-to-sudoers\"><a href=\"https:\/\/akbv.dev\/blog\/set-up-development-environment-in-ubuntu-22-04-lamp-and-more#step-3-add-user-to-sudoers\"><\/a>Step 3: Add User to Sudoers<\/h2>\n\n\n\n<p>By default, the&nbsp;<code>sudo<\/code>&nbsp;command is only available to the root user. To add your user to the sudoers list and allow them to run commands with root privileges, run the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo usermod -aG sudo YOUR_USER\n<\/code><\/pre>\n\n\n\n<p>Replace&nbsp;<code>YOUR_USER<\/code>&nbsp;with your actual username. This command will add your user to the&nbsp;<code>sudo<\/code>&nbsp;group, allowing them to execute commands as a superuser.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"step-4-install-apache2\"><a href=\"https:\/\/akbv.dev\/blog\/set-up-development-environment-in-ubuntu-22-04-lamp-and-more#step-4-install-apache2\"><\/a>Step 4: Install Apache2<\/h2>\n\n\n\n<p>Now, let&#8217;s install the Apache web server. Apache is a widely used web server that will serve as the backbone of our development environment. Run the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install apache2 apache2-utils\n<\/code><\/pre>\n\n\n\n<p>This command will install Apache and its utilities. Once the installation is complete, Apache will be up and running on your system.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"step-5-activate-apache2-modules\"><a href=\"https:\/\/akbv.dev\/blog\/set-up-development-environment-in-ubuntu-22-04-lamp-and-more#step-5-activate-apache2-modules\"><\/a>Step 5: Activate Apache2 Modules<\/h2>\n\n\n\n<p>To enhance the functionality of Apache, we need to activate some essential modules. Run the following command to activate the required modules:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo a2enmod rewrite ssl headers http2 vhost_alias\n<\/code><\/pre>\n\n\n\n<p>These modules will enable features like URL rewriting, SSL support, HTTP\/2 protocol, and virtual host aliasing. Enabling these modules will enhance the performance and security of your web server.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"step-6-configure-apache2-ssl\"><a href=\"https:\/\/akbv.dev\/blog\/set-up-development-environment-in-ubuntu-22-04-lamp-and-more#step-6-configure-apache2-ssl\"><\/a>Step 6: Configure Apache2 SSL<\/h2>\n\n\n\n<p>To secure your web server and enable SSL encryption, we need to generate a self-signed SSL certificate. Run the following commands to generate the certificate:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout \/etc\/ssl\/private\/apache-selfsigned.key -out \/etc\/ssl\/certs\/apache-selfsigned.crt\n<\/code><\/pre>\n\n\n\n<p>These commands will create a self-signed SSL certificate and place it in the appropriate directories. Note that this is a self-signed certificate and should only be used for development purposes. For production environments, consider using a trusted SSL certificate.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"step-7-update-apache2-configuration\"><a href=\"https:\/\/akbv.dev\/blog\/set-up-development-environment-in-ubuntu-22-04-lamp-and-more#step-7-update-apache2-configuration\"><\/a>Step 7: Update Apache2 Configuration<\/h2>\n\n\n\n<p>To optimize the Apache configuration for your development environment, we need to make some changes to the&nbsp;<code>apache2.conf<\/code>&nbsp;file. Run the following command to open the file in a text editor:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nano \/etc\/apache2\/apache2.conf\n<\/code><\/pre>\n\n\n\n<p>Once the file is open, locate the&nbsp;<code>&lt;Directory \/var\/www\/&gt;<\/code>&nbsp;section and modify it as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;Directory \/var\/www\/&gt;\n    Options -Indexes +FollowSymLinks\n    AllowOverride All\n    Require all granted\n&lt;\/Directory&gt;\n<\/code><\/pre>\n\n\n\n<p>These changes will disable directory listing, allow the use of&nbsp;<code>.htaccess<\/code>&nbsp;files for directory-specific configurations, and grant access to all users. Save the file and exit the text editor.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"step-8-install-mariadb\"><a href=\"https:\/\/akbv.dev\/blog\/set-up-development-environment-in-ubuntu-22-04-lamp-and-more#step-8-install-mariadb\"><\/a>Step 8: Install MariaDB<\/h2>\n\n\n\n<p>Next, we will install MariaDB, a fork of MySQL, which is a popular relational database management system. Run the following command to install MariaDB:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install mariadb-server mariadb-client\n<\/code><\/pre>\n\n\n\n<p>This command will install MariaDB and its client component. Once the installation is complete, you will be prompted to set the root password and perform some additional security configurations. Follow the on-screen instructions to secure your MariaDB installation.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"step-9-create-a-database-user\"><a href=\"https:\/\/akbv.dev\/blog\/set-up-development-environment-in-ubuntu-22-04-lamp-and-more#step-9-create-a-database-user\"><\/a>Step 9: Create a Database User<\/h2>\n\n\n\n<p>After installing MariaDB, it&#8217;s recommended to create a dedicated database user for your applications. To create a database user with root access, run the following commands:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo mysql -u root -p\n<\/code><\/pre>\n\n\n\n<p>Enter your root password when prompted. Once you are in the MariaDB console, execute the following commands to create a user and grant them full privileges:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE USER 'user'@'%' IDENTIFIED BY 'userpass';\nGRANT ALL ON *.* TO 'user'@'%' WITH GRANT OPTION;\n<\/code><\/pre>\n\n\n\n<p>Replace&nbsp;<code>'user'<\/code>&nbsp;and&nbsp;<code>'userpass'<\/code>&nbsp;with your desired username and password. These commands will create a user with the specified credentials and grant them all privileges on all databases. This user can be used to authenticate your applications with the database.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"step-10-add-repo-for-php\"><a href=\"https:\/\/akbv.dev\/blog\/set-up-development-environment-in-ubuntu-22-04-lamp-and-more#step-10-add-repo-for-php\"><\/a>Step 10: Add Repo for PHP<\/h2>\n\n\n\n<p>To install the latest version of PHP, we need to add a repository that provides the latest PHP packages. Run the following command to add the repository:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo add-apt-repository ppa:ondrej\/php\n<\/code><\/pre>\n\n\n\n<p>This command will add the repository maintained by Ond\u0159ej Sur\u00fd, which provides updated and custom versions of PHP for Ubuntu.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"step-11-install-php\"><a href=\"https:\/\/akbv.dev\/blog\/set-up-development-environment-in-ubuntu-22-04-lamp-and-more#step-11-install-php\"><\/a>Step 11: Install PHP<\/h2>\n\n\n\n<p>Now, let&#8217;s install PHP along with some commonly used modules. Run the following command to install PHP and the required modules:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install php8.1 php8.1-{fpm,mysql,intl,apcu,zip,dev,curl,cli,imagick,mbstring,gd,bcmath,redis,memcached,xml}\n<\/code><\/pre>\n\n\n\n<p>This command will install PHP 8.1 and its corresponding modules. If you prefer a different version of PHP, you can modify the version number accordingly.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"step-12-enable-php-fpm-for-apache2\"><a href=\"https:\/\/akbv.dev\/blog\/set-up-development-environment-in-ubuntu-22-04-lamp-and-more#step-12-enable-php-fpm-for-apache2\"><\/a>Step 12: Enable PHP-FPM for Apache2<\/h2>\n\n\n\n<p>To enable PHP-FPM (FastCGI Process Manager) for Apache2, run the following commands:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo a2enmod proxy_fcgi setenvif\nsudo a2enconf php8.1-fpm\n<\/code><\/pre>\n\n\n\n<p>These commands will enable the necessary modules and configurations to use PHP-FPM with Apache2. PHP-FPM improves the performance and scalability of PHP by utilizing separate worker processes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"step-13-install-xdebug\"><a href=\"https:\/\/akbv.dev\/blog\/set-up-development-environment-in-ubuntu-22-04-lamp-and-more#step-13-install-xdebug\"><\/a>Step 13: Install Xdebug<\/h2>\n\n\n\n<p>Xdebug is a powerful debugging and profiling tool for PHP. To install Xdebug, run the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install php8.1-xdebug\n<\/code><\/pre>\n\n\n\n<p>This command will install Xdebug for PHP 8.1. If you are using a different version of PHP, adjust the package name accordingly.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"step-14-configure-xdebug\"><a href=\"https:\/\/akbv.dev\/blog\/set-up-development-environment-in-ubuntu-22-04-lamp-and-more#step-14-configure-xdebug\"><\/a>Step 14: Configure Xdebug<\/h2>\n\n\n\n<p>To configure Xdebug, we need to create a configuration file. Run the following command to create the file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nano 80-tuning.ini\n<\/code><\/pre>\n\n\n\n<p>Paste the following code into the file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><em>; Maximum amount of memory a script may consume<\/em>\n<em>memory_limit<\/em> = 1024M\n\n<em>; Maximum execution time of each script, in seconds<\/em>\n<em>max_execution_time<\/em> = 60\n\n<em>; Maximum size of POST data that PHP will accept.<\/em>\n<em>post_max_size<\/em> = 1024M\n\n<em>; Maximum allowed size for uploaded files.<\/em>\n<em>upload_max_filesize<\/em> = 1024M\n\n<em>; Xdebug settings<\/em>\n<em>xdebug.mode<\/em>=debug\n<em>xdebug.start_with_request<\/em>=yes\n<em>xdebug.client_port<\/em>=9000\n\n<em>; Xdebug OLD settings<\/em>\n<em>xdebug.remote_enable<\/em>=1\n<em>xdebug.remote_port<\/em>=9000\n<em>xdebug.remote_autostart<\/em>=1\n<em>xdebug.remote_connect_back<\/em>=1\n<em>xdebug.log_level<\/em>=0\n<\/code><\/pre>\n\n\n\n<p>Save the file and exit the text editor.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"step-15-create-xdebug-configuration-script\"><a href=\"https:\/\/akbv.dev\/blog\/set-up-development-environment-in-ubuntu-22-04-lamp-and-more#step-15-create-xdebug-configuration-script\"><\/a>Step 15: Create Xdebug Configuration Script<\/h2>\n\n\n\n<p>To automate the process of creating symbolic links for the Xdebug configuration file, we will create a shell script. Run the following command to create the script file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nano create-symlink-80-tuning.sh\n<\/code><\/pre>\n\n\n\n<p>Paste the following code into the file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>#!\/bin\/bash<\/strong>\n\nif &#91; -f \"80-tuning.ini\" ]; then\n    echo \"Copying PHP tuning to \/etc\/php\/80-tuning.ini\"\n    cp 80-tuning.ini \/etc\/php\/80-tuning.ini\nelse\n    echo \"80-tuning.ini - File not found!\"\n    return 1\nfi\n\necho \"Creating symlinks to \/etc\/php\/80-tuning.ini\"\nln -s \/etc\/php\/80-tuning.ini \/etc\/php\/7.1\/fpm\/conf.d\/80-tuning.ini\nln -s \/etc\/php\/80-tuning.ini \/etc\/php\/7.1\/cli\/conf.d\/80-tuning.ini\nln -s \/etc\/php\/80-tuning.ini \/etc\/php\/7.3\/fpm\/conf.d\/80-tuning.ini\nln -s \/etc\/php\/80-tuning.ini \/etc\/php\/7.3\/cli\/conf.d\/80-tuning.ini\nln -s \/etc\/php\/80-tuning.ini \/etc\/php\/7.4\/fpm\/conf.d\/80-tuning.ini\nln -s \/etc\/php\/80-tuning.ini \/etc\/php\/7.4\/cli\/conf.d\/80-tuning.ini\nln -s \/etc\/php\/80-tuning.ini \/etc\/php\/8.0\/fpm\/conf.d\/80-tuning.ini\nln -s \/etc\/php\/80-tuning.ini \/etc\/php\/8.0\/cli\/conf.d\/80-tuning.ini\nln -s \/etc\/php\/80-tuning.ini \/etc\/php\/8.1\/fpm\/conf.d\/80-tuning.ini\nln -s \/etc\/php\/80-tuning.ini \/etc\/php\/8.1\/cli\/conf.d\/80-tuning.ini\nln -s \/etc\/php\/80-tuning.ini \/etc\/php\/8.2\/fpm\/conf.d\/80-tuning.ini\nln -s \/etc\/php\/80-tuning.ini \/etc\/php\/8.2\/cli\/conf.d\/80-tuning.ini\n\necho \"Restarting PHP-FPM...\"\nsystemctl restart php7.1-fpm\nsystemctl restart php7.3-fpm\nsystemctl restart php7.4-fpm\nsystemctl restart php8.0-fpm\nsystemctl restart php8.1-fpm\nsystemctl restart php8.2-fpm\n\necho \"Done!\"\n<\/code><\/pre>\n\n\n\n<p>Save the file and exit the text editor. Then, make the script executable by running the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo chmod +x create-symlink-80-tuning.sh\n<\/code><\/pre>\n\n\n\n<p>Finally, execute the script with the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo .\/create-symlink-80-tuning.sh\n<\/code><\/pre>\n\n\n\n<p>This script will copy the Xdebug configuration to the appropriate directory and create symbolic links for various PHP versions. It will also restart the corresponding PHP-FPM services.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"step-16-install-composer-optional\"><a href=\"https:\/\/akbv.dev\/blog\/set-up-development-environment-in-ubuntu-22-04-lamp-and-more#step-16-install-composer-optional\"><\/a>Step 16: Install Composer (Optional)<\/h2>\n\n\n\n<p>If you are working with PHP projects that require external dependencies, it&#8217;s highly recommended to install Composer. Composer is a dependency management tool for PHP that allows you to easily install and update packages. To install Composer, follow the official documentation at&nbsp;<a target=\"_blank\" rel=\"noreferrer noopener\" href=\"https:\/\/getcomposer.org\/download\/\">https:\/\/getcomposer.org\/download\/<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"step-17-configure-security-settings\"><a href=\"https:\/\/akbv.dev\/blog\/set-up-development-environment-in-ubuntu-22-04-lamp-and-more#step-17-configure-security-settings\"><\/a>Step 17: Configure Security Settings<\/h2>\n\n\n\n<p>To enhance the security of your development environment, we will configure the firewall and enable fail2ban. Run the following commands to install and configure these security tools:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install ufw\nsudo ufw allow ssh\nsudo ufw allow http\nsudo ufw allow https\nsudo ufw allow mysql\nsudo ufw enable\nsudo apt install fail2ban\nsudo nano \/etc\/fail2ban\/jail.local\n<\/code><\/pre>\n\n\n\n<p>In the&nbsp;<code>jail.local<\/code>&nbsp;file, add the following lines to enable fail2ban for MySQL authentication:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;mysqld-auth]\nenabled = true\n<\/code><\/pre>\n\n\n\n<p>Save the file and exit the text editor. These settings will enable the firewall, allow SSH, HTTP, HTTPS, and MySQL traffic, and enable fail2ban for MySQL authentication.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"step-18-configure-virtual-hosts-and-ssl\"><a href=\"https:\/\/akbv.dev\/blog\/set-up-development-environment-in-ubuntu-22-04-lamp-and-more#step-18-configure-virtual-hosts-and-ssl\"><\/a>Step 18: Configure Virtual Hosts and SSL<\/h2>\n\n\n\n<p>To organize and manage multiple websites on your development environment, it&#8217;s recommended to set up virtual hosts. Virtual hosts allow you to host multiple websites on a single Apache server by assigning different domain names or subdomains to each site. We will also configure SSL to secure the websites.<\/p>\n\n\n\n<p>To configure virtual hosts and SSL, follow these steps:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Create a new configuration file for your virtual host. Replace&nbsp;<code>websiteName<\/code>&nbsp;with your desired domain name or subdomain. Run the following command to create the configuration file:<code>sudo nano \/etc\/apache2\/sites-available\/websiteName.conf<\/code><\/li>\n\n\n\n<li>Paste the following configuration into the file:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>   &lt;VirtualHost *:8<strong>0<\/strong>&gt;\n       DocumentRoot \"\/var\/www\/example.com\"\n       ServerName example.com\n       &lt;Directory \"\/var\/www\/example.com\"&gt;\n           Options -Indexes +FollowSymLinks +MultiViews\n           Require all granted\n           AllowOverride All\n       &lt;\/Directory&gt;\n       &lt;FilesMatch \".+\\.ph(ar|p|tml)$\"&gt;\n           SetHandler \"proxy:unix:\/run\/php\/php8.1-fpm.sock|fcgi:\/\/localhost\"\n       &lt;\/FilesMatch&gt;\n   &lt;\/VirtualHost&gt;\n\n   &lt;VirtualHost *:44<strong>3<\/strong>&gt;\n       DocumentRoot \"\/var\/www\/example.com\"\n       ServerName example.com\n       SSLEngine on\n       SSLCertificateFile \/etc\/ssl\/certs\/apache-selfsigned.crt\n       SSLCertificateKeyFile \/etc\/ssl\/private\/apache-selfsigned.key\n\n       &lt;Directory \"\/var\/www\/example.com\"&gt;\n           Options -Indexes +FollowSymLinks +MultiViews\n           Require all granted\n           AllowOverride All\n       &lt;\/Directory&gt;\n       &lt;FilesMatch \".+\\.ph(ar|p|tml)$\"&gt;\n           SetHandler \"proxy:unix:\/run\/php\/php8.1-fpm.sock|fcgi:\/\/localhost\"\n       &lt;\/FilesMatch&gt;\n   &lt;\/VirtualHost&gt;\n<\/code><\/pre>\n\n\n\n<p>In this example, we assume that your website&#8217;s files are located at&nbsp;<code>\/var\/www\/example.com<\/code>. Replace this path with the actual path to your website&#8217;s root directory.<\/p>\n\n\n\n<p>The configuration includes both HTTP (<code>&lt;VirtualHost *:80&gt;<\/code>) and HTTPS (<code>&lt;VirtualHost *:443&gt;<\/code>) sections. For the SSL section, we assume you have already generated the SSL certificate and key files and placed them at&nbsp;<code>\/etc\/ssl\/certs\/apache-selfsigned.crt<\/code>&nbsp;and&nbsp;<code>\/etc\/ssl\/private\/apache-selfsigned.key<\/code>, respectively. Modify these paths if necessary.<\/p>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li>Save the file and exit the text editor.<\/li>\n\n\n\n<li>Enable the virtual host by creating a symbolic link:<code>sudo a2ensite websiteName.conf<\/code><\/li>\n\n\n\n<li>Restart Apache to apply the changes:<code>sudo systemctl restart apache2<\/code><\/li>\n<\/ol>\n\n\n\n<p>Now you can access your website by navigating to&nbsp;<code>http:\/\/skypebridge.localhost<\/code>&nbsp;for HTTP and&nbsp;<code>https:\/\/skypebridge.localhost<\/code>&nbsp;for HTTPS.<\/p>\n\n\n\n<p>Repeat these steps for each virtual host you want to set up, ensuring that each configuration file has a unique name and points to the appropriate document root directory and SSL certificate files.<\/p>\n\n\n\n<p>With this configuration, your websites will be accessible over both HTTP and HTTPS secured connections.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"step-19-install-and-configure-ssl-certificates\"><a href=\"https:\/\/akbv.dev\/blog\/set-up-development-environment-in-ubuntu-22-04-lamp-and-more#step-19-install-and-configure-ssl-certificates\"><\/a>Step 19: Install and Configure SSL Certificates<\/h2>\n\n\n\n<p>If you want to secure your websites with trusted SSL certificates, you can obtain them from a certificate authority (CA) or use Let&#8217;s Encrypt, a free and open certificate authority. Let&#8217;s Encrypt provides automated tools to obtain and renew SSL certificates. Follow the steps below to set up SSL certificates using Let&#8217;s Encrypt:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Install the Let&#8217;s Encrypt client, Certbot:<code>sudo apt install certbot python3-certbot-apache<\/code><\/li>\n\n\n\n<li>Obtain SSL certificates for your virtual hosts (replace&nbsp;<code>example.com<\/code>&nbsp;with your domain\/subdomain):<code>sudo certbot --apache -d example.com -d www.example.com<\/code><\/li>\n\n\n\n<li>Follow the prompts to provide the necessary information and agree to the Terms of Service.<\/li>\n\n\n\n<li>Certbot will automatically configure Apache with the SSL certificates and enable HTTPS for your virtual hosts.<\/li>\n\n\n\n<li>Certbot will also set up a monthly cron job to renew the SSL certificates automatically.<\/li>\n<\/ol>\n\n\n\n<p>With SSL certificates installed, your websites will be accessible over secure HTTPS connections.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"step-20-set-up-remote-mysql-access-optional\"><a href=\"https:\/\/akbv.dev\/blog\/set-up-development-environment-in-ubuntu-22-04-lamp-and-more#step-20-set-up-remote-mysql-access-optional\"><\/a>Step 20: Set Up Remote MySQL Access (Optional)<\/h2>\n\n\n\n<p>If you want to access your MySQL\/MariaDB database remotely, for example, from a database management tool on your local machine, you can configure your database server to allow remote access.<\/p>\n\n\n\n<p>Follow these steps to set up remote MySQL access:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Edit the MySQL\/MariaDB configuration file:<code>sudo nano \/etc\/mysql\/mariadb.conf.d\/50-server.cnf<\/code><\/li>\n\n\n\n<li>Locate the&nbsp;<code>bind-address<\/code>&nbsp;directive and comment it out or change its value to your server&#8217;s IP address:<code><em># bind-address = 127.0.0.1<\/em><\/code><\/li>\n\n\n\n<li>Save the file and exit the text editor.<\/li>\n\n\n\n<li>Restart MySQL\/MariaDB to apply the changes:<code>sudo systemctl restart mariadb<\/code><\/li>\n<\/ol>\n\n\n\n<p>Now you will be able to connect to your remote MySQL\/MariaDB server from your local machine using a database management tool like MySQL Workbench or phpMyAdmin.<\/p>\n\n\n\n<p>Please note that enabling remote access to your database server can pose security risks. Make sure to secure your database server by choosing strong passwords and restricting access to trusted IP addresses.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"step-21-enable-php-error-logging\"><a href=\"https:\/\/akbv.dev\/blog\/set-up-development-environment-in-ubuntu-22-04-lamp-and-more#step-21-enable-php-error-logging\"><\/a>Step 21: Enable PHP Error Logging<\/h2>\n\n\n\n<p>To debug PHP errors and warnings and troubleshoot issues in your application, it&#8217;s helpful to enable error logging in PHP.<\/p>\n\n\n\n<p>To enable PHP error logging, follow these steps:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Edit the PHP configuration file for the desired PHP version:<code>sudo nano \/etc\/php\/8.1\/fpm\/php.ini<\/code><\/li>\n\n\n\n<li>Find the&nbsp;<code>error_reporting<\/code>&nbsp;directive and set it to the desired error reporting level. For example, to log all errors, warnings, and notices, use the following value:<code>error_reporting = E_ALL<\/code><\/li>\n\n\n\n<li>Find the&nbsp;<code>display_errors<\/code>&nbsp;directive and set it to&nbsp;<code>Off<\/code>:<code>display_errors = Off<\/code><\/li>\n\n\n\n<li>Find the&nbsp;<code>log_errors<\/code>&nbsp;directive and set it to&nbsp;<code>On<\/code>:<code>log_errors = On<\/code><\/li>\n\n\n\n<li>Specify the path to the log file using the&nbsp;<code>error_log<\/code>&nbsp;directive. For example:<code>error_log = \/var\/log\/php\/php_error.log<\/code><\/li>\n\n\n\n<li>Save the file and exit the text editor.<\/li>\n\n\n\n<li>Restart PHP-FPM to apply the changes:<code>sudo systemctl restart php8.1-fpm<\/code><\/li>\n<\/ol>\n\n\n\n<p>PHP errors will now be logged to the specified file. You can then check the log file for any errors or warnings encountered during the execution of your PHP scripts.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"step-22-set-up-git-version-control\"><a href=\"https:\/\/akbv.dev\/blog\/set-up-development-environment-in-ubuntu-22-04-lamp-and-more#step-22-set-up-git-version-control\"><\/a>Step 22: Set Up Git Version Control<\/h2>\n\n\n\n<p>Git is a popular version control system that allows you to track changes in your codebase and collaborate with others. To set up Git, follow these steps:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Install Git:<code>sudo apt install git<\/code><\/li>\n\n\n\n<li>Configure your Git username and email:<code>git config --global user.name \"Your Name\" git config --global user.email \"youremail@example.com\"<\/code><\/li>\n\n\n\n<li>Generate an SSH key (if you don&#8217;t already have one) to securely authenticate with remote Git repositories:<code>ssh-keygen -t rsa -b 4096 -C \"youremail@example.com\"<\/code><\/li>\n\n\n\n<li>Add your SSH key to the SSH agent:<code>eval \"$(ssh-agent -s)\" ssh-add ~\/.ssh\/id_rsa<\/code><\/li>\n\n\n\n<li>Copy the SSH key to your clipboard:<code>cat ~\/.ssh\/id_rsa.pub<\/code><\/li>\n\n\n\n<li>Go to your Git hosting provider (e.g., GitHub, GitLab) and add the SSH key to your account settings.<\/li>\n<\/ol>\n\n\n\n<p>Now you can use Git to track changes in your projects, collaborate with others, and push your code to remote repositories.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"step-23-install-code-editors-and-development-tools\"><a href=\"https:\/\/akbv.dev\/blog\/set-up-development-environment-in-ubuntu-22-04-lamp-and-more#step-23-install-code-editors-and-development-tools\"><\/a>Step 23: Install Code Editors and Development Tools<\/h2>\n\n\n\n<p>Having a reliable code editor and development tools can greatly enhance your productivity and coding experience. Here are a few popular options:<\/p>\n\n\n\n<p>To learn how to install Visual Studio Code on Ubuntu 22.04 using the terminal, you can check out our detailed blog post&nbsp;<a target=\"_blank\" rel=\"noreferrer noopener\" href=\"http:\/\/akbv.dev\/blog\/vs-code-installation-by-terminal-ubuntu\">VS Code Installation Guide for Ubuntu via Terminal<\/a>. This guide provides step-by-step instructions for installing Visual Studio Code and getting started with the editor.<\/p>\n\n\n\n<p>Visual Studio Code offers a wide range of features and extensions that make it a powerful tool for coding in various programming languages. Whether you are a beginner or an experienced developer, having a solid code editor can significantly improve your development workflow.<\/p>\n\n\n\n<p>So head over to our blog post and follow the instructions to install Visual Studio Code on your Ubuntu 22.04 system.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"step-24-install-and-configure-redis\"><a href=\"https:\/\/akbv.dev\/blog\/set-up-development-environment-in-ubuntu-22-04-lamp-and-more#step-24-install-and-configure-redis\"><\/a>Step 24: Install and Configure Redis<\/h2>\n\n\n\n<p>Redis is an in-memory data structure store that can be used as a caching layer or as a messaging broker in your applications. To install Redis, follow these steps:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Install Redis:<code>sudo apt install redis-server<\/code><\/li>\n\n\n\n<li>Start the Redis service:<code>sudo systemctl start redis-server<\/code><\/li>\n\n\n\n<li>Enable Redis to start on boot:<code>sudo systemctl enable redis-server<\/code><\/li>\n\n\n\n<li>Configure Redis to allow remote connections (if needed). Open the Redis configuration file:<code>sudo nano \/etc\/redis\/redis.conf<\/code><\/li>\n\n\n\n<li>Find the&nbsp;<code>bind<\/code>&nbsp;directive and change its value to your server&#8217;s IP address or comment it out to allow connections from any IP:<code><em># bind 127.0.0.1<\/em><\/code><\/li>\n\n\n\n<li>Save the file and exit the text editor.<\/li>\n\n\n\n<li>Restart the Redis service to apply the changes:<code>sudo systemctl restart redis-server<\/code><\/li>\n<\/ol>\n\n\n\n<p>Redis is now installed and accessible on your system. You can use the Redis server for caching or as a messaging broker in your applications.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"conclusion\"><a href=\"https:\/\/akbv.dev\/blog\/set-up-development-environment-in-ubuntu-22-04-lamp-and-more#conclusion\"><\/a>Conclusion<\/h2>\n\n\n\n<p>Congratulations! You have successfully set up your development environment in Ubuntu 22.04 using the LAMP stack. You now have a powerful web server (Apache), a reliable database management system (MariaDB), the latest version of PHP with essential modules, debugging capabilities with Xdebug, security measures with Fail2ban and a firewall, and optional tools like Composer and Node.js\/npm. With this setup, you can start developing and testing your web applications with ease.<\/p>\n\n\n\n<p>Remember to always keep your system and applications up to date and follow security best practices to ensure a safe and secure development environment. Happy coding!<\/p>\n\n\n\n<p><em>Note: This guide assumes a basic understanding of Linux commands and concepts. If you encounter any issues during the setup process, refer to the official documentation of the respective tools or seek assistance from the developer community.<\/em><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Are you an aspiring developer looking to set up your development environment in Ubuntu 22.04?&hellip;<\/p>\n","protected":false},"author":1,"featured_media":65,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[7,13,17,18,9,11,14,4,5,6,3,16,10,12,15,8],"class_list":["post-20","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ubuntu-22-04","tag-apache2","tag-composer","tag-development","tag-environment","tag-fail2ban","tag-firewall","tag-git","tag-lamp","tag-mariadb","tag-mysql","tag-php","tag-redis","tag-ssl","tag-ufw","tag-visual-studio-code","tag-xdebug"],"_links":{"self":[{"href":"https:\/\/blog.akbv.dev\/index.php?rest_route=\/wp\/v2\/posts\/20"}],"collection":[{"href":"https:\/\/blog.akbv.dev\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.akbv.dev\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.akbv.dev\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.akbv.dev\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=20"}],"version-history":[{"count":3,"href":"https:\/\/blog.akbv.dev\/index.php?rest_route=\/wp\/v2\/posts\/20\/revisions"}],"predecessor-version":[{"id":67,"href":"https:\/\/blog.akbv.dev\/index.php?rest_route=\/wp\/v2\/posts\/20\/revisions\/67"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.akbv.dev\/index.php?rest_route=\/wp\/v2\/media\/65"}],"wp:attachment":[{"href":"https:\/\/blog.akbv.dev\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=20"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.akbv.dev\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=20"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.akbv.dev\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=20"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}