Setting up the environment on Ubuntu
Setting up your environment on Ubuntu is the easiest of the three platforms. In fact, you could take the provisioner.sh
script from the Setting up the environment with Vagrant section and execute it on your laptop. That should do the trick. However, just in case you already have some of the tools installed or you want to have a sense of control on what is going on, we will detail each step.
Installing PHP
The only thing to consider in this section is to remove any previous PHP versions on your system. To do so, you can run the following command:
$ sudo apt-get -y purge php.*
The next step is to add the necessary repositories in order to fetch the correct PHP version. The commands to add and update them are:
$ sudo apt-get install python-software-properties $ sudo LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/php -y $ sudo apt-get update
Finally, we need to install PHP 7 together with the driver for MySQL. For this, just execute the following three commands:
$ sudo apt-get install php7.0 php7.0-fpm php7.0-mysql -y $ sudo apt-get --purge autoremove -y $ sudo service php7.0-fpm start
Installing MySQL
Installing MySQL manually can be slightly different than with the Vagrant script. As we can interact with the console, we do not have to specify the root password previously; instead, we can force MySQL to prompt for it. Run the following command and keep in mind that the installer will ask you for the password:
$ sudo apt-get -y install mysql-server mysql-client
Once done, if you need to start the MySQL server, you can do it with the following command:
$ sudo service mysql start
Installing Nginx
The first thing that you need to know is that you can only have one web server listening on the same port. As port 80
is the default one for web applications, if you are running Apache on your Ubuntu machine, you will not be able to start an Nginx web server listening on the same port 80
. To fix this, you can either change the ports for Nginx or Apache, stop Apache, or uninstall it. Either way, the installation command for Nginx is as follows:
$ sudo apt-get install nginx –y
Now, you will need to enable a site with Nginx. The sites are files under /etc/nginx/sites-available
. There is already one file there, default
, which you can safely replace with the following content:
server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; root /var/www/html; index index.php index.html index.htm; server_name server_domain_or_IP; location / { try_files $uri $uri/ /index.php?$query_string; } location ~ \.php$ { try_files $uri /index.php =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
This configuration basically points the root directory of your web application to the /var/www/html
directory. You can choose the one that you prefer, but make sure that it has the right permissions. It also listens on the port 80
, which you can change with the one you prefer; just keep this in mind that when you try to access your application via a browser. Finally, to apply all the changes, run the following command:
$ sudo service nginx restart
Tip
Downloading the example code
You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
You can download the code files by following these steps:
- Log in or register to our website using your e-mail address and password.
- Hover the mouse pointer on the SUPPORT tab at the top.
- Click on Code Downloads & Errata.
- Enter the name of the book in the Search box.
- Select the book for which you're looking to download the code files.
- Choose from the drop-down menu where you purchased this book from.
- Click on Code Download.
Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:
- WinRAR / 7-Zip for Windows
- Zipeg / iZip / UnRarX for Mac
- 7-Zip / PeaZip for Linux