Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Setup digital ocean apache web server php mysql

Login

root@ubuntu-512mb-nyc3-01:~# ssh root@xxx.xxx.xxx.xxx

Update package manager

root@ubuntu-512mb-nyc3-01:~# apt-get update

root@ubuntu-512mb-nyc3-01:~# apt-get upgrade

Install Apache Web Server

root@ubuntu-512mb-nyc3-01:~# apt-get install apache2

Install latest PHP version (v7.2)

root@ubuntu-512mb-nyc3-01:~# apt-add-repository ppa:ondrej/php

Install MySQL Server

root@ubuntu-512mb-nyc3-01:~# apt-get install mysql-server php7.2-mysql

Initialize MySQL Server

root@ubuntu-512mb-nyc3-01:~# mysqld --initialize

Verify MySQL is installed

root@ubuntu-512mb-nyc3-01:~# mysql --version

Install PHP extensions (Optional)

root@ubuntu-512mb-nyc3-01:~# apt-cache pkgnames | grep php7.2

root@ubuntu-512mb-nyc3-01:~# apt-get install -y php7.2 libapache2-mod-php7.2 php7.2-cli php7.2-common php7.2-mbstring php7.2-gd php7.2-intl php7.2-xml php7.2-mysql php7.2-zip

* mcrypt extension missing in php7.2

Test web server is running

root@ubuntu-512mb-nyc3-01:~# cd /var/www/html/

root@ubuntu-512mb-nyc3-01:/var/www/html# touch info.php

root@ubuntu-512mb-nyc3-01:/var/www/html# echo "<?php phpinfo(); ?>" > info.php

Visit: http://165.227.227.66/info.php

root@ubuntu-512mb-nyc3-01:/var/www/html# rm info.php

Install phpmyadmin

root@ubuntu-512mb-nyc3-01:/var/www/html# apt-get install phpmyadmin

root@ubuntu-512mb-nyc3-01:/var/www/html# a2enmod rewrite

root@ubuntu-512mb-nyc3-01:/var/www/html# service apache2 restart

* phpmyadmin default user is phpmyadmin, not root.

Password is what you set during phpmyadmin installation.

Confirm phpmyadmin credentials

root@ubuntu-512mb-nyc3-01:/var/www/html# cat /etc/phpmyadmin/config-db.php

Browser access

Visit: http://165.227.227.66/phpmyadmin

Terminal access

root@ubuntu-512mb-nyc3-01:/var/www/html# mysql -u root -p

# Create new user and database.

SELECT DISTINCT user, host, authentication_string, password_expired FROM mysql.user;

CREATE DATABASE augur_tours;

GRANT ALL ON augur_tours.* TO augur@localhost IDENTIFIED BY 'T@urs.Augur';

FLUSH PRIVILEGES;

Troubleshooting...

Find current user

root@ubuntu-512mb-nyc3-01:/var/www/html# id

Add your user, usually root to www-data group

root@ubuntu-512mb-nyc3-01:/var/www/html# gpasswd -a "$USER" www-data

Confirm changes

root@ubuntu-512mb-nyc3-01:/var/www/html# id root

root@ubuntu-512mb-nyc3-01:/var/www/html# groups root

Update existing file ownership

root@ubuntu-512mb-nyc3-01:/var/www/html# chown -R "$USER":www-data /var/www

root@ubuntu-512mb-nyc3-01:/var/www/html# chown -R www-data:www-data /var/www

Update file permissions

root@ubuntu-512mb-nyc3-01:/var/www/html# chmod 764 -R /var/www

  • User (root): 7 rwx 111
  • Group (www-data): 6 rwx 110
  • Other: 4 rwx 100

Install Composer - PHP Package Manager

root@ubuntu-512mb-nyc3-01:/var/www/html# php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

root@ubuntu-512mb-nyc3-01:/var/www/html# php -r "if (hash_file('sha384', 'composer-setup.php') === '48e3236262b34d30969dca3c37281b3b4bbe3221bda826ac6a9a62d6444cdb0dcd0615698a5cbe587c3f0fe57a54d8f5') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

root@ubuntu-512mb-nyc3-01:/var/www/html# php composer-setup.php

root@ubuntu-512mb-nyc3-01:/var/www/html# php -r "unlink('composer-setup.php');"

Test composer

root@ubuntu-512mb-nyc3-01:/var/www/html# php composer.phar --version

Setup composer globally

root@ubuntu-512mb-nyc3-01:/var/www/html# mv composer.phar /usr/local/bin/composer

root@ubuntu-512mb-nyc3-01:/var/www/html# composer --version

Verify you have git installed

root@ubuntu-512mb-nyc3-01:/var/www/html# git --version

Setup virtual host

vim /etc/apache2/sites-available/example.com.conf

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    ServerAdmin admin@example.com

    DocumentRoot "/var/www/html/example"
    <Directory "/var/www/html/example">
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/example.error.log
    CustomLog ${APACHE_LOG_DIR}/example.access.log combined
</VirtualHost>

Activate new configuration

user@server:/# service apache2 reload

Enable site

user@server:/# a2ensite /etc/apache2/sites-available/example.com.conf

