Development Ubuntu 16.04 Server

How to Configure a New Ubuntu 16.04 Apache Server

Here are a set of commands to set up a fresh Ubuntu 16.04 Apache server with the option to install WordPress and the headless browsers PhantomJS and CasperJS. You’ll need FTP and SSH access to run the commands.

You can access your servers FTP using a program such as FileZilla and your servers SSH using a program such as PuTTY (you’ll need your servers login details to use these).

To update your server, set up Ubuntu’s uncomplicated firewall, PHP, MySQL, and PHPMyAdmin use the below command/s via SSH.

sudo apt-get update && sudo apt-get install apache2 && sudo systemctl restart apache2 && sudo ufw allow in “Apache Full” && ufw allow 21 && ufw allow 22 && ufw allow 3306 && ufw allow 80 && ufw allow 8080 && ufw enable && sudo apt-get install mysql-server && sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql && sudo apt-get install php7.0-curl && sudo apt-get install php7.0-gd && sudo apt-get install phpmyadmin && sudo phpenmod mcrypt && sudo phpenmod mbstring && sudo systemctl restart apache2

On the PHPMyAdmin config screen, press ‘space’ to select Apache2 and then select Yes.

Make the following file edits:

  • In /etc/apache2/apache2.conf edit the “AllowOverride” setting to “AllowOverride All” under “< Directory /var/www/ >”
  • In /etc/apache2/apache2.conf add line “ServerName ” followed by your servers IP/domain name
  • In /etc/apache2/mods-available/dir.conf move “index.php” to the beginning of the list
  • In /etc/apache2/conf-available/phpmyadmin.conf add “AllowOverride All” under “DirectoryIndex index.php”

Finally run:

sudo apt-get update && sudo systemctl restart apache2

Installing WordPress

If you’d like to install WordPress, download the zipped file from the WordPress website, unzip and upload the files/folders from the WordPress folder to var/html/www/ via FTP then run:

chown -R www-data:www-data /var/www/html/wp-admin && chown -R www-data:www-data /var/www/html/wp-content && chown -R www-data:www-data /var/www/html/wp-includes

Once installed if you find yourself having any issues uploading files due to their file size then you can look to add a php.ini file to you root WordPress directory and specific the max file size within this.

Installing PhantomJS and CasperJS headless browsers

If you’d like to install PhantomJS and CasperJS headless browsers then run the below command. CasperJS runs on top on PhantomJS, it’s worth noting that not all versions seem to be stable with each other but these versions seem to work well together.

cd /usr/local/share && wget && tar xjf phantomjs-2.1.1-linux-x86_64.tar.bz2 && ln -s /usr/local/share/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/share/phantomjs && ln -s /usr/local/share/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin/phantomjs && ln -s /usr/local/share/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/bin/phantomjs && which phantomjs && cd .. && cd .. && cd .. && phantomjs –version && cd /usr/local/bin && wget && tar -xzf casperjs-casperjs-1.1.4-1-14-g0b06a37.tar.gz && ln -s /usr/local/bin/casperjs-casperjs-0b06a37/bin/casperjs /usr/local/bin/casperjs && ln -s /usr/local/bin/casperjs-casperjs-0b06a37/bin/casperjs /usr/bin/casperjs && which casperjs && cd .. && cd .. && cd .. && casperjs –version

If you experience any issues running the longer commands then you could split these up at && to run these as shorter commands and identify where any issue is.

Useful Resources:

I hope this is helpful.

By Andy Corby

Hi, I'm Andy and I am a Digital Marketer and Full Stack Web Developer, with a BA (Honours) Business & Finance Degree (2:1) and 10+ Years Experience in Marketing and Development.

Leave a Reply

Your email address will not be published. Required fields are marked *

2 × 1 =