Step by Step - Creating Web Server - Digital Ocean Ubuntu - LAMP
Installing web server with apache, php and mysql step by step in Digital Ocean Environment.
CREATING WEBSERVER IN DIGITAL OCEAN
(APACHE - PHP - MYSQL - phpmyadmin)
*** Log in to your digital ocean account and select "+New Project" from left panel.
https://cloud.digitalocean.com/projects/new
Step 1 - Enter project details and click "Create Project".
Step 2 - Select "Get Started with a Droplet" from project screen.
Step 3 - It is really easy to try one click deployments from Digital Ocean. Go to "Marketplace" and Select "LAMP on Ubuntu 20.04"
Step 4 - Choose the plan for the project. Regular and cheapest options were selected for the project.
Step - 5 Select "Add block storage" if needed and chose datacenter region. Datacenter region selection is important for the target audience of the website.
Step 6 - Create a root password for the server and select additional options such as backups, IPv6 etc.
Step 7 - Last step. Choose a hostname and select the project for the droplet. Then click "Create Droplet"
Step 8 - The droplet will be ready in less than a minute. You may now see the IP address of the droplet and select options from right site.
Software included with the LAMP:
Package
|
Version | License |
Apache
|
2.4.41 | Apache 2 |
MySQL server
|
8.0.30 | GPL 2 with modifications |
PHP
|
8.1.8 | PHP v3.01 |
Fail2ban
|
0.11.1 | GPL 2 with modifications |
Postfix
|
3.4.10 | IBM Public |
Certbot
|
0.39.0 | Apache 2 |
In addition to the package installation, the 1-Click also:
- Enables the UFW firewall to allow only SSH (port
22
, rate limited), HTTP (port80
), and HTTPS (port443
) access. - Sets the MySQL root password and runs
mysql_secure_installation
. - Sets up the
debian-sys-maint
user in MySQL so the system’s init scripts for MySQL will work without requiring the MySQLroot
user password.
After you create a LAMP One-Click Droplet:
- You can view the LAMP instance immediately by visiting the Droplet’s IP address in your browser.
- You can log into the Droplet as root using either the password you set when you created the Droplet or with an SSH key, if you added one during creation.
- The MySQL root password is in
/root/.digitalocean_password
. - The web root is
/var/www/html
. - You can get information about the PHP installation by logging into the Droplet and running
php -i
.
Step 9 - After all access and launch the console. Welcome page provides some information about the droplet created.
Step 10 - Write "sudo apt update" and hit enter to console. Wait till installation.
Step 11 - Write "sudo apt install apache2" and hit enter to console. Wait till installation.
Step 12 - After completed. You may enter your droplet IP address to a browser and the default welcome page will appear. It means Apache 2 is ready.
Step 13 - To install mysql write "sudo apt install mysql-server" and hit enter. Wait for the installation.
Step 14 - When the installation is complete, run a simple security script that comes pre-installed with MySQL which will remove some dangerous defaults and lock down access to your database system. Start the interactive script by running: "sudo mysql_secure_installation".
After validating the password you may now write "sudo mysql" to use mysql commands. You may exit from mysql command lline by writing "exit" command.
Step 15 - Run the "sudo apt install php libapache2-mod-php php-mysql" command to install php and packacges.
PHP is the component of your setup that will process code to display dynamic content. It can run scripts, connect to your MySQL databases to get information, and hand the processed content over to your web server so that it can display the results to your visitors.
Step 16 - To change the directory index of the apache write "sudo nano /etc/apache2/mods-enabled/dir.conf" and hit enter. From the index move "index.php" to first order in order to use php as the first option.
When you are finished, save and close the file by pressing CTRL+X
. Confirm the save by typing Y
and then hit ENTER
to verify the file save location.
After this, restart the Apache web server in order for your changes to be recognized. You can do that by using "sudo systemctl restart apache2" command.
Step 17 - Apache on Ubuntu has one server block enabled by default that is configured to serve documents from the /var/www/html
directory. While this works well for a single site, it can become unwieldy if you are hosting multiple sites. Instead of modifying /var/www/html
, let’s create a directory structure within /var/www
for your_domain site, leaving /var/www/html
in place as the default directory to be served if a client request doesn’t match any other sites. After that you may enter following commands:
**** sudo chown -R $USER:$USER /var/www/your_domain
**** sudo chmod -R 755 /var/www/your_domain
**** nano /var/www/your_domain/index.html
Step 18 - After running last command. You will be able to edit you "index.html". When you are finished, save and close the file by pressing CTRL+X
. Confirm the save by typing Y
and then hit ENTER
to verify the file save location.
Step 19 - Enter and hit "sudo nano /etc/apache2/sites-available/your_domain.conf" command to edit the conf file for the virtual directory. When you are finished, save and close the file by pressing CTRL+X
. Confirm the save by typing Y
and then hit ENTER
to verify the file save location.
Step 20 - Enter the following commands after editing the virtual host:
**** sudo a2ensite your_domain.conf (to enable a2ensite tool)
**** sudo a2dissite 000-default.conf (to disable the 000-default.conf)
**** sudo apache2ctl configtest (to check the configuration errors.)
**** sudo systemctl restart apache2 (to implement the changes.)
Step 21 - Apache should now be serving your domain name. You can test this by navigating to http://your_domain
,
With that, your virtual host is fully set up. Before making any more changes or deploying an application, though, it would be helpful to proactively test out your PHP configuration in case there are any issues that should be addressed.
Step 22 - Enter and hit "sudo nano /var/www/your_domain/info.php" command to create info.php file in order to get information about current php installation. After saving and visiting " http://your_domain/info.php" you may now see the this page.
You may remove the page by entering "sudo rm /var/www/your_domain/info.php" command.
Step 23 - To install all files to your system anter the command "sudo apt install phpmyadmin php-mbstring php-gettext". When the prompt appears, “apache2” is highlighted, but not selected. To select Apache, hit SPACE
, TAB
, then ENTER
.
!! If you do not hit SPACE
to select Apache, the installer will not move the necessary files during installation.
The installation process adds the phpMyAdmin Apache configuration file into the /etc/apache2/conf-enabled/
directory, where it is read automatically. The only thing you need to do is explicitly enable the mbstring
PHP extension, which you can do by typing:
**** sudo phpenmod mbstring (to enable mbstring extension)
**** sudo systemctl restart apache2 (to push the changes)
Step 24 - To adjust user authentication and priviliges complete the following lines:
**** sudo mysql (to open MySQL prompt)
**** SELECT user,authentication_string,plugin,host FROM mysql.user; (check current mysql methods)
**** ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'; (configure root user)
**** FLUSH PRIVILEGES; (to reload the tables and push the changes.)
**** SELECT user,authentication_string,plugin,host FROM mysql.user; (to check the settings you made earlier)
**** CREATE USER 'kbsuperuser'@'localhost' IDENTIFIED BY 'password'; (create a new user)
**** GRANT ALL PRIVILEGES ON *.* TO 'kbsuperuser'@'localhost' WITH GRANT OPTION; (grant priviliges to the user)
Step 25 - You can now access the web interface by visiting your server’s domain name or public IP address followed by /phpmyadmin
:
Conclusion:
You should now have a configured and ready web server. You may move your files to root folder. Well Done!
What's Your Reaction?