1736377831

Community learning 2 lesson 3


# installing and configuring Apache Now that we have the server up and running, and we know how to navigate the file system we can move onto getting apache installed and set up. First the basics `sudo apt update -y && sudo apt upgrade -y`. Once thats done we `sudo apt install apache2 -y`. <br> Once that is finished you will have a default page working to help you verify if everything went right or not. To find this webpage you can go your your router and find your server by name. If you dont know what the servers name is run `hostname` and it will output the identifier that should match one of the devices on your home network. Another method to find the server's local ip will be running `ipconfig` or `ip a` and looking through the outputs to find the local ip. Here in the USA it will almost always start with 192.168.xxx.xxx:. This ip is the address of the server on your home network, this server is not hooked up to the internet yet and will therefore not be accessible from outside your home. Once you have the address you should be able to navigate to it on your primary computer and should be greeted with the default apache page. If you see this, congrats, you have finished the first part of this project. If not, please see me in the community_learning chat room. Now, as of this time, if all you want is a static website you can head to the /var/www/html dir and build your site there. The apache server will look for an index.html to be the default page, so if you want to import a project you have made beforehand and the first page is: home.html or something, please rename that file or go into the apache config. If you did the last lesson you should be able to navigate to these directories and edit and make new files. Now we will go over some common configuration. If what you want to do is not included in my list, read the [documentation.](https://httpd.apache.org/docs/2.4/) First i want to cover how to have multiple sites that you can toggle on-off so you can have multiple projects on the same server. Navigate to /etc/apache2/sites-available. Here you will find a dir called 000-default.conf. This is the config for the default apache-is-working landing page that you saw earlier. If you want to make more projects you just need to copy that default to: project2.conf or whatever. If you only intend this server to host one project and dont forsee yourself toggling what service is active frequently, then just use the default config. Make sure you take a backup of this file and store it somewhere safe just incase you goof something up. We will go over the contents of this file later. Once again read the [docs](https://httpd.apache.org/docs/2.4/) if there is something specific you want to change. Now i want to look at the networking bit of the server. For most people the default is fine but this file will enable you to change some things such as the default ports that you want to listen for. This file can be found at /etc/apache2/ports.conf. Be aware that we will be going over this is more detail once we get to playing around with your home router to make the server accessible to the internet. It is then that we will forward specific ports to the internet (80, 443, and 22) These 2 files are the most commonly used ones to: change the default file that it looks for from index.html to thisOne.html or to set up self-signed https so some users dont get the 'secure connection is not available' message. For now we are going to set up php and sql as i havent had any other feedback that would be relevant so i guess this guide is going to be catered towards that 1 person with feedback. None the less I am willing to help you set up anything else aslong as im familair with it. Im primary a RoR guy so if anyone wants to learn how to self host a puma or nginx rails server id be down to help. Msg me in the community learning chat if you want to take that spin on this lesson. To get php and a backend we need to install all the parts that are not already included. `sudo apt install mariadb-server -y` Mariadb is just a fork of mysql that from personal experience runs a bit lighter. Otherwise its the same and comparable with all the tools and cmds you are used too. Once that finished we need to make sure its working: `sudo systemctl status mysql`. Cool. Now we need to secure it. This will run a little script that will ask you some questions. If you know what you are doing do this by yourself, otherwise follow my directions and ill explain why I choose them. `sudo mysql_secure_installation` <br>Cool. question 1. switch to unix_socket auth: no. This can be a yes with no issues but let your server handle it with *its* config rather then using sql's config to setup the network, we dont need the sql telling the computer what to do. <br>2. change password, no, why would i do that. once again sql really dont need to change my servers root password. stay in your lane! i dont know why these questions exist. <br>3. remove anon users. sure. this means that you will have to ssh into the server with `ssh admin@serverIP` or `ssh david@serverIP` instead of just being able to `ssh serverIP`. This aint a huge deal, but when i went over the ssh in the previous lesson I said that if you ssh with just `ssh serverIP` that it will make a user based on the computer im connecting from. As a recap, my computer that im on right now is called debian_desktop1 with the user as David. So when i ssh into the server it by default made a David user and gave me a dir within the /home on the server. By selecting yes for question 3 means that i will now need to use `ssh david@serverIP`. The reason we want this is so that any actions done on the server can be logged with a username. This is very useful when you have multiple people that use the server. They can each have their own /home and any actions they do will be logged and make it easier for you to know who did what. Useful incase someone goofs something up, you can ask them what they did so it can be fixed. anyways, use yes or no based on your preference. i choose yes because i prefer the better logging & you should too. <br>4. Disallow root login remotely. Ok first ask youself. will i ever need to use sudo or root from outside my home network. If yes, then select no. otherwise select yes. What this setting does is disable users from being able to run cmds from root, if they arent within your home network. I personally make changes to my server from my laptop while im at work or elsewhere. This means i select NO otherwise i would only be able to use root while im at home. Up to you. <br>5. remove tests, yes. this is just to make sure the sql is working right. it is if you got this far so just yes to clear it out. you can do this at a later stage from the phpmyadmin console but no reason to skip doing it now. <br>6. reload. yuppers. Now you should be done with this. reboot your server for good measure. Next lesson we will install php. As always ill be in the community_learning chat room.

(0) Comments

Welcome to Chat-to.dev, a space for both novice and experienced programmers to chat about programming and share code in their posts.

About | Privacy | Terms | Donate
[2025 © Chat-to.dev]