Monday, January 18, 2016

Installing PHP7, Nginx, Mysql (Mariadb) (LEMP), Composer and Laravel on Arch Linux/Manjaro

8:24 AM Posted by xa1
My blog isn't meant to be a How-To guide, per SE, for that you could refer to DigitalOcean.

I dumped XAMPP, it has it's own php.ini, some configurations didn't work, couldn't enable mcrypt, etc, XAMPP is not a good solution. Tried to run PHP7 on Apache on my manjaro, didn't work, God knows why, so I settled on Nginx, and here's how I install it.

I have php7, php7-fpm, mariadb, Nginx and mcrypt for php7 installed, the first four can be installed using Pacman, the last should be installed using Yaourt, if you have package manager Pamac,  you could install all of them by using that. if you got stuck during the installation refer to DigitalOcean's blog post.

Now lets configure Nginx, which is the most important part, use your favorite text editor and edit etc/nginx/nginx.conf, fastcgi configuration, line (64 to 72 in my file) should look like this:

        # pass the PHP scripts to FastCGI server listening on
        location ~ \.php$ {
            root           html;
            fastcgi_pass   unix:/var/run/php-fpm/php-fpm.sock;
           fastcgi_index  index.php;
           fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
            include        fastcgi_params;

I suppose you know how to change the root, root   /usr/share/nginx/html; to something else, line 44 in my file, I tend to leave the root as is, create a folder inside it for php, Chmod 777 -R folder I created, and create a shortcut for it.
I also installed the latest version of composer using Pamac, you could also
sudo pacman -S php-composer

Or follow instructions on their website

For database management I use Adminer or SQLbuddy, the latter seems dead, last release 3 years ago. To install composer you run

composer global require "laravel/installer"
If Composer  asked for token, click on the link generated in terminal, and grant composer access for public repos.

One small note, I couldn't get Laravel to run on Nginx so I just do

php artisan serve application

You think you can make it work on Nginx? Let me know in the comments, but I'm satisfied for development, on a production server, I'd be using apache if I knew I want to run Laravel, and probably an Ubuntu or Debian VPS. Don't forget to

  sudo systemctl restart php-fpm.service and sudo systemctl restart nginx