Welcome to this guide on setting up a web development environment on Ubuntu 20.x! Whether you're building a website, a web app, or just experimenting, you'll need a solid server setup. We'll install and configure the following tools: Apache Server, MySQL Server, PHP, phpMyAdmin, Composer, and Git. Let’s make it simple and fun—here we go!
Here’s a quick overview of the tools we’ll set up:
| # | Tool | Purpose |
|---|---|---|
| 1 | Apache Server | Serves your web pages |
| 2 | MySQL Server | Manages your databases |
| 3 | PHP | Powers dynamic web content |
| 4 | phpMyAdmin | A web interface for MySQL |
| 5 | Composer | Manages PHP dependencies |
| 6 | Git | Tracks your code changes |
Apache is a popular web server that delivers your website to visitors. Let’s get it running.
-
Install Apache:
sudo apt-get install apache2
-
Test the Configuration: Check for syntax errors:
sudo apache2ctl configtest
Look for "Syntax OK" in the output.
-
Check the Config File (optional): Open the main configuration file to tweak settings if needed:
sudo nano /etc/apache2/apache2.conf
-
Restart Apache: Apply any changes:
sudo systemctl restart apache2
-
Set Permissions: Make the web directory writable:
sudo chmod 777 -R /var/www/html
Note:
777gives full permissions—use cautiously in production! -
Uninstall (if needed):
sudo apt-get remove --purge apache2
Test it by visiting http://localhost in your browser—you should see Apache’s default page!
MySQL is a database system for storing your app’s data. Let’s set it up.
-
Install MySQL:
sudo apt-get install mysql-server
-
Access MySQL: Log in as root:
sudo mysql
-
Set Root Password: Secure the root user with a password (e.g.,
root):ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
Exit with
exit;. -
Restart MySQL:
sudo systemctl restart mysql
-
Uninstall (if needed):
sudo apt-get remove --purge mysql-server
Now MySQL is ready to store your data!
PHP lets you create dynamic web pages. We’ll integrate it with Apache and MySQL.
-
Install PHP:
sudo apt-get install php libapache2-mod-php php-mysql
-
Configure Apache for PHP: Edit the directory index to prioritize
index.php:sudo nano /etc/apache2/mods-enabled/dir.conf
Change the line to:
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htmSave and exit.
-
Switch PHP Version (e.g., 5.4 to 7.4):
- Disable old version, enable new one:
sudo a2dismod php5.4 && sudo a2enmod php7.4 - Update CLI version:
sudo update-alternatives --set php /usr/bin/php7.4 sudo update-alternatives --set phar /usr/bin/phar7.4 sudo update-alternatives --set phar.phar /usr/bin/phar.phar7.4
- Disable old version, enable new one:
-
Uninstall (if needed):
sudo apt-get remove --purge php
Restart Apache (sudo systemctl restart apache2) and test PHP by creating /var/www/html/info.php with <?php phpinfo(); ?>—visit http://localhost/info.php.
phpMyAdmin provides a web interface to manage MySQL databases.
-
Install phpMyAdmin:
sudo apt-get install phpmyadmin
Follow the prompts—select Apache when asked.
-
Link to Apache: Add phpMyAdmin to Apache’s config:
sudo nano /etc/apache2/apache2.conf
Add this line at the bottom:
Include /etc/phpmyadmin/apache.confSave and exit.
-
Restart Apache:
sudo systemctl restart apache2
-
Uninstall (if needed):
sudo apt-get remove --purge phpmyadmin
Visit http://localhost/phpmyadmin and log in with your MySQL root credentials.
Composer is a dependency manager for PHP projects.
-
Install Composer:
sudo apt-get install composer
-
Verify Installation:
composer --version
-
Uninstall (if needed):
sudo apt-get remove --purge composer
Now you can manage PHP packages easily!
Git helps you version-control your code.
-
Install Git:
sudo apt-get install git
-
Verify Installation:
git --version
-
Uninstall (if needed):
sudo apt-get remove --purge git
Set up your Git identity with:
git config --global user.name "Your Name"
git config --global user.email "you@example.com"- Update Packages: Always start with
sudo apt-get update && sudo apt-get upgradeto ensure you’re installing the latest versions. - Security: In production, tighten permissions (e.g.,
chmod 755) and use strong passwords. - Testing: Create a simple PHP file or clone a project into
/var/www/htmlto confirm everything works.
You’ve just set up a fully functional web server on Ubuntu 20.x! With Apache serving pages, MySQL storing data, PHP powering your apps, phpMyAdmin managing databases, Composer handling dependencies, and Git tracking changes, you’re ready to build amazing projects. Have fun coding!
