DevOps
How To Install Apache, MySQL, PHP & Composer On Ubuntu
Advantage AI Engineering · · 10 min read

Install the classic LAMP-style stack on Ubuntu: Apache as the web server, MySQL for data, PHP with common extensions, and Composer for dependency management.
This guide walks through Apache, MySQL, PHP, and Composer on Ubuntu using apt. Run commands step by step; the first time you use sudo in a session you may be asked for your password so only privileged users can change system packages.
Step 1: Installing Apache
Refresh the package index, then install Apache:
sudo apt updatesudo apt install apache2After installation, open http://localhost (or your server IP) in a browser. You should see the Apache default page—your web server is running and reachable (ensure your firewall allows HTTP/HTTPS if you access it remotely).
Step 2: Installing MySQL
sudo apt install mysql-server
sudo mysqlIn the MySQL prompt, set a root password and authentication (replace the example password with a long, unique password you store safely):
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';exitThen you can log in from the shell with: mysql -u root -p (enter the password when prompted). Newer MySQL versions may use different default authentication plugins—if the ALTER line fails, check the MySQL 8.x docs for your exact release.
Step 3: Installing PHP
Apache serves your site, MySQL stores data, and PHP generates dynamic content. You need PHP, the MySQL driver for PHP, and Apache’s PHP module so .php files are executed by the web server. Core PHP packages are pulled in as dependencies.
sudo apt install php libapache2-mod-php php-mysqlWhen installation finishes, confirm the PHP version:
php -vYou can install many useful extensions in one go. Adjust the version (8.3 here) to match your installed PHP:
sudo apt-get install -y php8.3-cli php8.3-common php8.3-mysql php8.3-zip php8.3-gd php8.3-mbstring php8.3-curl php8.3-xml php8.3-bcmathStep 4: Setting up Composer
Composer is PHP’s dependency manager: you declare the libraries your project needs, and it installs and updates them. Download the official installer, verify it, and install the composer binary to /usr/local/bin:
curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php
HASH=$(curl -sS https://composer.github.io/installer.sig)
echo $HASH
php -r "if (hash_file('SHA384', '/tmp/composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('/tmp/composer-setup.php'); } echo PHP_EOL;"
sudo php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composerTest the installation:
composerYou should see Composer’s version and command list. For the latest verification steps, see getcomposer.org if installer signatures change.