A step by step guide to setup PHP (Laravel) environment (Linux). by@yjose

A step by step guide to setup PHP (Laravel) environment (Linux).

October 31st 2017 78,205 reads
Read on Terminal Reader
react to story with heart
react to story with light
react to story with boat
react to story with money
image
Youssouf El Azizi HackerNoon profile picture

Youssouf El Azizi

image

This article is a step by step tutorial to get started with PHP and laravel in Linux environment ( Ubuntu ). By installing Apache2, Mysql and PHP, your LAMP server is ready to host your PHP application.

At the end of this post, you’ll know how to add your custom domain for your local environment.

If you are familiar with Docker check My post :Laravel & Docker, Zero config with Vessel.

Let’s start !!!

As you expected from all kind of Linux tutorials you should first update and upgrade your system by running :


sudo apt-get updatesudo apt-get upgrade

Now your system and packages system is up to date.

Next, you need to install some basics dependencies to avoid all kind of problems in your workflow

sudo apt-get install -y git curl wget zip unzip

Installing Apache2 server :

sudo apt-get install apache2

To make sure that the server is running you can execute this command in your terminal

sudo systemctl status apache2

image

sudo systemctl status apache2

As you see above, the service appears to have started successfully, you can also access to your server through the http://localhost address and you will see Apache2 default home page.

It is important to know that all your web content must be under the /var/www/html directory. you can check the Bonus section to make any folder as your root web content to know how to config.

To master Appche2 config you need to master this 6 commands line:

  • a2enmod (apache2 enable mode) : To enable an Apache2 mod like rewrite mode.
  • a2dismod (apache2 disable mode) : To disable an Apache2 mod.
  • a2enconf (apache2 enable Config) : To enable a specific config.
  • a2disconf (apache2 disable config) : To disable a specific config.
  • a2ensite(apache2 enable Site) : To enable a specific app.
  • a2dissite (apache2 disable Site) : To disable a specific app.

Enable rewrite mode


sudo a2enmod rewritesudo systemctl restart apache2

This Gif take you around the most important Apache directories.

image

You can learn more about Apache config and Linux in this article

Install MySQL

sudo apt-get install mysql-server

Click Enter to validate the first popup, then create a password for your Mysql root user. it’s highly recommended to secure Mysql server by running :

mysql_secure_installation

You can read more about improving MySQL installation security

To mange database, there is a lot of SQL clients to use with MySQL like MySQL Workbench, SQuirreL, SQLECTRON or the great Google Extension Chrome MySQL Admin .

Install PHP :


sudo add-apt-repository -y ppa:ondrej/phpsudo apt-get update


sudo apt-get install -y php7.1 php7.1-fpm libapache2-mod-php7.0 php7.1-cli php7.1-curl php7.1-mysql php7.1-sqlite3 \php7.1-gd php7.1-xml php7.1-mcrypt php7.1-mbstring php7.1-iconv

As you see above this large command will install php, php-cli and the most important php libraries.

Install Composer :


curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composersudo chown -R $USER $HOME/.composer

Now you are ready to create your first Laravel app.

Test web Server

To test your LAMP server, just create a Laravel application under Apache2 root directory.


cd /var/www/htmlcomposer create-project --prefer-dist laravel/laravel lara_app

Open your browser and you can access to your app through :

http://localhost/lara_app/public

Bonus

In this section you will discover how you can create a Laravel application with custom domain name outside apache2 directory.

first create a config file under /etc/apache2/sites-available directory.


cd /etc/apache2/sites-availablesudo touch lara_app.conf

Past and update DocumentRoot and Directory with your app folder inside the file.

<VirtualHost *:80>.

ServerName lara_app.dev

ServerAdmin [email protected]


# Your Custom folderDocumentRoot /media/disk2/Work/lara_app/public/

<Directory /media/disk2/Work/lara_app/public/>

Options Indexes FollowSymLinks

AllowOverride None

Require all granted

</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log

CustomLog ${APACHE_LOG_DIR}/access.log

</VirtualHost>

Next, give to your custom folder the permission to execute

chmod -R 755 /media/disk2/Work/lara_app/public/

Then disable the default site and enable you new lara_app site.


sudo a2dissite 000-defaultsudo a2ensite lara_app

At last, you can configure the lara_app.dev domain name by adding this line into /etc/hosts file.




# /etc/hosts127.0.0.1 localhost127.0.0.1 lara_app.dev127.0.1.1 youssouf-Latitude-E6410

Now you can access to your app through your custom domain name : http://lara_app.dev

If you are familiar with Docker check My post :Laravel & Docker, Zero config with Vessel.

If you are familiar with React check My post :


Introducing reactjs-popup 🎉 — Modals, Tooltips and Menus — All in one_This article is about giving you a simple overview of what you can do with reactjs-popup and how to use it effectively._hackernoon.com

Thanks for reading! If you think other people should read this, clap for me, tweet and share the post. Remember to follow me on Medium so you can get notified about my future posts.

Read more stories https://elazizi.com/

image

react to story with heart
react to story with light
react to story with boat
react to story with money
L O A D I N G
. . . comments & more!