Skip to content

Instantly share code, notes, and snippets.

@shankar-bavan
Last active June 8, 2024 08:42
Show Gist options
  • Save shankar-bavan/b6c825aa3353845c547d7878ce66fd98 to your computer and use it in GitHub Desktop.
Save shankar-bavan/b6c825aa3353845c547d7878ce66fd98 to your computer and use it in GitHub Desktop.
Ubuntu server setup guide

Install Apache

sudo apt-get update -y
sudo apt-get upgrade -y

Install and start Apache.

sudo apt-get install apache2 -y
sudo systemctl enable apache2.service
sudo systemctl restart apache2.service

Verify that Apache was installed without errors by accessing it from your local browser. Enter hostname -I to obtain your IP address for the server and navigate to http://SERVER_IP/. You will see the default Apache2 page.

Install MySQL

Install the MariaDB database server (a fork of MySQL).

sudo apt-get install mysql-server -y

Then, run the mysql_secure_installation.

sudo mysql_secure_installation

You will be asked to set a password, followed by some other questions. Enter a secure password and then press ENTER to select the defaults.

Install PHP

sudo apt install php libapache2-mod-php

Then install common PHP extensions such as gd, mysql and so forth.

sudo apt-get install php-{bcmath,bz2,intl,gd,mbstring,mysql,zip,fpm} -y
sudo apt-get install php-xml
sudo systemctl enable mysql.service

Finally, restart Apache to allow PHP to run.

sudo systemctl restart apache2.service

Enable mod_rewrite

sudo a2enmod rewrite
sudo systemctl restart apache2

Install and Use Composer on Ubuntu

sudo apt update
sudo apt install curl php-cli php-mbstring git unzip

Make sure you’re in your home directory, then retrieve the installer using curl:

cd ~
curl -sS https://getcomposer.org/installer -o composer-setup.php

Next, verify that the installer matches the SHA-384 hash for the latest installer found on the Composer Public Keys / Signatures page. Copy the hash from that page and store it as a shell variable: https://composer.github.io/pubkeys.html

HASH=544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061

Now execute the following PHP script to verify that the installation script is safe to run:

php -r "if (hash_file('SHA384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

You’ll see the following output. Installer verified

To install composer globally, use the following command which will download and install Composer as a system-wide command named composer, under /usr/local/bin:

sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer

To test your installation, run:

composer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment