├── _config.yml └── readme.md /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Laravel configuration with LAMP stack. 2 | 3 | This guide will also cover Laravel pretty URLs with `UBUNTU 18.04`. This guide is heavily inspired from [this guide][1] 4 | 5 | ## Step 1 — Installing Apache and Updating the Firewall 6 | 7 | Install Apache using Ubuntu's package manager, `apt`: 8 | 9 | ``` 10 | sudo apt update 11 | sudo apt install apache2 12 | ``` 13 | 14 | ### Adjust the Firewall to Allow Web Traffic 15 | 16 | ```sudo ufw app list``` 17 | 18 | Output 19 | ``` 20 | Available applications: 21 | Apache 22 | Apache Full 23 | Apache Secure 24 | OpenSSH 25 | ``` 26 | 27 | If you look at the `Apache Full` profile, it should show that it enables traffic to ports `80` and `443`: 28 | ```sudo ufw app info "Apache Full"``` 29 | 30 | ``` 31 | Output 32 | Profile: Apache Full 33 | Title: Web Server (HTTP,HTTPS) 34 | Description: Apache v2 is the next generation of the omnipresent Apache web 35 | server. 36 | 37 | Ports: 38 | 80,443/tcp 39 | ``` 40 | 41 | Allow incoming HTTP and HTTPS traffic for this profile: 42 | 43 | ``` 44 | sudo ufw allow in "Apache Full" 45 | ``` 46 | 47 | Now 48 | ``` 49 | http://your_server_ip 50 | ``` 51 | will serve you `Apache` default page. 52 | 53 | ## Step 2 — Installing MySQL 54 | 55 | ``` 56 | sudo apt install mysql-server 57 | ``` 58 | 59 | Setup password for `root` user. 60 | 61 | ``` 62 | sudo mysql 63 | mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'secure_password'; 64 | mysql> FLUSH PRIVILEGES; 65 | mysql> exit; 66 | ``` 67 | > For secure `MySQL` installation, please check [this guide][1] 68 | 69 | ## Step 3 — Installing PHP 70 | 71 | In original guide, required Modules for `Laravel` are missing. Guide contains something like this. 72 | 73 | > ~~sudo apt install php libapache2-mod-php php-mysql~~ 74 | 75 | instead, we're going to install `PHP 7.2` with all the Modules that `Laravel` requires. 76 | 77 | ``` 78 | sudo apt install php7.2 libapache2-mod-php7.2 php7.2-mbstring php7.2-xmlrpc php7.2-soap php7.2-gd php7.2-xml php7.2-cli php7.2-zip php-mysql php-curl 79 | 80 | ``` 81 | 82 | In most cases, you will want to modify the way that Apache serves files when a directory is requested. Currently, if a user requests a directory from the server, `Apache` will first look for a file called `index.html`. We want to tell the web server to prefer `PHP` files over others, so make `Apache` look for an `index.php` file first. 83 | 84 | To do this, type this command to open the `dir.conf` file in a text editor with `root` privileges: 85 | 86 | ``` 87 | sudo vi /etc/apache2/mods-enabled/dir.conf 88 | ``` 89 | 90 | ```vim 91 | 92 | DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm 93 | 94 | ``` 95 | 96 | move `index.php` after `DirectoryIndex` 97 | 98 | ```vim 99 | 100 | DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm 101 | 102 | ``` 103 | 104 | Restart the `Apache` web server. 105 | 106 | ``` 107 | sudo systemctl restart apache2 108 | ``` 109 | 110 | ## Step 4: Install Composer to Download Laravel 111 | ``` 112 | curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer 113 | ``` 114 | 115 | cd `/var/www/html` 116 | ``` 117 | sudo composer create-project laravel/laravel MyProject --prefer-dist 118 | ``` 119 | 120 | ### Change Permissions 121 | 122 | ``` 123 | sudo chown -R www-data:www-data /var/www/html/MyProject/ 124 | sudo chmod -R 755 /var/www/html/MyProject/ 125 | ``` 126 | 127 | ## Step 5: Configure Apache 128 | 129 | You can choose whatever name you want for this file, I am going to stick with `laravel.conf` 130 | 131 | ``` 132 | sudo vi /etc/apache2/sites-available/laravel.conf 133 | ``` 134 | 135 | Add following content to file. 136 | ```vim 137 | 138 | ServerAdmin admin@example.com 139 | DocumentRoot /var/www/html/MyProject/public 140 | ServerName example.com 141 | 142 | 143 | Options +FollowSymlinks 144 | AllowOverride All 145 | Require all granted 146 | 147 | 148 | ErrorLog ${APACHE_LOG_DIR}/error.log 149 | CustomLog ${APACHE_LOG_DIR}/access.log combined 150 | 151 | ``` 152 | 153 | Save the file and exit(hit `esc` then type `:wq` and hit `Enter`). 154 | 155 | ## Step 6: Enable the Laravel and Rewrite Module 156 | 157 | ``` 158 | sudo a2dissite 000-default.conf 159 | sudo a2ensite laravel.conf 160 | sudo a2enmod rewrite 161 | sudo service apache2 restart 162 | ``` 163 | 164 | ## Step 7: Restart Apache 165 | 166 | ``` 167 | sudo systemctl restart apache2.service 168 | ``` 169 | 170 | and you're all set to go. 171 | 172 | Head to `http://example.com` and you'll see `Laravel` homepage. 173 | 174 | [1]: https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-ubuntu-18-04 "How To Install Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu 18.04" 175 | --------------------------------------------------------------------------------