Why Ubuntu is the Best Choice for Development
When it comes to setting up a stable, secure, and developer-friendly environment, I find that Ubuntu is my best choice. While distributions like Arch Linux or CachyOS offer high customization, they often require a lot of configuration and troubleshooting. Ubuntu, on the other hand, offers the perfect balance of ease-of-use and stability.
Whether you’re just getting started with web development or you’re setting up a serious production environment, Ubuntu’s straightforward approach ensures that you spend more time coding and less time debugging system configuration issues. In this guide, we’ll walk you through setting up a complete PHP development environment on Ubuntu 24.10, including:
- Installing Apache to serve your web pages.
- Installing PHP for dynamic content.
- Configuring your Apache server to grant read/write access for your development files.
Step 1: Install Apache Web Server
Apache is one of the most popular web servers in the world and is easy to set up on Ubuntu.
- Update Your Package List
Start by ensuring your system is up-to-date:sudo apt update
- Install Apache
Install the Apache web server with the following command:sudo apt install apache2
- Start and Enable Apache
Once installed, you can start the Apache service and ensure it runs on boot:sudo systemctl start apache2
sudo systemctl enable apache2 - Verify Apache Installation
To confirm that Apache is running, open your browser and navigate to:http://localhost
You should see the Apache2 Ubuntu default page, confirming that the server is working.
Step 2: Install PHP and Required Modules
PHP is essential for dynamic web content, and we’ll install the most common PHP modules for web development.
- Install PHP and Common Modules
Run the following command to install PHP and a set of useful PHP extensions:sudo apt install php libapache2-mod-php php-cli
- Restart Apache
After installing PHP, restart Apache so it loads the PHP module:sudo systemctl restart apache2
- Verify PHP Installation
To ensure that PHP is working correctly with Apache, create a PHP info file:sudo nano /var/www/html/info.php
Inside the file, add the following:
<?php
phpinfo();
?>
Save and exit the editor (press CTRL + X, then Y, then Enter).
Now, visit http://localhost/info.php in your browser. You should see the PHP information page, indicating PHP is working correctly.
Step 3: Setting Up Writable Directories for Your Projects
For development, you’ll want to store your projects in /var/www/html
but still have the ability to write files (such as logs or temporary data). Let’s set up the proper permissions so that you can edit files and directories within /var/www/html
, while still maintaining a secure server setup.
- Create Your Project Directory
First, create a directory inside/var/www/html
for your project. For example, let’s create a directory namedmy-php-project
:sudo mkdir /var/www/html/my-php-project
- Change Ownership of the Project Directory
Next, change the ownership of your project directory to your user. This allows you to edit files inside the directory:sudo chown -R $USER:$USER /var/www/html/my-php-project
- Set Writable Permissions for Your Project
Set the directory’s permissions so that your user can write to it while still giving Apache the ability to serve the files:sudo chmod -R 775 /var/www/html/my-php-project
This ensures:- You (the owner) have read, write, and execute permissions.
- The
www-data
group (Apache) has read and execute permissions. - Others have read-only access.
- Verify Permissions
You can check that the directory has the correct permissions by listing the files:ls -l /var/www/html/my-php-project
The output should show something like:drwxrwxr-x 2 yourusername www-data 4096 Dec 25 12:34 my-php-project
Conclusion
Congratulations! We’ve successfully set up a PHP development environment on Ubuntu 24.10. We now have:
- A fully functional Apache web server.
- PHP installed and running.
- A project directory with read/write permissions, so we can develop and test your PHP projects with ease.
Ubuntu provides a smooth, efficient, and reliable development environment that can help us focus on what matters most—writing great code. Whether I’m working on simple PHP scripts or complex web applications, Ubuntu is once again my operating system of choice!