To activate the new configuration, you need to run:

user@server:/# systemctl reload apache2

Restart apache web server

user@server:/# service apache2 restart

List enabled sites

user@server:/# apache2ctl -S

Test domain

user@server:/# curl -I example.com

Check logs

user@server:/# cat /var/log/apache2/example.error.log

Rollback

user@server:/# a2dissite example.com.conf user@server:/# rm /etc/apache2/sites-available/example.com.conf

Useful

user@server:/# service apache2 start user@server:/# service apache2 stop user@server:/# service apache2 restart

Site Address

http://127.0.0.1/example => http://example.com

* WordPress

Update project url

http://xxx.xxx.xxx.xxx/example/wp-admin/options-general.php

From: http://xxx.xxx.xxx.xxx/example

To: http://example.com

SSH

https://letsencrypt.org

user@server:/# apt-get install letsencrypt

Documetation

user@server:/# apt-get update
user@server:/# apt-get install software-properties-common
user@server:/# add-apt-repository universe
user@server:/# add-apt-repository ppa:certbot/certbot
user@server:/# apt-get update
user@server:/# apt-get install certbot python-certbot-apache

user@server:/# letsencrypt certonly -a webroot --webroot-path=/var/www/html/example -d example.com -d www.example.com

user@server:/# cd /etc/apache2/sites-available

https://stackoverflow.com/a/26717793/2732184

user@server:/etc/apache2/sites-available# vim example.com.conf

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    ServerAdmin admin@example.com

    DocumentRoot "/var/www/html/example"
    <Directory "/var/www/html/example">
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Require all granted
    </Directory>

    # Don't serve http. Redirect all traffic to https
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

    ErrorLog ${APACHE_LOG_DIR}/example.error.log
    CustomLog ${APACHE_LOG_DIR}/example.access.log combined
</VirtualHost>
<VirtualHost *:443>
    ServerName example.com
    ServerAlias www.example.com
    ServerAdmin admin@example.com

    DocumentRoot "/var/www/html/example"
    <Directory "/var/www/html/example">
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Require all granted
    </Directory>

    SSLEngine on
    SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem

    ErrorLog ${APACHE_LOG_DIR}/example.error.log
    CustomLog ${APACHE_LOG_DIR}/example.access.log combined
</VirtualHost>
/etc/apache2/sites-available# a2enmod rewrite
/etc/apache2/sites-available# a2ensite default-ssl
/etc/apache2/sites-available# a2enmod ssl
/etc/apache2/sites-available# systemctl reload apache2

* Wordpress

http://example.com/wp-admin/options-general.php

Change to https

From: http://example.com

To: https://example.com

RainLoop mail server

https://www.youtube.com/watch?v=pBmHkgnsP6Q

https://www.howtoforge.com/how-to-install-rainloop-webmail-on-ubuntu-1804/

https://www.linuxbabe.com/mail-server/install-rainloop-webmail-ubuntu-16-04

# apt-get install -y php7.2-curl

# cd /var/www
var/www# mkdir rainloop
var/www# cd rainloop
var/www/rainloop# curl -s http://repository.rainloop.net/installer.php | php
var/www/rainloop# chown -R www-data:www-data /var/www/rainloop
var/www/rainloop# chmod 755 -R /var/www/rainloop
var/www/rainloop# letsencrypt certonly -a webroot --webroot-path=/var/www/rainloop -d mail.example.com -d www.mail.example.com

var/www/rainloop# vim /etc/apache2/sites-available/rainloop.conf

<VirtualHost *:80>
    ServerName mail.example.com
    ServerAlias www.mail.example.com
    ServerAdmin admin@example.com

    DocumentRoot "/var/www/rainloop"

    <Directory "/var/www/rainloop">
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Require all granted
    </Directory>

    <Directory  "/var/www/rainloop/data">
        Order allow,deny
        Deny from all
    </Directory>

    # # Don't serve http. Redirect all traffic to https
    # RewriteEngine On
    # RewriteCond %{HTTPS} off
    # RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

    ErrorLog ${APACHE_LOG_DIR}/rainloop.error.log
    CustomLog ${APACHE_LOG_DIR}/rainloop.access.log combined
</VirtualHost>

<VirtualHost *:443>
    ServerName mail.example.com
    ServerAlias www.mail.example.com
    ServerAdmin admin@example.com

    DocumentRoot "/var/www/rainloop"

    <Directory "/var/www/rainloop">
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Require all granted
    </Directory>

    <Directory  "/var/www/rainloop/data">
        Order allow,deny
        Deny from all
    </Directory>

    SSLEngine on
    SSLCertificateFile /etc/letsencrypt/live/mail.example.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/mail.example.com/privkey.pem

    ErrorLog ${APACHE_LOG_DIR}/rainloop.error.log
    CustomLog ${APACHE_LOG_DIR}/rainloop.access.log combined
</VirtualHost>
var/www/rainloop# 

Enable site

# user@server:/# a2ensite /etc/apache2/sites-available/rainloop.conf

Restart apache web server

# user@server:/# service apache2 restart

Confirm enabled sites

# apache2ctl -S

Test domain

# user@server:/# curl -I mail.example.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.