As the code in your project or organization grow, is a good practice to separate those concerns across different modules or packages. In order to do that you will need a private Composer Repository.
When it comes to host PHP packages you can either use a SaaS provider like packagist.com or self-hosted using Satis or Private Packagist.
In this tutorial we’re going to be covering the hole setup process of Satis as a private Composer Repository.
Step 1. Install Apache
Open your terminal and type in these commands:
1 2 |
sudo apt-get update sudo apt-get install apache2 |
That’s it. Check if apache is installed opening your browser and typing the server’s IP address. The page should display “It works!”.
Step 2. Install SSL using Let’s Encrypt
Setting up Apache to use ServerName:
First of all let’s configure apache to include ServerName. Open the apache configuration file for the default site in “/etc/apache2/sites-enabled/000-default.conf”. Uncomment the “ServerName” parameter and change it with the domain you want to use for your private repository. Ex: “packagist.domain.com”.
The file should look like this:
1 2 3 4 5 6 7 8 9 |
<VirtualHost *:80> ServerName packagist.domain.com ServerAdmin webmaster@localhost DocumentRoot /var/www/html ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> |
Restart apache typing this command in your console:
1 |
sudo service apache2 restart |
Installing Let’s Encrypt Client:
Let’s Encrypt client require a non-root sudo enabled-user. If you already have one you can skip adding these commands:
1 2 |
adduser letsencrypt usermod -aG sudo letsencrypt |
Log into your server using using the your sudo-enabled account. Let’s go ahead and install the official Let’s Encrypt client called Certbot.
1 2 3 |
sudo add-apt-repository ppa:certbot/certbot sudo apt-get update sudo apt-get install python-certbot-apache |
Set up the SSL Certificate:
To obtain a certificate, run the certbot command like so, where “packagist.domain.com” is your domain:
1 |
sudo certbot --apache -d packagist.domain.com |
Follow the installation process and you should get the following message if everything is good:
1 2 3 4 5 6 |
------------------------------------------------------------------------------- Congratulations! You have successfully enabled https://packagist.domain.com You should test your configuration at: https://www.ssllabs.com/ssltest/analyze.html?d=packagist.domain.com ------------------------------------------------------------------------------- |
You’re good to go, check your SSL connection opening your browser using your https URL.
Step 3. Install PHP and required extensions
Open your terminal and type in these commands:
1 2 3 4 5 |
sudo apt-get install php7.0 sudo apt-get install libapache2-mod-php7.0 sudo apt-get install php7.0-xml sudo apt-get install php7.0-mbstring sudo apt-get install zip unzip php7.0-zip |
Check if php is installed typing this command in your console:
1 |
php -v |
You should see something like:
1 2 3 4 |
HP 7.0.25-0ubuntu0.16.04.1 (cli) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies with Zend OPcache v7.0.25-0ubuntu0.16.04.1, Copyright (c) 1999-2017, by Zend Technologies |
Finally restart apache typing this command in your console:
1 |
sudo service apache2 restart |
Step 4. Install Satis
In order to install Satis, type the these commands in your console:
1 2 3 |
cd /var/www/html curl -sS https://getcomposer.org/installer | php php composer.phar create-project composer/satis --stability=dev --keep-vcs |
We’re good, now we need to create the satis configuration file. Create a file named satis.json In /var/www/html with the following content:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
{ "name": "My Repository", "homepage": "https://packagist.yourdomain.com", "repositories": [ { "type": "vcs", "url": "git@github.com:mookofe/php-benchmark.git" }, ], "require-all": true, "require-dependencies": false, "require-dev-dependencies": false, "archive": { "directory": "dist", "format": "tar", "skip-dev": true } } |
Make sure to add your repositories to the “repositories” array. Now we can generate the static web pages:
1 |
php satis/bin/satis build satis.json . |
Final Step. Use your private repository in your projects:
In your project’s composer.json file add the new private repository to the “repositories” array. The final composer.json file should like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
{ "name": "project/name", "require": { "php": ">=7.1", ... } "repositories": [ { "type": "composer", "url": "https://packagist.domain.com/" } ] } |
Related: