How to setup Apache, MySql, and PHP on Ubuntu Linux

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
here what's up guys Alex here thank you for checking this video and welcome to this quick tutorial on how to set up a fully functional development environment on Linux [Music] welcome again so what is a development environment if you're a developer and you have a Linux machine you're wondering why you should care it's basically a simulation or like the configuration of a server a fully functional server on your local machine so whenever you need to develop an application in PHP Ruby or whatever other scripting language you're going to use it's better to develop these application first on your machine on your computer instead of constantly pushing constantly uploading files on a remote server server online in order to test your application setting up a local server is necessary for specific languages that need a server in order to run if you're just building a front-end application like a static HTML website we CSS a Java Script you don't really need a local server setup for your machine you can do it simply by opening the HTML file on your browser but if you're developing an application that uses PHP or a connection to a database like my sequel you need a server running on your machine and Linux is the perfect place to start because Linux actually comes with a server built in inside a system like the default configuration of Linux it's perfect for a local environment in fact if you ever had the experience of buying or purchasing a server online you will most likely notice that you have the option to choose what type of machine you can set up and ninety-nine percent of the time that machine is a Linux machine most likely running Ubuntu or another flavor another distribution of Linux so first of all what we're gonna install we're going to set up on our machine is a lamp stack I don't know if you ever heard about these word lamp but it's just a fancy way of saying a fully functional server the runs my sequel in PHP in fact lamp stands for Linux operating system Apache a my sequel that is the database and P is PHP a lamp stack is the default type of software bundle that it's necessary in order to run a web server and after installing your Linux operating system whatever choice of operating system we are already 50% done basically because we already have BL or Linux and the a our Apache server to test if your Linux installation has an Apache server running you can simply open a new browser tab and type localhost by default the localhost of the new Linux installation should point directly to your Apache welcome screen or something like that that specify that you're actually running Apache to currently on Ubuntu it works that's perfect and a bunch of configuration examples so let's access the terminal first we want to check if we actually have Apache and if it's running to check if we have Apache we can simply write which tachi to and if we don't get any error and we get the actual directory of Apache means that Apache is actually installed on our machine to check the status of Apache we can simply type sudo service that Apache is a service Apache to status and it's going to ask for our root password and that's perfect here we have a quick report of the status of our server and it's green it's active and running and it's simulating a bunch of HTTP address and is taking care of a bunch of localhost all good if you get an answer that your Apache server is not running and the activation status it's written like deactivated or disabled or like not running you can simply fix this issue by typing sudo service Apache start the other thing that we want to check is we want to check how it's possible at automatically our system every time we type localhost in a work bar it's going to our Apache folder and it's pointing to our local environment is not pointing to Google or another server because if I type something in the search bar it goes directly to Google and does a research based on something on the word that I wrote that I also misspelled but why when I type localhost it doesn't go to Google but goes to Apache this is because Apache handles these requests and unique URL thanks to a host file and to check our hosts file we can open it in sublime and check the configuration to open it in sublime through the terminal I'm going to type su bl2 called sublime and then I'm saying that four words left from the EDC folder /host file open this in sublime hit enter we have here a list of names we'd a specific IP address these 127.0.0.1 is the local host the local IP address of our machine or assimilations like something that doesn't really exist online it's an IP address that is used only for local machine so every time we want to set up something that points to our local Apache server we can write it here so for example if I want then every time I type like test dot dev and I hit enter this test of dev should point to my Apache installation instead of trying to reach a web site called test or dev that doesn't exist let's do it inside our host file let's just write a space and write has dot depth some users likes to repeat this row and just having one single address per row it's it doesn't really matter you can do both it's a sort of like type of organization if you want to click keep your host file cleaner you can write everything in line it doesn't really matter but let's save this we're going to get prompt with password confirmation and if we try to access the test dev of course because we specified a specific host that's the TV URL to point in to our local host automatically now is going to our Apache installation and that's perfect is not trying to access a non existing URL on the internet but it's pointing to our local file so at this point what we have to do we have to connect these local IP addresses local address that we set up in our host file to an actual folder in our server so we can actually simulate how a website works any IP address that points to a physical folder inside a server if we notice here in the Apache presentation screen of a boon to we know that our server folder is located here at the VAR wwo HTML and blah blah all the others thing but we know that our apache server installing Ubuntu is automatically grabbing all the stuff like all the folders and files that are set up and configure inside this location so that's where we have to go if you want to check where this location is and what's inside we can simply open our file manager and holding alt key and then hitting up arrow we're going to navigate up a couple of times to reach the root folder of our installation and here you will notice we have the bar and then www here we have the HTML folder that is the default one that goes inside this presentation of Apache and we have the index.html that's perfect so this is the location where we have to create all the folders related to our local website so in my case I want to create a folder called test if you notice if you right-click and try to create a new folder you can't because these folder these Apache var folder is protected under root access so if you're not logged as an administrator as a root you cannot create any folder we're going to solve this issue in just a moment but as a suggestion you shouldn't create folders or files or anything else directly inside the file manager you should do it especially during the first configuration you should do everything through terminal and that's what we're gonna do let's switch back to our terminal let's create a new folder for our test dev website so let's say sudo to act as a root administrator m'kay dear that is the command the bash command to create a directory and it's shortened for make a directory then let's specify - P to say that we want to create also a parent directory if we need to create a parent directory in my case we're not going to need to create a parent directory but if you want to create multiple directory and sub directories you should use the - P command and we're going to create our directory inside the bar www location and then we can call tests that is a new one with a - P we can potentially create another subfolder and call it like CSS directly so these - P out remedy is going to create for us the test and the flat and the CSS folder inside the test we don't need to do that we're going to create just the test folder press Enter is going to we're going to get prompt to insert our administrator password and it's perfect if you go back in two places now we have the test folder and awesome we created our first folder for our new local environment now we have to change the permissions of this folder in order to be able to create files write whatever we want to change the permission we have to change the ownership do that let's type again sudo and then th own to change the ownership and - R to make it recursive so it's going to include whatever other folder is going to be created folder and file is going to be created inside this main folder will automatically get the the permission and the ownership of this main folder that we're setting right now I want to set the permission and the ownership to myself both group and user to do that without checking what's my user name and how do I write it properly in bla bla bla we can simply write the very bola the global variable dollar user for the group and then dollar user for the owner automatically this system will grab this global variable and we use our name that in my case for my computer is Alec hat and it's going to associate the ownership and the group to those files that I'm going to specify to Alec and myself so let's specify that I want the owner I want to change the ownership to the folder var www test perfect then the last thing that we have to do for this part is change the permission of the VAR WWE by default this folder is not readable is not globally readable and accessible let's change it by writing again sudo chmod to modify the permission and again - our to be recursive and then let's specify permission seven five five to make it readable and not writable only readable to the global folder www perfect now if we go back here and we exit the test we and we right-click we notice that we can create a new folder we can create a new file we can do pretty much everything because now this folder if we access the properties and we check the permissions belongs to us as a user and we can access all the file so that's perfect that's what we want it at this point just for the sake of this tutorial and just create a boilerplate let's create a new file called index dot PHP by saying touch inside the bar www test the index dot PHP and let's open in sublime this file that we just created of course is empty let's create let's open the PHP tags and let's write echo PHP info save it that's perfect we can close this file we don't need it anymore now we have our server we the test folder and the index dot PHP file that we just created but if we refresh the tester dev of course is going to always go to these default Apache introduction file because we didn't actually hook our IP address to the actual folder in our Apache server that's where a virtual host comes in handy because in that way we can connect the document route the document directory to the actual server directory and simulate the server directories you have a server name that in our case is going to be tested on dev so let's do it to create a virtual host in Apache is really really simple and I'm going to show you where the virtual hosts are in Apache so if we go back in our root folder and we access our etc' folder we are gonna see apache 2 that is our server installed on our machine we have to see here and we access the sites available you're going to notice we have a folder we have a file called 0 0 0 - default if we hope and we're going to notice that pretty much all the lines are commented out and the only lines that are not are the one referring to document root that is the default one the www HTML folder these boilerplate type of file it's necessary for us we're going to use it to specify all our filter host in order to hook the test of URL to the actual test folder that we created our www Apache folder as a small recommendation never never never edit files that are inside the sites enabled sites enabled is a folder that it's managed by Apache and automatically populated or deleted or managed independently by Apache with some scripts you don't need to edit or manually touch whatever it is inside the site's enable every time you need to create a virtual host always and only edit files and create files inside this site available folder don't get confused otherwise you risk to break your Apache installation and we don't want to do that let's access back our terminal and let's duplicate that default conf file that we just saw so we're going to use the sudo command again and then CP that stands for copy we're going to copy de TC Apache to forward slash sides available /d 0 0 0 0 and if we hit tab automatically the system we recognize the file and will populate it for us without a complete and we're going to duplicate it in the same location so let's repeat de TT Apache 2 and then the sides available and then we need to specify the name of the file with the same extension of our virtual host that we want to use our website so in my case is going to be test dot death and then dot com because it's a config file so the name of the file as always always have to resemble and has to be identical to the name of the URL that you're going to use for this site for this virtual host at it enter and automatically we have the duplicated we can check if we go back inside sites available we have the test def config now we need to edit it in order to edit it we need to access a pseudo or we can use sublime and get prompt with confirmation every time we save it so let's hit arrow up to get our previous entry and here we can just simply type sublime he'd enter and that's perfect here we can pretty much remove all these comments that are not necessary let's leave here we can remove pretty much area actually let's remove everything and let's manually write what we need be sure that you're editing the test of des comms and not the default one because we don't want to touch the default one we don't want to risk to break it so first we need to specify a server admin and usually the server admin resembles the type of file the type of website that we're editing so let's change it to something for example admin at test dot dev of course on a real case scenario these would be the actual email address of the server admin so you can hook every time there's a server issue to send an email to the server admin and it's going to get the laws of the reports and all the errors for now because we are in a local environment we don't need to specify a real email but you can change it and doing whatever you want we need to change the server name to the URL that we want to use and that's where we need to specify test dot dev and then the document root is where we created our folder where our website and the files of our website are going to be so in my case are inside VAR w w test that's perfect then we can specify a bunch of extra information if you want there are most likely important if your one attract error and custom logs so we can specify the dollar and then the curly braket Apache log dear that is the global variable where our our logs are going to be saved inside our Apache server and we're going to store every inside error or dot log and then we can duplicate this and change this to custom log and instead of error log we're gonna change it to access log and we're going to specify that this file has to be combined these are kind of default things that you need you you don't Neela you you just laid here you don't really need to edit is just like default configuration of an Apache server so that's perfect and this is the bare minimum there are many many other options that we're going to check in a minute we're going to see all the other options in a bit but this is the bare minimum to have a fully functional virtual host so now we can save this file we're going to get a prompt to insert our administration password that's perfect now we can close this and in order to enable and activate this file we need to use a bash script for Apache that automatically does that for us and to do that we need to type again sudo then a to n-side that means Apache to enabled side and we need to specify the file that we just created test dot dev dot call we don't need to enter the entire route because automatically this script is going to look for the file inside the sites available because it's the only location where you should have this type of configuration file in order to enable so let's hit enter and now the site tested dev is available and activated if we check back in our folder in the Apache 2 and we access the site's enabled you're going to notice we have a symlink a file that it's a link that points to our test account that's why you don't ever ever have to touch the sites enable folder because automatically these folders is managed by death script to activate and deactivate all the sites that are inside the sites available folder now in order to complete we need to restart or reload Apache with this script so let's copy the script let's paste it here and at each Center when I get prompt with the administration password Apache has been reloaded let's go back to our server let's go back to Network browser let's refresh test dev and we have the PHP info file that's perfect if we don't get PHP here if we don't get anything with the info - PHP means that you don't have PHP installed inside your machine to install PHP in your machine first you need to check if you have it so just type eh P - P if you don't have it you can simply type sudo apt-get install PHP 7.0 that is the current version of PHP available and I strongly suggest you to use the apt package manager and some users like to use homebrew or Linux brew that is the derivation of homebrew for Linux to get the latest repositories or like the rated latest packages but if you don't really need to do it you can totally have a stable version of PHP or a stable version of whatever package you want to use through the official and built-in package manager of Linux that is apt so now our virtual host is up and we can manage all the files through our root folder VAR www test these is our test file but what I don't like is that I don't want every time I need to edit these folders I need to edit this file or I'm working on this website a to access the root bar WWN test I want to create a symlink to my home directory site and I have here the www so I know that if I access here I'm going to go directly inside Apache and every time I create a folder there or something it means that I can set up a new virtual host a new website and I can keep everything better organized and better separated so let's do it of course through terminal so in order to create a symlink through the terminal we need to type l and space - s to create a symlink point to the folder that we want to link it we want to kind of duplicate and copy and generate this my KDS bar /ww and then the destination folder that in my case is my home directory my name that is the user of that home this computer and then the folder sites and then the name of the link that is going to be www Center perfect let's go back in our word directory let's go back in our home directory sites and then I have two WWWF I double click I'm going to access directly to my test folder or my HTML folder or whatever I'm going to directly get redirected to the location where my server actually here so this is really handy and of course because it's a root folder it's a protective one we're gonna have these icon you can change the icon if you want but it doesn't really matter it's just like really handy quick link to going to your server so these is our entire workflow to set up manually set up a local server on Linux through Apache but of course it's kind of convoluted I mean if I don't explain anything and I just simply type it it's really easy and really quick to use it but if you need to create a lot of sides constantly and you need to generate like once a week and UF sign you to manage multiple websites kind of tedious especially or even if you create a one localhost one virtual host then a couple of months passed before you need to create another one are you completely forgot all the workflow and everything and what would you have to do it's kind of like tedious so we need a sort of automation that's where a super nifty script shell crepe that I found comes in handy if you access my github repository to a like add and virtual host ie forked shell script created by this user over wire that created the super nifty shell script I forked it because there was a small issue in one of the file when he was generating the IP address in the host file I fix that I push it so now we can quickly use it you can just simply download the virtual host dot shelf and dot s H file and then move into your beam folder in order to use it globally so let's do it let's open this file let's click it to run and then let's simply save it inside our home directory save now based on the instruction we need to change the chmod to be executable so we need to specify plus X to the virtual host s H that's what we're going to do so let's write th mod + X to be executable and then we're - host SH that is the file that I'm currently I just downloaded in my home directory scene hunter perfect now we have to copy paste this into our user local bin and rename it into virtual hosts so we remove the SH extension and we don't need to type it every time we want to execute this command so let's do it let's copy it is tasks s our terminal let's paste it here and let's change the initial location of control here and done now we have access to a bunch of super nifty quick script that will help us to automatically generate everything we did manually by itself so we need to specify just a couple of options and automatic is going to pre-populate everything for us and the script that we can use this simply sudo because we need to access it through a root virtual host we have the option to create or delete new domain and specify the host directory that it's optional so for example if I want to create a def fight for my awps wordpress installation i can simply use that script to say sudo vr-12 host create a WPF dev and then I want the folder typical a WPF and each Center done if we go back up there we go that we are inside our fold and if we check what the script did basically created a new virtual host added our host to the EDC host file and reloaded Apache for us and now we have everything here so we can check what what happened if we go inside our folders inside our ww we're going to see that now we have the awps and automatically the scripts generate a PHP info file that if we access it here we can check everything works that perfect plus automatically the system created for us inside all those Apache folder et Cie Apache two sites available created the awps def comp that if we open you'll notice here we have way more options that we had before and this is perfect because all these options are important for us they allow override all of the directory and the follow symlinks multi views all these options and require all granted will automatically set up the virtual host to accept for example permalinks or allow us to upload files to the server for example through the media float or WordPress and generate it also for us a unique file to handle all the error and access logs instead of having one single file that takes care of all our websites so this script is amazing it's really fast as quick as you notice and if you don't want this site anymore like for example you worked on it and it's a really whole website you want to clean your server you want to delete it you can reuse the same exact code that is pseudo virtual host but instead of create we can write delete and then let's delete the localhost and let's delete the Apache folder it's going to ask for confirmation to delete the root directory and let's specify yes perfect now if we go back up and we refresh again the site it doesn't work anymore if we access the folders here we inside the sites available we don't have anymore the awpa the sites enable either if we go back in our root bar www a WPS does not exist anymore of course our simile inside sites it's updated as well that's perfect the last thing that we want to do we need to create a database because a server without a database is kind of useless nowadays all the applications like WordPress they need a database so first of all we need to install my sequel to install my sequel is really easy first let's clear a little bit this terminal and let's say sudo apt apt get install my sequel - server that's it enter and let's say yes automatically the ABG package manager is going to download all the core files of my sequel in order for us to configure and set it up on our local machine so it's going to take a little bit and then at the end we're going to get prompt to set up automatically and configure so I usually get admin because root and admin are like kind of okay are the same so repeat the password just in case and then hit enter and automatically is going to get configured for us perfect now to check if our meta code server is actual running we can simply type system CTL that it is system controller check the status of our mice equals R is and of course we're going to get a positive confirmation is active and running is inside the our at being location my sequel D that's perfect now what we can do we can potentially use my sequel through the terminal but it's not really intuitive and after working many many years with Mac OS I'm used to sequel pro unfortunately sequel Pro doesn't exist for Linux but there's a database manager that it's available and it's really nifty that it's called the beaver it's a free and universal SQL client is open source and it's really cool so let's download it and of course it is multi-platform that it's amazing let's download the Debian package 64-bit and in order to launch it we need to run the packaging solution through the terminal so let's copy the name of this file let's copy the name of this file and let's type as for the instructure run sudo dpkg e DB ver and then the name death so let's type this stuff so let's run sudo dpkg then the location over fire that is inside our downloads folder and then the name of the file with the extension dot Deb and let's eat enter perfect now the next step is to simply execute DB v or simply click on T beaver wonderful so the new connection type let's go to down to my sequel and next localhost port is perfect we don't have a database username is root password is admin and local user client inside user next we don't have SSH access we don't know if SLE test the connection download driver files we are missing driver though that's perfect let's do it connect it awesome test connection connected success everything works and finish perfect now if we double click we can access our my sequel local installation and do everything that we usually do in a regular database installation so now here we can create a new database for example I would database for WordPress a lot of L's with Drupal whatever installation you want you can always access it through the root and perfect we have everything that we need to use our machine to develop all the web applications that we want so it's pretty much it for this video as you know there's probably this whole system kind of sounds complicated or convoluted but just because I was explaining step by step what I was doing while I was installing and configuring all the things now that you set it up for the first time and you have that script it's just super quick and easy and super automated even doing it manually would it take you just a couple of minutes because you don't have to stop every time to explain to understand what command is you are ready F those commands and that's perfect by using the script the virtual host shell script it's going to help you a lot to speed up these entire process setting up a new virtual host and automatically having a new folder generated for you in your Apache installation so it's pretty much it for this video hope you enjoyed it if you did please give it a thumbs up or subscribe to my channel and if you want you can check the support me page on my website to see all different ways and methods to support me support my channel and help me to do better videos and better tutorials for you thank you again guys and until the next lesson and usual happy coding
Info
Channel: Alessandro Castellani
Views: 116,601
Rating: 4.87292 out of 5
Keywords: coding, devops, linux, lamp stack, apache, mysql, php, development, server, how to, help
Id: TrLAx27Npns
Channel Id: undefined
Length: 36min 55sec (2215 seconds)
Published: Sun Apr 30 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.